small_fixed_array/
truncating_into.rs1use alloc::{string::String, vec::Vec};
2
3use crate::{FixedArray, FixedString, ValidLength};
4
5mod sealed {
6 use alloc::{string::String, vec::Vec};
7
8 pub trait Sealed {}
9
10 impl Sealed for String {}
11 impl<T> Sealed for Vec<T> {}
12}
13
14pub trait TruncatingInto<T>: sealed::Sealed {
19 fn trunc_into(self) -> T;
20}
21
22impl<LenT: ValidLength> TruncatingInto<FixedString<LenT>> for String {
23 fn trunc_into(self) -> FixedString<LenT> {
24 FixedString::from_string_trunc(self)
25 }
26}
27
28impl<T, LenT: ValidLength> TruncatingInto<FixedArray<T, LenT>> for Vec<T> {
29 fn trunc_into(self) -> FixedArray<T, LenT> {
30 FixedArray::from_vec_trunc(self)
31 }
32}