pub struct SharedStringArena { /* private fields */ }Implementations§
Sourcepub fn reset(
path: impl AsRef<Path>,
capacity_bytes: usize,
) -> Result<Self, ArenaError>
pub fn reset( path: impl AsRef<Path>, capacity_bytes: usize, ) -> Result<Self, ArenaError>
Truncate the arena at path and initialize an empty one,
invalidating every StringRef live peers hold. For a caller that
knows it owns the path.
pub fn open( path: impl AsRef<Path>, expected_capacity_bytes: usize, ) -> Result<Self, ArenaError>
Sourcepub fn open_read_only(
path: impl AsRef<Path>,
expected_capacity_bytes: usize,
) -> Result<Self, ArenaError>
pub fn open_read_only( path: impl AsRef<Path>, expected_capacity_bytes: usize, ) -> Result<Self, ArenaError>
Open an arena this process may only read.
open needs a read+write file handle, which a
consumer of a privileged producer’s arena does not have. Reads
behave identically; intern and friends return
ArenaError::ReadOnly.
Sourcepub fn is_writable(&self) -> bool
pub fn is_writable(&self) -> bool
Whether this mapping may be written.
pub fn capacity_bytes(&self) -> usize
pub fn used_bytes(&self) -> usize
pub fn remaining_bytes(&self) -> usize
Sourcepub fn intern(&self, s: &str) -> Result<StringRef, ArenaError>
pub fn intern(&self, s: &str) -> Result<StringRef, ArenaError>
Append a string to the arena. Returns a StringRef that resolves to the bytes in any mapping of the same file.
Returns Err(Full) when the arena has no room. The empty
string "" interns at the current offset with len = 0.
Sourcepub fn intern_bytes(&self, bytes: &[u8]) -> Result<StringRef, ArenaError>
pub fn intern_bytes(&self, bytes: &[u8]) -> Result<StringRef, ArenaError>
Append arbitrary bytes (not necessarily UTF-8) to the arena.
Useful for storing binary blobs alongside strings. Retrieve
with get_bytes; get will reject non-UTF-8 with
InvalidUtf8.
Sourcepub fn get_bytes(&self, r: StringRef) -> Result<&[u8], ArenaError>
pub fn get_bytes(&self, r: StringRef) -> Result<&[u8], ArenaError>
Resolve a StringRef to its &[u8]. Returns Err(InvalidRef)
when the ref doesn’t fall inside the arena’s used region.
Sourcepub fn get(&self, r: StringRef) -> Result<&str, ArenaError>
pub fn get(&self, r: StringRef) -> Result<&str, ArenaError>
Resolve a StringRef to a &str. Returns Err(InvalidUtf8)
when the bytes aren’t valid UTF-8 (the arena doesn’t enforce
validity per-segment; it’s checked on read).
Sourcepub fn intern_and_get(&self, s: &str) -> Result<(StringRef, &str), ArenaError>
pub fn intern_and_get(&self, s: &str) -> Result<(StringRef, &str), ArenaError>
Convenience: intern AND return a &str view into the
just-written bytes plus the ref.
Sourcepub fn clear(&self)
pub fn clear(&self)
Reset the arena to empty. NOT concurrency-safe; callers must ensure no other threads/processes are interning or reading. Existing StringRefs become invalid (their bytes may be overwritten by subsequent interns).
pub fn flush(&self) -> Result<(), ArenaError>
Sourcepub fn flush_async(&self) -> Result<(), ArenaError>
pub fn flush_async(&self) -> Result<(), ArenaError>
Non-blocking flush: schedules a writeback via the OS. Note: Windows is only partially async (sync to page cache, not to disk).