Skip to content

Commit a7e4d9f

Browse files
committed
Add From<FixedString/Array> impls for Cow<'static, str/[T]>
1 parent 52f55af commit a7e4d9f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/array.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{fmt::Debug, hash::Hash, mem::ManuallyDrop, ptr::NonNull};
1+
use std::{borrow::Cow, fmt::Debug, hash::Hash, mem::ManuallyDrop, ptr::NonNull};
22

33
use crate::length::{InvalidLength, SmallLen, ValidLength};
44

@@ -217,6 +217,12 @@ impl<T, LenT: ValidLength> From<FixedArray<T, LenT>> for Vec<T> {
217217
}
218218
}
219219

220+
impl<T: Clone, LenT: ValidLength> From<FixedArray<T, LenT>> for Cow<'static, [T]> {
221+
fn from(value: FixedArray<T, LenT>) -> Self {
222+
Cow::Owned(value.into_vec())
223+
}
224+
}
225+
220226
impl<T, LenT: ValidLength> TryFrom<Box<[T]>> for FixedArray<T, LenT> {
221227
type Error = InvalidLength<T>;
222228
fn try_from(boxed_array: Box<[T]>) -> Result<Self, Self::Error> {

src/string.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{cmp::PartialEq, fmt::Write as _, hash::Hash};
1+
use std::{borrow::Cow, cmp::PartialEq, fmt::Write as _, hash::Hash};
22

33
use crate::{
44
array::FixedArray,
@@ -205,6 +205,12 @@ impl<LenT: ValidLength> From<FixedString<LenT>> for String {
205205
}
206206
}
207207

208+
impl<LenT: ValidLength> From<FixedString<LenT>> for Cow<'static, str> {
209+
fn from(value: FixedString<LenT>) -> Self {
210+
Cow::Owned(value.into_string())
211+
}
212+
}
213+
208214
impl<LenT: ValidLength> AsRef<str> for FixedString<LenT> {
209215
fn as_ref(&self) -> &str {
210216
self

0 commit comments

Comments
 (0)