Struct KanziString
pub struct KanziString(/* private fields */);Expand description
Kanzi uses C++ std::string internally, and its internal representation differs from the Rust
String type. Rust strings represent a sequence of UTF-8 code points, while C++ strings are
an array of c_char.
This implies that it is possible to represent a string in Kanzi that is not valid Unicode, causing the conversion to fail on the Rust side.
To handle this case we could have used OsString or CString, but this would still require
reallocating the string, as Rust might use a different allocator than C++.
Instead we “wrap” C++ strings in a wrapper (requiring only a small 8-byte allocation) and pass a pointer to this wrapper. This allows crate users to hold the string as an opaque object and use it solely for communication with Kanzi or convert it (possibly losslessly) to a Rust string via allocation.
Implementations§
§impl KanziString
impl KanziString
pub fn len(&self) -> usize
pub fn clear(&mut self)
pub fn is_empty(&self) -> bool
pub fn at(&self, pos: usize) -> Option<i8>
pub fn compare(&self, rhs: &KanziString) -> Ordering
pub fn append(&mut self, rhs: impl AsRef<KanziStr>)
pub fn from_slice(slice: &[i8]) -> KanziString
pub fn from_bytes(bytes: &[u8]) -> KanziString
pub fn from_utf8(utf8: &str) -> KanziString
pub fn from_kanzi_str(str: &KanziStr) -> KanziString
Methods from Deref<Target = KanziStr>§
pub fn as_ptr(&self) -> *const i8
pub fn as_slice(&self) -> &[i8]
pub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_utf8(&self) -> Result<&str, Utf8Error>
pub fn to_utf8_lossy(&self) -> String
pub fn to_cstring(&self) -> Option<CString>
pub fn to_kanzi_string(&self) -> KanziString
pub fn is_empty(&self) -> bool
pub fn len(&self) -> usize
Trait Implementations§
§impl<T> AsRef<T> for KanziString
impl<T> AsRef<T> for KanziString
§impl Clone for KanziString
impl Clone for KanziString
§fn clone(&self) -> KanziString
fn clone(&self) -> KanziString
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl DataObjectConstraint for KanziString
impl DataObjectConstraint for KanziString
§type DataArg<'a> = &'a KanziStr
type DataArg<'a> = &'a KanziStr
DataObject.
Generally, this type matches Self except for KanziString. Read more§fn as_arg(&self) -> <KanziString as DataObjectConstraint>::DataArg<'_>
fn as_arg(&self) -> <KanziString as DataObjectConstraint>::DataArg<'_>
Self to a type accepted by DataObject::set_value.§impl Debug for KanziString
impl Debug for KanziString
§impl Default for KanziString
impl Default for KanziString
§fn default() -> KanziString
fn default() -> KanziString
§impl Deref for KanziString
impl Deref for KanziString
§impl Display for KanziString
impl Display for KanziString
§impl Ord for KanziString
impl Ord for KanziString
§impl<'a> PartialEq<&'a KanziStr> for KanziString
impl<'a> PartialEq<&'a KanziStr> for KanziString
§impl<'a> PartialEq<&'a str> for KanziString
impl<'a> PartialEq<&'a str> for KanziString
§impl PartialEq<KanziStr> for KanziString
impl PartialEq<KanziStr> for KanziString
§impl PartialEq<String> for KanziString
impl PartialEq<String> for KanziString
§impl PartialEq<str> for KanziString
impl PartialEq<str> for KanziString
§impl PartialEq for KanziString
impl PartialEq for KanziString
§impl PartialOrd for KanziString
impl PartialOrd for KanziString
§impl VariantConstraint for KanziString
impl VariantConstraint for KanziString
§type DataArg<'a> = &'a KanziStr
type DataArg<'a> = &'a KanziStr
Variant.
Generally, this type matches Self, except for KanziString, Resource, and ResourceId. Read more