pub trait String:
StringView
+ Debug
+ Display
+ PartialOrd
+ Ord
+ Hash
+ Deref<Target = [u8]>
+ DerefMut
+ PartialEq
+ Eq {
Show 24 methods
// Required methods
fn capacity(&self) -> usize;
fn len(&self) -> usize;
// Provided methods
fn as_bytes(&self) -> &[u8] { ... }
fn as_bytes_with_nul(&self) -> &[u8] { ... }
fn as_c_str(&self) -> *const c_char { ... }
fn as_mut_bytes(&mut self) -> &mut [u8] { ... }
fn as_str(&self) -> &str { ... }
fn clear(&mut self) { ... }
fn find(&self, bytes: &[u8]) -> Option<usize> { ... }
fn is_empty(&self) -> bool { ... }
fn is_full(&self) -> bool { ... }
fn insert(
&mut self,
idx: usize,
byte: u8,
) -> Result<(), StringModificationError> { ... }
fn insert_bytes(
&mut self,
idx: usize,
bytes: &[u8],
) -> Result<(), StringModificationError> { ... }
unsafe fn insert_bytes_unchecked(&mut self, idx: usize, bytes: &[u8]) { ... }
fn pop(&mut self) -> Option<u8> { ... }
fn push(&mut self, byte: u8) -> Result<(), StringModificationError> { ... }
fn push_bytes(
&mut self,
bytes: &[u8],
) -> Result<(), StringModificationError> { ... }
fn remove(&mut self, idx: usize) -> Option<u8> { ... }
fn remove_range(&mut self, idx: usize, len: usize) -> bool { ... }
fn retain<F: FnMut(u8) -> bool>(&mut self, f: F) { ... }
fn rfind(&self, bytes: &[u8]) -> Option<usize> { ... }
fn strip_prefix(&mut self, bytes: &[u8]) -> bool { ... }
fn strip_suffix(&mut self, bytes: &[u8]) -> bool { ... }
fn truncate(&mut self, new_len: usize) { ... }
}Expand description
A UTF-8 string trait. The string class uses Unicode (ISO/IEC 10646) terminology throughout its interface. In particular:
- A code point is the numerical index assigned to a character in the Unicode standard.
- A code unit is the basic component of a character encoding system. For UTF-8, the code unit has a size of 8-bits
For example, the code point U+0041 represents the letter ‘A’ and can be encoded in a single 8-bit code unit in UTF-8. The code point U+1F4A9 requires four 8-bit code units in the UTF-8 encoding.
The NUL code point (U+0000) is not allowed anywhere in the string.
§Note
Currently only Unicode code points less than 128 (U+0080) are supported. This restricts the valid contents of a string to those UTF8 strings that are also valid 7-bit ASCII strings. Full Unicode support will get added later.
Required Methods§
Provided Methods§
Sourcefn as_bytes_with_nul(&self) -> &[u8]
fn as_bytes_with_nul(&self) -> &[u8]
Returns a null-terminated slice to the underlying bytes
Sourcefn as_mut_bytes(&mut self) -> &mut [u8]
fn as_mut_bytes(&mut self) -> &mut [u8]
Returns a mutable slice to the underlying bytes
Sourcefn find(&self, bytes: &[u8]) -> Option<usize>
fn find(&self, bytes: &[u8]) -> Option<usize>
Finds the first occurrence of a byte string in the given string. If the byte string was
found the start position of the byte string is returned, otherwise None.
Sourcefn insert(
&mut self,
idx: usize,
byte: u8,
) -> Result<(), StringModificationError>
fn insert( &mut self, idx: usize, byte: u8, ) -> Result<(), StringModificationError>
Inserts a byte at a provided index. If the index is out of bounds it panics. If the string has no more capacity left it fails otherwise it succeeds.
use iceoryx2_bb_container::string::*;
const STRING_CAPACITY: usize = 123;
let mut some_string = StaticString::<STRING_CAPACITY>::from_bytes(b"helo").unwrap();
some_string.insert(3, 'l' as u8).unwrap();
assert!(some_string == b"hello");Sourcefn insert_bytes(
&mut self,
idx: usize,
bytes: &[u8],
) -> Result<(), StringModificationError>
fn insert_bytes( &mut self, idx: usize, bytes: &[u8], ) -> Result<(), StringModificationError>
Inserts a byte array at a provided index. If the index is out of bounds it panics. If the string has no more capacity left it fails otherwise it succeeds.
use iceoryx2_bb_container::string::*;
const STRING_CAPACITY: usize = 123;
let mut some_string = StaticString::<STRING_CAPACITY>::from_bytes(b"ho").unwrap();
some_string.insert_bytes(1, b"ell").unwrap();
assert!(some_string == b"hello");Sourceunsafe fn insert_bytes_unchecked(&mut self, idx: usize, bytes: &[u8])
unsafe fn insert_bytes_unchecked(&mut self, idx: usize, bytes: &[u8])
Inserts a byte array at a provided index.
§Safety
- The ‘idx’ must by less than
String::len(). - The ‘bytes.len()’ must be less or equal than
String::capacity()-String::len()
Sourcefn pop(&mut self) -> Option<u8>
fn pop(&mut self) -> Option<u8>
Removes the last character from the string and returns it. If the string is empty it returns none.
use iceoryx2_bb_container::string::*;
const STRING_CAPACITY: usize = 123;
let mut some_string = StaticString::<STRING_CAPACITY>::from_bytes(b"hello!").unwrap();
let char = some_string.pop().unwrap();
assert!(char == '!' as u8);
assert!(some_string == b"hello");Sourcefn push(&mut self, byte: u8) -> Result<(), StringModificationError>
fn push(&mut self, byte: u8) -> Result<(), StringModificationError>
Adds a byte at the end of the string. If there is no more space left it fails, otherwise it succeeds.
Sourcefn push_bytes(&mut self, bytes: &[u8]) -> Result<(), StringModificationError>
fn push_bytes(&mut self, bytes: &[u8]) -> Result<(), StringModificationError>
Adds a byte array at the end of the string. If there is no more space left it fails, otherwise it succeeds.
Sourcefn remove(&mut self, idx: usize) -> Option<u8>
fn remove(&mut self, idx: usize) -> Option<u8>
Removes a character at the provided index and returns it.
Sourcefn remove_range(&mut self, idx: usize, len: usize) -> bool
fn remove_range(&mut self, idx: usize, len: usize) -> bool
Removes a range beginning from idx.
Sourcefn retain<F: FnMut(u8) -> bool>(&mut self, f: F)
fn retain<F: FnMut(u8) -> bool>(&mut self, f: F)
Removes all characters where f(c) returns false.
Sourcefn rfind(&self, bytes: &[u8]) -> Option<usize>
fn rfind(&self, bytes: &[u8]) -> Option<usize>
Finds the last occurrence of a byte string in the given string. If the byte string was
found the start position of the byte string is returned, otherwise None.
Sourcefn strip_prefix(&mut self, bytes: &[u8]) -> bool
fn strip_prefix(&mut self, bytes: &[u8]) -> bool
Removes a given prefix from the string. If the prefix was not found it returns false, otherwise the prefix is removed and the function returns true.
Sourcefn strip_suffix(&mut self, bytes: &[u8]) -> bool
fn strip_suffix(&mut self, bytes: &[u8]) -> bool
Removes a given suffix from the string. If the suffix was not found it returns false, otherwise the suffix is removed and the function returns true.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.