Skip to content

Commit

Permalink
Impl From<C: CountUInt> for counters
Browse files Browse the repository at this point in the history
  • Loading branch information
nvzqz committed Nov 7, 2023
1 parent 9788513 commit 7af51c4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ Versioning](http://semver.org/spec/v2.0.0.html).

### Added

- `From<C>` for
[`ItemsCount`](https://docs.rs/divan/X.Y.Z/divan/counter/struct.ItemsCount.html),
[`BytesCount`](https://docs.rs/divan/X.Y.Z/divan/counter/struct.BytesCount.html),
and
[`CharsCount`](https://docs.rs/divan/X.Y.Z/divan/counter/struct.CharsCount.html)
where `C` is `u8``u64` or `usize` (via `CountUInt` internally). This provides
an alternative to the `new` constructor.

- [`BytesCount::of_many`](https://docs.rs/divan/X.Y.Z/divan/counter/struct.BytesCount.html#method.of_many)
method similar to [`BytesCount::of`](https://docs.rs/divan/0.1/divan/counter/struct.BytesCount.html#method.of),
but with a parameter by which to multiply the size of the type.
Expand Down
21 changes: 21 additions & 0 deletions src/counter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,27 @@ impl Counter for BytesCount {}
impl Counter for CharsCount {}
impl Counter for ItemsCount {}

impl<C: CountUInt> From<C> for BytesCount {
#[inline]
fn from(count: C) -> Self {
Self::new(count)
}
}

impl<C: CountUInt> From<C> for CharsCount {
#[inline]
fn from(count: C) -> Self {
Self::new(count)
}
}

impl<C: CountUInt> From<C> for ItemsCount {
#[inline]
fn from(count: C) -> Self {
Self::new(count)
}
}

impl BytesCount {
/// Count N bytes.
#[inline]
Expand Down

0 comments on commit 7af51c4

Please sign in to comment.