Skip to content

Commit

Permalink
Add implementation for converting ShortString to String
Browse files Browse the repository at this point in the history
When integrating with other libraries it can be useful to get away from
protocol specific types especially for common types such as `String`.

Add an implementation for `From<ShortString> for String` to unwrap a
`ShortString` and get the original String back.
  • Loading branch information
tpoliaw committed Jul 18, 2024
1 parent c1fbf90 commit 1bae04e
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions types/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ impl fmt::Display for ShortString {
}
}

impl From<ShortString> for String {
fn from(value: ShortString) -> Self {
value.0
}
}

impl<'a> LongString {
/// Get a reference to a LongString as &[u8]
pub fn as_bytes(&'a self) -> &'a [u8] {
Expand Down

0 comments on commit 1bae04e

Please sign in to comment.