Skip to main content

just_string/
traits_t.rs

1use std::{
2    ffi::{CString, IntoStringError},
3    io,
4    net::{SocketAddr, ToSocketAddrs},
5    ops::Deref,
6    result::Result,
7    string::FromUtf8Error,
8    vec::IntoIter,
9};
10
11use crate::JustString;
12
13impl ToSocketAddrs for JustString<'_> {
14    type Iter = IntoIter<SocketAddr>;
15
16    fn to_socket_addrs(&self) -> io::Result<Self::Iter> {
17        self.deref().to_socket_addrs()
18    }
19}
20
21impl TryFrom<CString> for JustString<'_> {
22    type Error = IntoStringError;
23
24    fn try_from(value: CString) -> Result<Self, Self::Error> {
25        String::try_from(value).map(JustString::String)
26    }
27}
28
29impl TryFrom<Vec<u8>> for JustString<'_> {
30    type Error = FromUtf8Error;
31
32    fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
33        String::try_from(value).map(JustString::String)
34    }
35}