Crates.io | country-code-enum |
lib.rs | country-code-enum |
version | 0.2.0 |
source | src |
created_at | 2024-10-05 19:28:04.027475 |
updated_at | 2024-10-06 02:23:54.038292 |
description | Copyable Serde and Sqlx compatible country codes |
homepage | |
repository | https://github.com/imbolc/country-code-enum |
max_upload_size | |
id | 1398408 |
size | 22,519 |
Copyable Serde and Sqlx compatible country codes
use country_code_enum::CountryCode;
let argentina: CountryCode = "AR".parse().unwrap();
assert_eq!(argentina, CountryCode::AR);
assert_eq!(argentina.as_ref(), "AR");
assert_eq!(argentina.name(), "Argentina");
use country_code_enum::CountryCode;
#[cfg(feature = "serde")]
{
let argentina: CountryCode = serde_json::from_str("\"AR\"").unwrap();
assert_eq!(argentina, CountryCode::AR);
assert_eq!(serde_json::to_string(&argentina).unwrap(), "\"AR\"");
}
use country_code_enum::CountryCode;
async fn sqlx_example(pool: sqlx::PgPool) {
let argentina = sqlx::query_scalar!(r#"SELECT 'AR'::varchar as "val: CountryCode""#)
.fetch_one(&pool)
.await
.unwrap()
.unwrap();
assert_eq!(argentina, CountryCode::AR);
let s = sqlx::query_scalar!("SELECT $1::varchar", argentina as _)
.fetch_one(&pool)
.await
.unwrap()
.unwrap();
assert_eq!(s, "AR");
}
please run .pre-commit.sh before sending a PR, it will check everything
This project is licensed under the MIT license.