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

pub const fn as_ptr(&self) -> *mut StringWrapper

pub fn as_str(&self) -> &KanziStr

§

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
where <KanziString as Deref>::Target: AsRef<T>, T: ?Sized,

§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
§

impl Clone for KanziString

§

fn clone(&self) -> KanziString

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl DataObjectConstraint for KanziString

§

type DataArg<'a> = &'a KanziStr

Specifies the type of an argument that provides a value to the DataObject. Generally, this type matches Self except for KanziString. Read more
§

fn as_arg(&self) -> <KanziString as DataObjectConstraint>::DataArg<'_>

Converts Self to a type accepted by DataObject::set_value.
§

impl Debug for KanziString

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for KanziString

§

fn default() -> KanziString

Returns the “default value” for a type. Read more
§

impl Deref for KanziString

§

type Target = KanziStr

The resulting type after dereferencing.
§

fn deref(&self) -> &<KanziString as Deref>::Target

Dereferences the value.
§

impl Display for KanziString

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Drop for KanziString

§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

impl Ord for KanziString

§

fn cmp(&self, rhs: &KanziString) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
§

impl<'a> PartialEq<&'a KanziStr> for KanziString

§

fn eq(&self, rhs: &&'a KanziStr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<'a> PartialEq<&'a str> for KanziString

§

fn eq(&self, rhs: &&'a str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq<KanziStr> for KanziString

§

fn eq(&self, rhs: &KanziStr) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq<String> for KanziString

§

fn eq(&self, rhs: &String) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq<str> for KanziString

§

fn eq(&self, rhs: &str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialEq for KanziString

§

fn eq(&self, rhs: &KanziString) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl PartialOrd for KanziString

§

fn partial_cmp(&self, rhs: &KanziString) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl VariantConstraint for KanziString

§

type DataArg<'a> = &'a KanziStr

Specifies the type of an argument that provides a value to Variant. Generally, this type matches Self, except for KanziString, Resource, and ResourceId. Read more
§

type RetArg = KanziString

Specifies the type of the return value received from Variant. Generally, this type matches Self, except for Resource. Read more
§

fn as_arg(&self) -> <KanziString as VariantConstraint>::DataArg<'_>

Converts Self to a type accepted by Variant::create or Object::set_property.
§

impl Eq for KanziString

§

impl PropertyTypeConstraint for KanziString

§

impl Send for KanziString

§

impl Sync for KanziString

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> AsAny for T
where T: 'static,

§

fn as_any(&self) -> &(dyn Any + 'static)

§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Inherits<T> for T

§

fn upcast(self) -> Base

§

fn upcast_ref(&self) -> &Base

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.