#[repr(C)]pub struct RbStringOwned {
pub len: u32,
pub data: *mut u8,
pub capacity: u32,
}Expand description
FFI-safe owned string
Unlike RbString, this type owns its memory and must be freed by calling
rb_string_free. This is used for strings returned from Rust to the host.
§Memory Ownership
- Memory is allocated by Rust
- Must be freed by calling
rb_string_free - Do NOT free with host language’s free()
Fields§
§len: u32Length in bytes (excluding null terminator)
data: *mut u8Pointer to null-terminated UTF-8 data (Rust-owned)
capacity: u32Allocation capacity (for proper deallocation)
Implementations§
Source§impl RbStringOwned
impl RbStringOwned
Sourcepub fn from_string(s: String) -> Self
pub fn from_string(s: String) -> Self
Create from a Rust String (takes ownership)
The string will be null-terminated for C compatibility.
Sourcepub fn from_slice(s: &str) -> Self
pub fn from_slice(s: &str) -> Self
Create from a string slice (copies data)
Sourcepub fn as_borrowed(&self) -> RbString
pub fn as_borrowed(&self) -> RbString
Convert to borrowed RbString
Trait Implementations§
Source§impl Debug for RbStringOwned
impl Debug for RbStringOwned
Source§impl Default for RbStringOwned
impl Default for RbStringOwned
impl Send for RbStringOwned
Auto Trait Implementations§
impl Freeze for RbStringOwned
impl RefUnwindSafe for RbStringOwned
impl !Sync for RbStringOwned
impl Unpin for RbStringOwned
impl UnsafeUnpin for RbStringOwned
impl UnwindSafe for RbStringOwned
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