diff --git a/.gitignore b/.gitignore index e88a27a..ff11fa7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,14 @@ -# System -.DS_Store - -# Integrated development environment +# Integrated development environment. .vscode -# Package manager -## Cargo +# Package manager. +## Cargo. target -## NPM +## NPM. node_modules -# Test data +# System. +.DS_Store + +# Test data. tmp diff --git a/.rustfmt.toml b/.rustfmt.toml index 1b83aba..8a01662 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -1,18 +1,18 @@ -# Basic +# Basic. edition = "2021" hard_tabs = true max_width = 100 tab_spaces = 4 -# Imports +# Import. imports_granularity = "Crate" reorder_imports = true -# Format comments +# Comments. comment_width = 100 wrap_comments = true -# Misc +# Misc. format_code_in_doc_comments = true inline_attribute_width = 100 match_arm_blocks = false diff --git a/Cargo.lock b/Cargo.lock index bc61060..32954bb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,57 +1,88 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 + +[[package]] +name = "itoa" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674" [[package]] name = "language" -version = "0.1.2" +version = "0.1.3" dependencies = [ "serde", + "serde_json", ] +[[package]] +name = "memchr" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" + [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.36" +version = "1.0.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc" dependencies = [ "proc-macro2", ] +[[package]] +name = "ryu" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" + [[package]] name = "serde" -version = "1.0.215" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f" +checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.215" +version = "1.0.217" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0" +checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" dependencies = [ "proc-macro2", "quote", "syn", ] +[[package]] +name = "serde_json" +version = "1.0.135" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b0d7ba2887406110130a978386c4e1befb98c674b4fba677954e4db976630d9" +dependencies = [ + "itoa", + "memchr", + "ryu", + "serde", +] + [[package]] name = "syn" -version = "2.0.82" +version = "2.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83540f837a8afc019423a8edb95b52a8effe46957ee402287f4292fae35be021" +checksum = "46f71c0377baf4ef1cc3e3402ded576dccc315800fbc62dfc7fe04b009773b4a" dependencies = [ "proc-macro2", "quote", @@ -60,6 +91,6 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.12" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83" diff --git a/Cargo.toml b/Cargo.toml index bfed38a..c480f21 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,15 +7,14 @@ license = "GPL-3.0" name = "language" readme = "README.md" repository = "https://github.com/hack-ink/language" -version = "0.1.2" +version = "0.1.3" [profile.ci-dev] incremental = false inherits = "dev" -# [profile.ci-release] -# inherits = "release" -# lto = true - [dependencies] serde = { version = "1.0", optional = true, features = ["derive"] } + +[dev-dependencies] +serde_json = { version = "1.0" } diff --git a/src/lib.rs b/src/lib.rs index dbc47c0..1cc1aab 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,10 +9,11 @@ use serde::{ ser::Serializer, Deserialize, Serialize, }; +#[cfg(all(not(feature = "serde"), test))] use serde_json as _; // self use Language::*; -/// Language collection. +#[allow(missing_docs)] #[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] pub enum Language { /// Afrikaans (South Africa) @@ -1818,3 +1819,14 @@ impl<'de> Deserialize<'de> for Language { Language::from_tag(&tag).ok_or_else(|| Error::unknown_variant(&tag, &[])) } } + +#[cfg(feature = "serde")] +#[test] +fn serde_should_work() { + let lang = Language::EnUs; + let serialized = serde_json::to_string(&lang).unwrap(); + assert_eq!(serialized, "\"en-US\""); + + let deserialized: Language = serde_json::from_str(&serialized).unwrap(); + assert_eq!(deserialized, lang); +}