Skip to content

Commit

Permalink
more convenience methods for Chars (#6)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Klein <mklein@bitdrift.io>
  • Loading branch information
mattklein123 authored Dec 8, 2023
1 parent 0144102 commit 83ce4e0
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion protobuf/src/chars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ impl Chars {
pub fn into_bytes(self) -> Bytes {
self.0
}

/// Self-explanatory
pub fn as_str(&self) -> &str {
self
}
}

// Chars can be used as the key in a HashMap in a proto map. Because Chars is a wrapper around
Expand Down Expand Up @@ -92,9 +97,19 @@ impl Deref for Chars {
}
}

impl<T> AsRef<T> for Chars
where
T: ?Sized,
<Chars as Deref>::Target: AsRef<T>,
{
fn as_ref(&self) -> &T {
self.deref().as_ref()
}
}

impl Borrow<str> for Chars {
fn borrow(&self) -> &str {
&*self
self
}
}

Expand Down

0 comments on commit 83ce4e0

Please sign in to comment.