pub struct SeqString { /* private fields */ }Expand description
Byte string that tracks its allocation source.
§Safety Invariants
- If
global=true:ptrpoints to a global-allocated byte buffer whose memory matcheslen/capacity; the buffer is freed onDrop. - If
global=false:ptrpoints into the thread-local arena; the arena owns the memory and frees it in bulk on strand exit. - The byte content is not required to be valid UTF-8.
- For global strings:
capacitymust match the originalVec<u8>’s capacity so deallocation is correctly sized.
Implementations§
Source§impl SeqString
impl SeqString
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Borrow the underlying bytes. Always succeeds; the type carries no UTF-8 invariant. Byte-clean operations (concat, byte length, equality, search, network I/O, crypto, etc.) should use this.
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
View as &str if the bytes happen to be valid UTF-8.
Text-level operations (codepoint counting, case folding,
string.json-escape, regex.* with Unicode classes,
formatting for display) call this and treat None as a
fallible-text failure — the conventional (value Bool)
failure tuple, returning -1 / empty string / false per the
surrounding op’s contract.
Sourcepub fn as_str_lossy(&self) -> Cow<'_, str>
pub fn as_str_lossy(&self) -> Cow<'_, str>
View as &str, replacing any invalid UTF-8 with U+FFFD. Use
only for human-facing display where lossiness is acceptable
(Debug, panic messages, REPL output). Operations that round-
trip user data must use [as_bytes] or [as_str] instead.
Sourcepub fn as_str_or_empty(&self) -> &str
pub fn as_str_or_empty(&self) -> &str
View as &str, returning "" if the bytes aren’t valid UTF-8.
The convenience for text-required ops (string.length,
string.find, file paths, integer parsing, …) that expect a
&str and have an existing degenerate-result-or-failure-tuple
path for empty input. A non-UTF-8 input lands in that same
failure path, with no extra branching at every call site.
Sourcepub fn is_interned(&self) -> bool
pub fn is_interned(&self) -> bool
Check if this is an interned/static string (Issue #166)
Interned strings have capacity=0 and point to static data. They are never freed and can be compared by pointer for O(1) equality.
Trait Implementations§
Source§impl Clone for SeqString
impl Clone for SeqString
Source§fn clone(&self) -> SeqString
fn clone(&self) -> SeqString
Clone always allocates from the global allocator for Send safety.
When a SeqString is sent through a channel, the receiving
strand gets an independent global-allocated copy that doesn’t
depend on the sender’s arena. Byte-clean: copies the underlying
&[u8], no UTF-8 validation.
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more