Skip to main content

MaaStringBuffer

Struct MaaStringBuffer 

Source
pub struct MaaStringBuffer { /* private fields */ }
Expand description

A string buffer for UTF-8 text data.

Used for passing strings between Rust and the C API. Automatically freed when dropped.

Implementations§

Source§

impl MaaStringBuffer

Source

pub fn new() -> MaaResult<Self>

Create a new buffer.

Source

pub unsafe fn from_raw(handle: *mut MaaStringBuffer) -> Self

Create from an existing handle.

§Safety

This function assumes the handle is valid. The returned buffer will NOT take ownership of the handle (it won’t be destroyed on drop). Use this when you are borrowing a handle from the C API.

Source

pub fn from_handle(handle: *mut MaaStringBuffer) -> Option<Self>

Create from an existing handle safely (checks for null). Returns None if handle is null.

Source

pub fn as_ptr(&self) -> *mut MaaStringBuffer

Get the underlying raw handle.

Source

pub fn raw(&self) -> *mut MaaStringBuffer

Get the underlying raw handle (alias for as_ptr).

Source§

impl MaaStringBuffer

Source

pub fn set<S: AsRef<str>>(&mut self, content: S) -> MaaResult<()>

Set the buffer content from a string.

Source

pub fn set_ex<B: AsRef<[u8]>>(&mut self, content: B) -> MaaResult<()>

Set the buffer content from raw bytes (zero-copy if possible).

This uses MaaStringBufferSetEx which accepts a length, allowing passing bytes without explicit null termination if the API supports it.

Source

pub fn as_str(&self) -> &str

Get the buffer content as a string slice.

Source

pub fn as_bytes(&self) -> &[u8]

Get the buffer content as a byte slice.

Source

pub fn is_empty(&self) -> bool

Check if the buffer is empty.

Source

pub fn clear(&mut self) -> MaaResult<()>

Clear the buffer.

Source

pub fn len(&self) -> usize

Get the size of the buffer content (excluding null terminator).

Trait Implementations§

Source§

impl AsRef<str> for MaaStringBuffer

Source§

fn as_ref(&self) -> &str

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl Debug for MaaStringBuffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MaaStringBuffer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for MaaStringBuffer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for MaaStringBuffer

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl From<&str> for MaaStringBuffer

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl Send for MaaStringBuffer

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.