pub struct OwnedString { /* private fields */ }Expand description
Rust-side ownership of an ABI string and its producer’s deallocator.
Not Copy or Clone: moving the value transfers cleanup responsibility.
ⓘ
use rpi_plugin_sdk::callbacks::OwnedString;
let owner = OwnedString::from_string("text".into());
let copy = owner;
drop(owner); // Ownership moved; a second release cannot be expressed safely.Implementations§
Source§impl OwnedString
impl OwnedString
pub fn from_string(text: String) -> Self
Sourcepub unsafe fn from_raw(raw: StbString, free: Option<FreeStringFn>) -> Self
pub unsafe fn from_raw(raw: StbString, free: Option<FreeStringFn>) -> Self
Adopt an owning string at an ABI boundary.
§Safety
The caller transfers unique ownership of a live buffer satisfying
StbString::to_string_lossy’s requirements. No raw copy may subsequently
be read, changed or freed while this owner exists. free, when present,
must be this buffer’s producer-side deallocator, callable from any thread.
When absent, the allocation will not be reclaimed automatically.
pub fn to_string_lossy(&self) -> String
Sourcepub fn as_str_lossy(&self) -> Cow<'_, str>
pub fn as_str_lossy(&self) -> Cow<'_, str>
Read the buffer without copying valid UTF-8. Invalid UTF-8 is replaced,
matching Self::to_string_lossy. The view cannot outlive its owner.
ⓘ
use rpi_plugin_sdk::callbacks::OwnedString;
let text = {
let owner = OwnedString::from_string("text".into());
owner.as_str_lossy()
};
println!("{text}");Trait Implementations§
Source§impl Drop for OwnedString
impl Drop for OwnedString
Auto Trait Implementations§
impl Freeze for OwnedString
impl RefUnwindSafe for OwnedString
impl Send for OwnedString
impl Sync for OwnedString
impl Unpin for OwnedString
impl UnsafeUnpin for OwnedString
impl UnwindSafe for OwnedString
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