1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use crate::{
    arraystring::ArrayString, errors::CapacityError, len::LengthType, mem::SpareMemoryPolicy,
};

impl<L, SM, const C: usize> core::str::FromStr for ArrayString<L, SM, C>
where
    L: LengthType,
    SM: SpareMemoryPolicy<u8>,
{
    type Err = CapacityError;

    #[inline]
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        Self::try_from(s)
    }
}

#[cfg(test)]
mod testing {
    use crate as cds;
    use cds::{arraystring::ArrayString, errors::CapacityError, len::U8, mem::Uninitialized};
    use core::str::FromStr;

    #[test]
    fn test_from_str() {
        type AS = ArrayString<U8, Uninitialized, 4>;

        let s = AS::from_str("cds").unwrap();
        assert_eq!(s, "cds");

        let s = AS::from_str("").unwrap();
        assert_eq!(s, "");

        assert!(matches!(AS::from_str("abcdef"), Err(CapacityError)));
    }
}