logos.mem.string
Module mem · package logos-mem
Traits
traitToString
trait ToString
Converts a value to an owned String (Rust-style .to_string()).
Takes self by value; the blanket impl<T: Display> ToString for T lives in mem.fmt.
Implemented by: bool i8 i16 i32 i64 u8 u16 u32 u64 usize isize f32 f64 str T
Types
structString
struct String
Owned, heap-allocated, growable byte string.
Invariant: data[nbytes] == 0 (null terminator always present when cap > 0).
Implements: Send Sync Drop Eq Datum FmtWrite Display Debug
Fields
cap: i64
data: *mut u8
nbytes: i64
Methods
fn advance_len(self: &mut String, n: i64) -> void
Advances the content length by n bytes and writes the null terminator.
Call after writing into the buffer returned by spare_ptr.
fn as_datum(self: &String) -> DView
Captures the UTF-8 content bytes (not the {ptr,len,cap} struct) as a W_STRING view.
fn as_ptr(self: &String) -> *const u8
Returns a read-only pointer to the null-terminated bytes; null if never allocated.
fn as_str(self: &String) -> &[u8]
Returns a read-only str view of the content bytes.
fn capacity(self: &String) -> i64
Returns the allocated capacity in bytes, excluding the null-terminator slot.
fn clear(self: &mut String) -> void
Resets the length to zero, keeping the allocation.
fn datum_meta(self: &String) -> u64
fn drop(self: String) -> void
fn eq(self: &String, other: &String) -> bool
fn eq_cstr(self: &String, s: *const u8) -> bool
Returns true if the content equals the null-terminated C string s.
fn eq_str(self: &String, s: &[u8]) -> bool
Returns true if the content equals the str slice s.
fn eq_string(self: &String, other: &String) -> bool
Returns true if the content bytes equal other’s.
fn from(s: &[u8]) -> String
Creates a String by copying a str slice (Rust-style String::from("...")).
fn from_bytes(s: *const u8, n: i64) -> String
Creates a String by copying n bytes from s.
fn from_cstr(s: *const u8) -> String
Creates a String by copying a null-terminated C string.
fn grow(self: &mut String, needed: i64) -> void
Ensures capacity for needed additional content bytes plus the null terminator.
No-op (buffer and length preserved) on needed < 0, overflow, or allocation failure.
fn is_empty(self: &String) -> bool
Returns true if the length is zero.
fn len(self: &String) -> i64
Returns the number of content bytes, excluding the null terminator.
fn ne(self: &String, other: &String) -> bool
fn new() -> String
Creates an empty String with no heap allocation.
fn push_bytes(self: &mut String, s: *const u8, n: i64) -> void
Appends n bytes from s; no-op if n <= 0.
fn push_char(self: &mut String, cp: u32) -> void
Encodes the Unicode codepoint cp as UTF-8 and appends it.
Invalid codepoints (surrogates, above U+10FFFF) append U+FFFD.
fn push_cstr(self: &mut String, s: *const u8) -> void
Appends a null-terminated C string.
fn push_i64(self: &mut String, v: i64) -> void
Appends the decimal representation of a signed 64-bit integer.
fn push_str(self: &mut String, s: &[u8]) -> void
Appends a str slice.
fn push_u64(self: &mut String, v: u64) -> void
Appends the decimal representation of an unsigned 64-bit integer.
fn push_u8(self: &mut String, c: u8) -> void
Appends a single byte.
fn spare_ptr(self: &mut String, reserve: i64) -> *mut u8
Ensures reserve spare bytes and returns a pointer to the first spare byte.
Write directly into the buffer, then call advance_len.
fn truncate(self: &mut String, new_len: i64) -> void
Truncates the length to new_len bytes; no-op if new_len >= len().
Negative values clamp to 0. The allocation is preserved.
fn with_capacity(cap: i64) -> String
Creates an empty String with capacity for cap content bytes.
On allocation failure, returns the unallocated String::new() state.