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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use crate::{
    Bin, BooToOwned, DefaultStrBuilder, NewBin, NewSBin, SBin, SStr, Str, StrBuilder, StrFactory,
};
use std::marker::PhantomData;

/// Default implementation used to create `Str`. See `StrFactory` for documentation.
///
/// ```rust
/// use abin::{Str, NewStr, StrFactory};
/// let string : Str = NewStr::from_static("Hello, I'm a binary!");
/// assert_eq!("Hello, I'm a binary!", string.as_str());
/// ```
pub struct NewStr {
    _phantom: PhantomData<()>,
}

impl NewStr {
    /// Constructs a builder that can be used to create `Str`.
    #[inline]
    pub fn builder<'a>() -> impl StrBuilder<'a, T = Bin> {
        DefaultStrBuilder::new(NewBin::builder())
    }
}

impl StrFactory for NewStr {
    type TBinFactory = NewBin;
}

impl BooToOwned<str, Str> for NewStr {
    fn convert_to_owned(borrowed: &str) -> Str {
        Self::copy_from_str(borrowed)
    }
}

/// Default implementation used to create `SStr`. See `StrFactory` for documentation.
///
/// ```rust
/// use abin::{SStr, NewSStr, StrFactory};
/// let string : SStr = NewSStr::from_static("Hello, I'm a binary!");
/// assert_eq!("Hello, I'm a binary!", string.as_str());
/// ```
pub struct NewSStr {
    _phantom: PhantomData<()>,
}

impl NewSStr {
    /// Constructs a builder that can be used to create `SStr`.
    #[inline]
    pub fn builder<'a>() -> impl StrBuilder<'a, T = SBin> {
        DefaultStrBuilder::new(NewSBin::builder())
    }
}

impl StrFactory for NewSStr {
    type TBinFactory = NewSBin;
}

impl BooToOwned<str, SStr> for NewSStr {
    fn convert_to_owned(borrowed: &str) -> SStr {
        Self::copy_from_str(borrowed)
    }
}