stack_cstr/
cstr_heap.rs

1use std::ffi::{CStr, CString, c_char};
2
3use crate::CStrLike;
4
5pub struct CStrHeap {
6    cstr: CString,
7}
8
9impl CStrHeap {
10    pub fn new(s: CString) -> Self {
11        Self { cstr: s }
12    }
13
14    pub fn as_ptr(&self) -> *const c_char {
15        self.cstr.as_ptr()
16    }
17
18    pub fn as_cstr(&self) -> &CStr {
19        self.cstr.as_c_str()
20    }
21}
22
23impl CStrLike for CStrHeap {
24    fn as_ptr(&self) -> *const c_char {
25        self.as_ptr()
26    }
27
28    fn as_cstr(&self) -> &CStr {
29        self.as_cstr()
30    }
31}