From fa8c81fd82cce2d342a915997a1d7373b5486270 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 14 Apr 2023 10:30:19 +0200 Subject: [PATCH] Add AsTypeDescription impl for human_repr types Signed-off-by: Matthias Beyer --- Cargo.lock | 7 ++++ Cargo.toml | 2 + src/lib.rs | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 9483ee9..c6285da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -321,6 +321,12 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" +[[package]] +name = "human-repr" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0fb489e3108b684bba475a4cb9804260365870e2f60058265e3d0a3b309bdb1" + [[package]] name = "idna" version = "0.3.0" @@ -778,6 +784,7 @@ version = "0.4.0" dependencies = [ "bytesize", "clap", + "human-repr", "indexmap", "nu-ansi-term", "pretty", diff --git a/Cargo.toml b/Cargo.toml index 9f73ca3..989dae0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,6 +27,7 @@ bin = ["render", "dep:clap", "dep:serde_json", "dep:term_size"] bytesize = ["dep:bytesize"] url = ["dep:url"] uuid = ["dep:uuid"] +human-repr = ["dep:human-repr"] [dependencies] clap = { version = "4.2.1", features = ["derive"], optional = true } @@ -42,6 +43,7 @@ type_description_derive = { version = "0.4.0", path = "type_description_derive" bytesize = { version = "1", optional = true } url = { version = "2", optional = true } uuid = { version = "1", optional = true } +human-repr = { version = "1", optional = true } [dev-dependencies] serde = { version = "1.0.159", features = ["derive"] } diff --git a/src/lib.rs b/src/lib.rs index aabf282..9bbeabc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -315,6 +315,115 @@ impl_config_kind!(TypeKind::String; "String"; "An URL" => url::Url); #[cfg(feature = "uuid")] impl_config_kind!(TypeKind::String; "String"; "A UUID" => uuid::Uuid); +#[cfg(feature = "human_repr")] +impl AsTypeDescription for human_repr::HumanCountData { + fn as_type_description() -> TypeDescription { + TypeDescription::new( + "String".into(), + TypeKind::String, + Some(indoc::indoc! {r#" + A String that represents a count of something + + ## Examples + + A number of bytes: + + ``` + 43.21GB + ``` + + A number of "Packets": + + ``` + 123.5kPackets + ``` + + 74893200 of something unspecified: + + ``` + 74.9M + ``` + + ## More information + + For more information have a look at the documentation of + [the human_repr crate](https://docs.rs/human_repr). + "#} + ), + ) + } +} + +#[cfg(feature = "human_repr")] +impl AsTypeDescription for human_repr::HumanDurationData { + fn as_type_description() -> TypeDescription { + TypeDescription::new( + "String".into(), + TypeKind::String, + Some(indoc::indoc! {r#" + A String that represents a duration + + Note that floating point rounding applies. + + ## Examples + + 10 milliseconds + + ``` + 10ms + ``` + + 3.435999 seconds: + + ``` + 3.44s + ``` + + ## More information + + For more information have a look at the documentation of + [the human_repr crate](https://docs.rs/human_repr). + "#} + ), + ) + } +} + +#[cfg(feature = "human_repr")] +impl AsTypeDescription for human_repr::HumanThroughputData { + fn as_type_description() -> TypeDescription { + TypeDescription::new( + "String".into(), + TypeKind::String, + Some(indoc::indoc! {r#" + A String that represents a throughput + + Note that floating point rounding applies. + + ## Examples + + 1.2 Megabytes per second: + + ``` + 1.2MB/s + ``` + + 6.1 tests per Minute + + ``` + 6.1tests/m + ``` + + ## More information + + For more information have a look at the documentation of + [the human_repr crate](https://docs.rs/human_repr). + "#} + ), + ) + } +} + impl_config_kind!(TypeKind::String; "String"; "A filesystem path" => std::path::PathBuf); #[cfg(test)]