Skip to content

Commit

Permalink
Add AsTypeDescription impl for human_repr types
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Beyer <[email protected]>
  • Loading branch information
matthiasbeyer committed Apr 14, 2023
1 parent 64bac97 commit fa8c81f
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"] }
Expand Down
109 changes: 109 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> AsTypeDescription for human_repr::HumanCountData<T> {
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<T> AsTypeDescription for human_repr::HumanThroughputData<T> {
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)]
Expand Down

0 comments on commit fa8c81f

Please sign in to comment.