#[repr(transparent)]
pub struct Str { /* private fields */ }
Expand description

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

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)

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

Immutably borrows from an owned value. Read more

Get a static reference to the default value for this type. Read more

Cast slice to type Self. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Converts to this type from the input type.

Converts to this type from the input type.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts the given value to a String. Read more