pub struct CStringPtr { /* private fields */ }Expand description
RAII wrapper for C strings returned from FFI Ensures proper cleanup when the wrapper goes out of scope
This type is intentionally !Send and !Sync because the underlying C pointer comes from Go’s runtime which is not thread-safe.
Implementations§
Source§impl CStringPtr
impl CStringPtr
Sourcepub unsafe fn new(ptr: *mut c_char) -> Self
pub unsafe fn new(ptr: *mut c_char) -> Self
Creates a new wrapper from a raw pointer
§Safety
The caller must ensure that:
ptris either null or a valid pointer returned fromcue_eval_package- The pointer has not been freed already
- The pointer will not be used after this wrapper is dropped
- No other thread is accessing this pointer
- The memory pointed to by
ptrwill remain valid for the lifetime of this wrapper
§FFI Contract
This function expects that the Go side:
- Returns either null or a valid C string pointer
- Allocates memory that must be freed with
cue_free_string - Does not modify the memory after returning the pointer
Sourcepub unsafe fn to_str(&self) -> Result<&str>
pub unsafe fn to_str(&self) -> Result<&str>
Converts the C string to a Rust &str
§Safety
This function is safe to call when:
- The wrapped pointer is not null (checked with
debug_assert) - The pointer points to a valid null-terminated C string
- The pointed-to memory contains valid UTF-8 data
- The memory will not be modified during the lifetime of the returned &str
§Errors
Returns an error if the C string contains invalid UTF-8
§Panics
In debug builds, panics if the pointer is null
Trait Implementations§
Auto Trait Implementations§
impl Freeze for CStringPtr
impl RefUnwindSafe for CStringPtr
impl !Send for CStringPtr
impl !Sync for CStringPtr
impl Unpin for CStringPtr
impl UnwindSafe for CStringPtr
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more