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 std::ffi::{CStr, CString};

use crate::pdcstring::{PdCStr, PdCString};

pub trait PdCStringExt
where
    Self: Sized,
{
    fn from_c_string(s: CString) -> Self;
    fn into_c_string(self) -> CString;
}

impl PdCStringExt for PdCString {
    fn from_c_string(s: CString) -> Self {
        Self::from_inner(s)
    }

    fn into_c_string(self) -> CString {
        self.into_inner()
    }
}

pub trait PdCStrExt {
    fn from_c_str(s: &CStr) -> &Self;
    fn as_c_str(&self) -> &CStr;
}

impl PdCStrExt for PdCStr {
    fn from_c_str(s: &CStr) -> &Self {
        Self::from_inner(s)
    }

    fn as_c_str(&self) -> &CStr {
        self.as_inner()
    }
}