Buffer

Struct Buffer 

Source
pub struct Buffer<'l> {
    pub buffer: [c_char; 1024],
    /* private fields */
}
Expand description

String buffer that allows code to build Lua strings piecemeal.

This structure has a lifetime 'l because it internally stores a pointer to the Lua State that was used to initialize this buffer.

Fields§

§buffer: [c_char; 1024]

Implementations§

Source§

impl Buffer<'_>

Source

pub const fn zeroed() -> MaybeUninit<Self>

Construct an instance of Buffer that’s zeroed, and put it inside of MaybeUninit for future usage.

This actually puts the buffer into an invalid state - it must be used with luaL_buffinit to properly initialize it. Only then can it be assumed to be initialized.

Source

pub unsafe fn new_in_raw(l: *mut State) -> Self

Construct a properly initialized instance of Buffer with the capacity BUFFER_SIZE in the raw Lua state pointed to by l.

§Safety

l must point to a valid Lua State.

Source

pub unsafe fn prep_with( &mut self, size: usize, func: impl FnOnce(&mut [c_char]), )

Allocate enough space in the buffer for a given number of C characters, and use a Rust function to fill the space with characters.

§Safety

The underlying Lua state may raise a memory error.

Source

pub unsafe fn prep_default_with(&mut self, func: impl FnOnce(&mut [c_char]))

Allocate enough space in the buffer BUFFER_SIZE C characters, and use a Rust function to fill the space with characters.

See also Buffer::prep_with.

§Safety

The underlying Lua state may raise a memory error.

Source

pub const fn len(&self) -> usize

Get the current length of the buffer.

Equivalent to the C macro luaL_bufflen.

Source

pub const fn is_empty(&self) -> bool

Return true if the buffer is empty.

Source

pub const fn capacity(&self) -> usize

Get the current capacity of the buffer.

Source

pub fn contents(&mut self) -> &mut [c_char]

Return the current contents of the buffer as a Rust mutable slice.

Functionally equivalent to the C macro luaL_buffaddr.

Source

pub unsafe fn add_char(&mut self, ch: c_char)

Add 1 C character to the buffer.

Equivalent to the C macro luaL_addchar.

§Safety

The underlying Lua state may raise a memory error.

Source

pub fn remove(&mut self, delta: usize)

Remove a given number of C characters from the buffer. Equivalent to the C macro luaL_buffsub.

Source

pub unsafe fn add_chars(&mut self, data: &[c_char])

Add an array of C characters to the buffer.

Functionally equivalent to the function luaL_addlstring.

§Safety

The underlying Lua state may raise a memory error.

Source

pub unsafe fn add_string(&mut self, data: &CStr)

Add a C string to the buffer. Equivalent to the function luaL_addstring.

§Safety

The underlying Lua state may raise a memory error.

Source

pub fn add_value(&mut self)

Convert a value on top of the associated Lua stack to a string, and pop the result into the buffer.

Equivalent to the function luaL_addvalue.

Source

pub fn finish(self)

Equivalent to the function luaL_pushresult.

Trait Implementations§

Source§

impl<'l> Debug for Buffer<'l>

Source§

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

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

impl<'l> Ord for Buffer<'l>

Source§

fn cmp(&self, other: &Buffer<'l>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<'l> PartialEq for Buffer<'l>

Source§

fn eq(&self, other: &Buffer<'l>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'l> PartialOrd for Buffer<'l>

Source§

fn partial_cmp(&self, other: &Buffer<'l>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Write for Buffer<'_>

Source§

fn write_str(&mut self, s: &str) -> Result

Writes a string slice into this writer, returning whether the write succeeded. Read more
Source§

fn write_char(&mut self, c: char) -> Result

Writes a char into this writer, returning whether the write succeeded. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Glue for usage of the write! macro with implementors of this trait. Read more
Source§

impl<'l> Eq for Buffer<'l>

Source§

impl<'l> StructuralPartialEq for Buffer<'l>

Auto Trait Implementations§

§

impl<'l> Freeze for Buffer<'l>

§

impl<'l> RefUnwindSafe for Buffer<'l>

§

impl<'l> !Send for Buffer<'l>

§

impl<'l> !Sync for Buffer<'l>

§

impl<'l> Unpin for Buffer<'l>

§

impl<'l> UnwindSafe for Buffer<'l>

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, 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.