[−][src]Struct gvariant::Str
Type with same representation as GVariant "s", "o" and "g" types
This is the type returned by:
gv!("s").cast(data);
We can't use Rust's str
type here because GVariant strings always end with
a NUL byte.
Implementations
impl Str
[src]
pub fn as_bytes_non_conformant(&self) -> &[u8]
[src]
Convert &Str
to &[u8]
This will give the same result as s.to_str().as_bytes()
for normal
data, but unlike using to_str()
it should be 0-cost as it doesn't
require scanning the underlying data.
The result of this function will deviate from the GLib GVariant implementation if the data contains embedded NULs or non-utf8 data. The spec says:
2.7.3 Handling Non-Normal Serialised Data
String with Embedded Nul
If a string has a nul character as its final byte, but also contains another nul character before this final terminator, the value of the string is taken to be the part of the string that precedes the embedded nul. This means that obtaining a C pointer to a string is still a constant time operation.
Instead this function will return the data with the embedded NULs intact (excluding the final NUL byte)
pub fn to_str(&self) -> &str
[src]
Convert &Str
to &str
For consistency with the GLib implementation this will return a empty string if the underlying data is not utf-8 encoded or contains embedded NULs. This differs from the wording of the GVariant specification which says that "the use of UTF-8 is expected and encouraged", but it is not guaranteed.
This function executes in linear time with the length of the data. If
you know that your data is in normal form you can use
self.to_bytes_non_conformant()
instead which executes in constant
time.
Trait Implementations
impl AlignOf for Str
[src]
impl AllBitPatternsValid for Str
[src]
impl Cast for Str
[src]
fn default_ref() -> &'static Self
[src]
fn try_from_aligned_slice(
slice: &AlignedSlice<Self::AlignOf>
) -> Result<&Self, WrongSize>
[src]
slice: &AlignedSlice<Self::AlignOf>
) -> Result<&Self, WrongSize>
fn try_from_aligned_slice_mut(
slice: &mut AlignedSlice<Self::AlignOf>
) -> Result<&mut Self, WrongSize>
[src]
slice: &mut AlignedSlice<Self::AlignOf>
) -> Result<&mut Self, WrongSize>
fn from_aligned_slice(slice: &AlignedSlice<Self::AlignOf>) -> &Self
[src]
impl Debug for Str
[src]
impl Display for Str
[src]
impl Eq for Str
[src]
impl PartialEq<Str> for Str
[src]
impl PartialEq<Str> for str
[src]
impl PartialEq<str> for Str
[src]
impl RefCast for Str
[src]
type From = [u8]
fn ref_cast(_from: &Self::From) -> &Self
[src]
fn ref_cast_mut(_from: &mut Self::From) -> &mut Self
[src]
impl<'_> SerializeTo<Str> for &'_ Str
[src]
impl<'_> SerializeTo<Str> for &'_ str
[src]
impl<'_, T: SerializeTo<Str> + Copy> SerializeTo<Str> for &'_ T
[src]
impl<'_> SerializeTo<Str> for &'_ Box<Str>
[src]
impl<'_> SerializeTo<Str> for &'_ String
[src]
impl StructuralEq for Str
[src]
impl ToOwned for Str
[src]
Auto Trait Implementations
impl RefUnwindSafe for Str
impl Send for Str
impl Sync for Str
impl Unpin for Str
impl UnwindSafe for Str
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,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,