pub struct ApiString { /* private fields */ }Expand description
A string type used in VPP API messages.
This represents a variable-length string with a length prefix, commonly used in VPP API message structures.
Note that copying/cloning ApiString objects will not copy/clone the contents of the string.
Implementations§
Source§impl ApiString
impl ApiString
Sourcepub fn to_str(&self) -> Result<&str, Utf8Error>
pub fn to_str(&self) -> Result<&str, Utf8Error>
Converts the string to a &str slice.
If the contents of the ApiString are valid UTF-8 data, this
function will return the corresponding &[str] slice. Otherwise,
it will return an error with details of where UTF-8 validation failed.
Sourcepub fn to_string_lossy(&self) -> Cow<'_, str>
pub fn to_string_lossy(&self) -> Cow<'_, str>
Converts the string to a Cow<str>, replacing invalid UTF-8 sequences with �.
Sourcepub unsafe fn set_len(&mut self, length: u32)
pub unsafe fn set_len(&mut self, length: u32)
Sets the length of the string in bytes.
§Safety
The caller must ensure that the underlying buffer has at least length bytes of valid
memory and is initialised.
Sourcepub fn copy_from_str(&mut self, s: &str)
pub fn copy_from_str(&mut self, s: &str)
Copies the contents of the given string into this ApiString.
§Panics
Panics if the length of the ApiString is different to the length of the string in bytes.