Struct cxx::CxxString [−][src]
Binding to C++ std::string
.
Invariants
As an invariant of this API and the static analysis of the cxx::bridge
macro, in Rust code we can never obtain a CxxString
by value. C++’s string
requires a move constructor and may hold internal pointers, which is not
compatible with Rust’s move behavior. Instead in Rust code we will only ever
look at a CxxString through a reference or smart pointer, as in &CxxString
or UniquePtr<CxxString>
.
Implementations
impl CxxString
[src]
pub fn new<T: Private>() -> Self
[src]
CxxString
is not constructible via new
. Instead, use the
let_cxx_string!
macro.
pub fn len(&self) -> usize
[src]
Returns the length of the string in bytes.
Matches the behavior of C++ std::string::size.
pub fn is_empty(&self) -> bool
[src]
Returns true if self
has a length of zero bytes.
Matches the behavior of C++ std::string::empty.
pub fn as_bytes(&self) -> &[u8]
[src]
Returns a byte slice of this string’s contents.
pub fn as_ptr(&self) -> *const u8
[src]
Produces a pointer to the first character of the string.
Matches the behavior of C++ std::string::data.
Note that the return type may look like const char *
but is not a
const char *
in the typical C sense, as C++ strings may contain
internal null bytes. As such, the returned pointer only makes sense as a
string in combination with the length returned by len()
.
pub fn to_str(&self) -> Result<&str, Utf8Error>
[src]
Validates that the C++ string contains UTF-8 data and produces a view of it as a Rust &str, otherwise an error.
pub fn to_string_lossy(&self) -> Cow<'_, str>
[src]
If the contents of the C++ string are valid UTF-8, this function returns a view as a Cow::Borrowed &str. Otherwise replaces any invalid UTF-8 sequences with the U+FFFD replacement character and returns a Cow::Owned String.
pub fn push_str(self: Pin<&mut Self>, s: &str)
[src]
Appends a given string slice onto the end of this C++ string.
pub fn push_bytes(self: Pin<&mut Self>, bytes: &[u8])
[src]
Appends arbitrary bytes onto the end of this C++ string.
Trait Implementations
impl Debug for CxxString
[src]
impl Display for CxxString
[src]
impl Eq for CxxString
[src]
impl ExternType for CxxString
[src]
impl Hash for CxxString
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for CxxString
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<CxxString> for CxxString
[src]
impl PartialEq<str> for CxxString
[src]
impl PartialOrd<CxxString> for CxxString
[src]
Auto Trait Implementations
impl RefUnwindSafe for CxxString
impl Send for CxxString
impl Sync for CxxString
impl !Unpin for CxxString
impl UnwindSafe for CxxString
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,