non_empty_string/trait_impls/
mod.rs

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
use std::borrow::Borrow;

mod delegated_traits;

use crate::NonEmptyString;

#[cfg(not(no_global_oom_handling))]
impl From<char> for NonEmptyString {
    #[inline]
    fn from(c: char) -> Self {
        let string = c.to_string();
        NonEmptyString::new(string).expect("since there is a singular char, the string will not be empty as it will contain exactly one char")
    }
}

// Defined in the file for [`str`], not [`String`]
impl Borrow<str> for NonEmptyString {
    fn borrow(&self) -> &str {
        <String as Borrow<str>>::borrow(&self.0)
    }
}

impl Borrow<String> for NonEmptyString {
    fn borrow(&self) -> &String {
        &self.0
    }
}