Crates.io | place_capitals |
lib.rs | place_capitals |
version | 0.1.1 |
source | src |
created_at | 2023-09-06 12:02:57.17069 |
updated_at | 2023-09-06 12:10:19.628324 |
description | Get place capitals for countries and USA states |
homepage | https://github.com/GeethaPardheev/place_capitals |
repository | https://github.com/GeethaPardheev/place_capitals |
max_upload_size | |
id | 965209 |
size | 16,903 |
The Place Capitals Crate is a Rust library designed to provide easy access to static data related to countries, their capitals, and USA states and their capitals. This crate offers convenient functions to check whether a given place is a country or a USA state, as well as the ability to retrieve the capital for a given place.
To use the Place Capitals Crate in your Rust project, add it as a dependency in your Cargo.toml
file:
[dependencies]
place-capitals = "0.1.0"
First, import the crate in your Rust project:
extern crate place_capitals;
use place_capitals::PlaceDetector;
fn main() {
// Create a new PlaceDetector instance
let detector = PlaceDetector::new();
// Check if a place is a country
let is_country = detector.is_country("France");
println!("Is it a country? {}", is_country); // Output: Is it a country? true
// Check if a place is a USA state
let is_usa_state = detector.is_usa_state("California");
println!("Is it a USA state? {}", is_usa_state); // Output: Is it a USA state? true
// Check an unknown place
let is_unknown = detector.is_country("Mars");
println!("Is it a country? {}", is_unknown); // Output: Is it a country? false
}
fn main() {
// Create a new PlaceDetector instance
let detector = PlaceDetector::new();
// Get the capital of a country
let country_capital = detector.get_capital("France");
println!("Capital of France: {:?}", country_capital); // Output: Capital of France: Some("Paris")
// Get the capital of a USA state
let usa_state_capital = detector.get_capital("California");
println!("Capital of California: {:?}", usa_state_capital); // Output: Capital of California: Some("Sacramento")
// Get the capital of an unknown place
let unknown_capital = detector.get_capital("Mars");
println!("Capital of Mars: {:?}", unknown_capital); // Output: Capital of Mars: None
}
This crate is distributed under the terms of the MIT License. See the LICENSE file for details.
Contributions to this crate are welcome! If you encounter any issues or have ideas for improvements, please open an issue or submit a pull request on the GitHub repository.