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§

source

fn as_string(&self) -> &FixedSizeByteString<CAPACITY>

Returns a reference to the underlying FixedSizeByteString

source

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
source

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
source

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§

source

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.

source

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
source

fn as_bytes(&self) -> &[u8]

Returns the contents as a slice

source

fn as_c_str(&self) -> *const i8

Returns a zero terminated slice of the underlying bytes

source

fn capacity(&self) -> usize

Returns the capacity of the file system type

source

fn is_full(&self) -> bool

Returns true when the string is full, otherwise false

source

fn is_empty(&self) -> bool

Returns true when the string is empty, otherwise false

source

fn len(&self) -> usize

Returns the length of the string

source

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.

source

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.

source

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.

source

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.

source

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.

source

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.

source

fn remove_range( &mut self, idx: usize, len: usize ) -> Result<(), SemanticStringError>

Removes a range. If the removal would create an illegal content it fails.

source

fn retain<F>(&mut self, f: F) -> Result<(), SemanticStringError>
where F: FnMut(u8) -> bool,

Removes all bytes which satisfy the provided clojure f. If the removal would create an illegal content it fails.

source

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.

source

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.

source

fn truncate(&mut self, new_len: usize) -> Result<(), SemanticStringError>

Truncates the string to new_len.

Object Safety§

This trait is not object safe.

Implementors§

source§

impl SemanticString<FILENAME_LENGTH> for Base64Url

source§

impl SemanticString<FILENAME_LENGTH> for FileName

source§

impl SemanticString<GROUP_NAME_LENGTH> for GroupName

source§

impl SemanticString<PATH_LENGTH> for FilePath

source§

impl SemanticString<PATH_LENGTH> for Path

source§

impl SemanticString<USER_NAME_LENGTH> for UserName