pub trait SemanticString<const CAPACITY: usize>: Sized + SemanticStringAccessor<CAPACITY> + Debug + Display + Deref<Target = [u8]> + PartialEq + Eq + Hash {
Show 23 methods
// Required methods
fn as_string(&self) -> &FixedSizeByteString<CAPACITY>;
unsafe fn new_unchecked(bytes: &[u8]) -> Self;
unsafe fn insert_bytes_unchecked(&mut self, idx: usize, bytes: &[u8]);
fn normalize(&self) -> Self;
// Provided methods
fn new(value: &[u8]) -> Result<Self, SemanticStringError> { ... }
unsafe fn from_c_str(ptr: *mut i8) -> Result<Self, SemanticStringError> { ... }
fn as_bytes(&self) -> &[u8] ⓘ { ... }
fn as_c_str(&self) -> *const i8 { ... }
fn capacity(&self) -> usize { ... }
fn is_full(&self) -> bool { ... }
fn is_empty(&self) -> bool { ... }
fn len(&self) -> usize { ... }
fn insert(
&mut self,
idx: usize,
byte: u8
) -> Result<(), SemanticStringError> { ... }
fn insert_bytes(
&mut self,
idx: usize,
bytes: &[u8]
) -> Result<(), SemanticStringError> { ... }
fn pop(&mut self) -> Result<Option<u8>, SemanticStringError> { ... }
fn push(&mut self, byte: u8) -> Result<(), SemanticStringError> { ... }
fn push_bytes(&mut self, bytes: &[u8]) -> Result<(), SemanticStringError> { ... }
fn remove(&mut self, idx: usize) -> Result<u8, SemanticStringError> { ... }
fn remove_range(
&mut self,
idx: usize,
len: usize
) -> Result<(), SemanticStringError> { ... }
fn retain<F>(&mut self, f: F) -> Result<(), SemanticStringError>
where F: FnMut(u8) -> bool { ... }
fn strip_prefix(
&mut self,
bytes: &[u8]
) -> Result<bool, SemanticStringError> { ... }
fn strip_suffix(
&mut self,
bytes: &[u8]
) -> Result<bool, SemanticStringError> { ... }
fn truncate(&mut self, new_len: usize) -> Result<(), SemanticStringError> { ... }
}
Expand description
Trait that defines the methods a FixedSizeByteString
with context semantics, a
SemanticString
shares. A new SemanticString
can be created with the crate::semantic_string!
macro. For the usage, see crate::semantic_string
.
Required Methods§
sourcefn as_string(&self) -> &FixedSizeByteString<CAPACITY>
fn as_string(&self) -> &FixedSizeByteString<CAPACITY>
Returns a reference to the underlying FixedSizeByteString
sourceunsafe fn new_unchecked(bytes: &[u8]) -> Self
unsafe fn new_unchecked(bytes: &[u8]) -> Self
Creates a new content but does not verify that it does not contain invalid characters.
§Safety
- The slice must contain only valid characters.
- The slice must have a length that is less or equal CAPACITY
- The slice must not contain invalid UTF-8 characters
sourceunsafe fn insert_bytes_unchecked(&mut self, idx: usize, bytes: &[u8])
unsafe fn insert_bytes_unchecked(&mut self, idx: usize, bytes: &[u8])
Adds bytes to the string without checking if they only contain valid characters or would result in a valid result.
§Safety
- The user must ensure that the bytes contain only valid characters.
- The user must ensure that the result, after the bytes were added, is valid.
- The slice must have a length that is less or equal CAPACITY
- The slice is not contain invalid UTF-8 characters
sourcefn normalize(&self) -> Self
fn normalize(&self) -> Self
Normalizes the string. This function is used as basis for core::hash::Hash
and
PartialEq
. Normalizing a SemanticString
means to bring it to some format so that it
contains still the same semantic content but in an uniform way so that strings, with the
same semantic content but different representation compare as equal.
Provided Methods§
sourcefn new(value: &[u8]) -> Result<Self, SemanticStringError>
fn new(value: &[u8]) -> Result<Self, SemanticStringError>
Creates a new content. If it contains invalid characters or exceeds the maximum supported length of the system or contains illegal strings it fails.
sourceunsafe fn from_c_str(ptr: *mut i8) -> Result<Self, SemanticStringError>
unsafe fn from_c_str(ptr: *mut i8) -> Result<Self, SemanticStringError>
Creates a new content from a given ptr. The user has to ensure that it is null-terminated.
§Safety
- The pointer must be ‘\0’ (null) terminated
- The pointer must be valid and non-null
- The contents must have a length that is less or equal CAPACITY
- The contents must not contain invalid UTF-8 characters
sourcefn insert(&mut self, idx: usize, byte: u8) -> Result<(), SemanticStringError>
fn insert(&mut self, idx: usize, byte: u8) -> Result<(), SemanticStringError>
Inserts a single byte at a specific position. When the capacity is exceeded, the byte is an illegal character or the content would result in an illegal content it fails.
sourcefn insert_bytes(
&mut self,
idx: usize,
bytes: &[u8]
) -> Result<(), SemanticStringError>
fn insert_bytes( &mut self, idx: usize, bytes: &[u8] ) -> Result<(), SemanticStringError>
Inserts a byte slice at a specific position. When the capacity is exceeded, the byte slice contains illegal characters or the content would result in an illegal content it fails.
sourcefn pop(&mut self) -> Result<Option<u8>, SemanticStringError>
fn pop(&mut self) -> Result<Option<u8>, SemanticStringError>
Removes the last character. If the string is empty it returns None
.
If the removal would create an illegal content it fails.
sourcefn push(&mut self, byte: u8) -> Result<(), SemanticStringError>
fn push(&mut self, byte: u8) -> Result<(), SemanticStringError>
Adds a single byte at the end. When the capacity is exceeded, the byte is an illegal character or the content would result in an illegal content it fails.
sourcefn push_bytes(&mut self, bytes: &[u8]) -> Result<(), SemanticStringError>
fn push_bytes(&mut self, bytes: &[u8]) -> Result<(), SemanticStringError>
Adds a byte slice at the end. When the capacity is exceeded, the byte slice contains illegal characters or the content would result in an illegal content it fails.
sourcefn remove(&mut self, idx: usize) -> Result<u8, SemanticStringError>
fn remove(&mut self, idx: usize) -> Result<u8, SemanticStringError>
Removes a byte at a specific position and returns it. If the removal would create an illegal content it fails.
sourcefn remove_range(
&mut self,
idx: usize,
len: usize
) -> Result<(), SemanticStringError>
fn remove_range( &mut self, idx: usize, len: usize ) -> Result<(), SemanticStringError>
Removes a range. If the removal would create an illegal content it fails.
sourcefn retain<F>(&mut self, f: F) -> Result<(), SemanticStringError>
fn retain<F>(&mut self, f: F) -> Result<(), SemanticStringError>
Removes all bytes which satisfy the provided clojure f. If the removal would create an illegal content it fails.
sourcefn strip_prefix(&mut self, bytes: &[u8]) -> Result<bool, SemanticStringError>
fn strip_prefix(&mut self, bytes: &[u8]) -> Result<bool, SemanticStringError>
Removes a prefix. If the prefix does not exist it returns false. If the removal would lead
to an invalid string content it fails and returns SemanticStringError::InvalidContent
.
After a successful removal it returns true.
sourcefn strip_suffix(&mut self, bytes: &[u8]) -> Result<bool, SemanticStringError>
fn strip_suffix(&mut self, bytes: &[u8]) -> Result<bool, SemanticStringError>
Removes a suffix. If the suffix does not exist it returns false. If the removal would lead
to an invalid string content it fails and returns SemanticStringError::InvalidContent
.
After a successful removal it returns true.