Skip to content

Commit

Permalink
Add Cow::Borrowed conversion implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed Nov 11, 2024
1 parent 8a94e33 commit 4578684
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ impl<T, LenT: ValidLength> From<FixedArray<T, LenT>> for Vec<T> {
}
}

impl<'a, T: Clone, LenT: ValidLength> From<&'a FixedArray<T, LenT>> for Cow<'a, [T]> {
fn from(value: &'a FixedArray<T, LenT>) -> Self {
Cow::Borrowed(value.as_slice())
}
}

impl<T: Clone, LenT: ValidLength> From<FixedArray<T, LenT>> for Cow<'_, [T]> {
fn from(value: FixedArray<T, LenT>) -> Self {
Cow::Owned(value.into_vec())
Expand Down
6 changes: 6 additions & 0 deletions src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,12 @@ impl<LenT: ValidLength> From<FixedString<LenT>> for String {
}
}

impl<'a, LenT: ValidLength> From<&'a FixedString<LenT>> for Cow<'a, str> {
fn from(value: &'a FixedString<LenT>) -> Self {
Cow::Borrowed(value.as_str())
}
}

impl<LenT: ValidLength> From<FixedString<LenT>> for Cow<'_, str> {
fn from(value: FixedString<LenT>) -> Self {
Cow::Owned(value.into_string())
Expand Down

0 comments on commit 4578684

Please sign in to comment.