matheus-git/country-logic

2

stars

10

commits

Rust

primary language

Sep 2, 2026

updated

cli
prolog
rust
scryer-prolog

README

Country Logic

Country Logic architecture — REST API, Rust CLI, Prolog rules, and results

Country Logic is a small command-line application for exploring country data with Rust and Prolog. It fetches names, regions, populations, ISO codes, and land borders from the REST Countries API, converts that data into Prolog facts, and evaluates four simple logical rules with an embedded Scryer Prolog engine.

The project is intentionally compact. Rust handles the command-line interface, HTTP requests, JSON decoding, and Prolog integration. The rules in rules.pl handle country relationships and population queries.

Requirements

Setup

Copy the example environment file:

cp .env.example .env

Then replace the placeholder in .env with your API key:

RESTCOUNTRIES_API_KEY=your_key

The .env file is ignored by Git. An existing environment variable takes precedence over the value in that file.

Usage

List all countries or regions:

cargo run -- countries
cargo run -- regions

Run country queries:

cargo run -- large
cargo run -- region Americas
cargo run -- more-populous Brazil
cargo run -- neighbors Brazil

Country arguments accept an English name or a three-letter ISO code. Lists are sorted alphabetically and contain no duplicates.

Prolog rules

  • large_country(Country) finds countries with more than 100 million people.
  • country_in_region(Country, Region) finds countries in a region.
  • more_populous(CountryA, CountryB) finds countries with a larger population.
  • borders(Country, Neighbor) finds countries that share a land border.

Project structure

  • src/main.rs defines the CLI and connects Rust to Prolog.
  • src/query_countries.rs fetches and decodes the required API data.
  • rules.pl contains the four Prolog rules.
  • .env.example documents the required environment variable.

Validation

Run the automated checks with:

cargo test
cargo clippy --all-targets -- -D warnings

Contributors

matheus-git

10 commits

matheus-git/country-logic

2

stars

10

commits

Rust

primary language

Sep 2, 2026

updated

cli
prolog
rust
scryer-prolog

README

Country Logic

Country Logic architecture — REST API, Rust CLI, Prolog rules, and results

Country Logic is a small command-line application for exploring country data with Rust and Prolog. It fetches names, regions, populations, ISO codes, and land borders from the REST Countries API, converts that data into Prolog facts, and evaluates four simple logical rules with an embedded Scryer Prolog engine.

The project is intentionally compact. Rust handles the command-line interface, HTTP requests, JSON decoding, and Prolog integration. The rules in rules.pl handle country relationships and population queries.

Requirements

Setup

Copy the example environment file:

cp .env.example .env

Then replace the placeholder in .env with your API key:

RESTCOUNTRIES_API_KEY=your_key

The .env file is ignored by Git. An existing environment variable takes precedence over the value in that file.

Usage

List all countries or regions:

cargo run -- countries
cargo run -- regions

Run country queries:

cargo run -- large
cargo run -- region Americas
cargo run -- more-populous Brazil
cargo run -- neighbors Brazil

Country arguments accept an English name or a three-letter ISO code. Lists are sorted alphabetically and contain no duplicates.

Prolog rules

  • large_country(Country) finds countries with more than 100 million people.
  • country_in_region(Country, Region) finds countries in a region.
  • more_populous(CountryA, CountryB) finds countries with a larger population.
  • borders(Country, Neighbor) finds countries that share a land border.

Project structure

  • src/main.rs defines the CLI and connects Rust to Prolog.
  • src/query_countries.rs fetches and decodes the required API data.
  • rules.pl contains the four Prolog rules.
  • .env.example documents the required environment variable.

Validation

Run the automated checks with:

cargo test
cargo clippy --all-targets -- -D warnings

See what people are saying

Contributors

matheus-git

10 commits

Languages

Rust

95.3%

Prolog

4.7%