[][src]Struct gvariant::Str

#[repr(transparent)]pub struct Str { /* fields omitted */ }

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]

type AlignOf = A1

impl AllBitPatternsValid for Str[src]

impl Cast for Str[src]

impl Debug for Str[src]

impl Display for Str[src]

impl Eq for Str[src]

impl<'_> From<&'_ Str> for String[src]

impl<'a> From<&'a Str> for &'a 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]

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]

type Owned = Box<Self>

The resulting type after obtaining ownership.

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]