Struct xcb::Lat1Str

source ·
pub struct Lat1Str { /* private fields */ }
Expand description

A slice to a Latin-1 (aka. ISO 8859-1) string.

It is usually seen in its borrowed form, &Lat1Str. Lat1Str contains a slice of bytes and is by definition always valid Latin-1.

This type is useful for XCB because strings in the X protocol are expected to be Latin-1 encoded. Although the X strings are Latin-1, in reality ASCII can be expected without too much risk, hence all the ASCII related functions.

This does not account for strings passed as raw bytes to x::ChangeProperty (e.g. to set a window title). These strings are passed as-is by the X server to the window compositor and encoding is implied by the property itself (e.g. UTF-8 for _NET_WM_NAME aka. window title).

Implementations§

source§

impl Lat1Str

source

pub fn from_bytes(bytes: &[u8]) -> &Self

Returns a reference to a Lat1Str that borrows the passed bytes

source

pub fn try_from_ascii(str: &str) -> Result<&Self, Lat1Error>

Returns a reference to a Lat1Str that borrows the passed string bytes only if str is pure ASCII. Otherwise, a Lat1Error::NonAscii is returned.

source

pub fn from_ascii(str: &str) -> &Self

Returns a reference to a Lat1Str that borrows the passed string bytes only if str is pure ASCII.

§Panics

This function panics if str contains non-ASCII chars.

source

pub unsafe fn from_ascii_unchecked(str: &str) -> &Self

Returns a reference to a Lat1Str that borrows the passed string bytes.

§Safety

If str contains non-ASCII characters, the returned string will not correspond to the passed string (the latin-1 will contain utf-8 encoding).

source

pub fn from_utf8(str: &str) -> Cow<'_, Lat1Str>

Returns a Latin-1 string built from a UTF-8 string

Cow::Borrowed is returned if str contains only ASCII, otherwise, a conversion from UTF-8 is performed and Cow::Owned is returned.

source

pub fn is_ascii(&self) -> bool

Checks whether the slice only contains ASCII characters.

source

pub fn len(&self) -> usize

Returns the number of characters in the string.

source

pub fn as_bytes(&self) -> &[u8]

Returns the string as slice of bytes.

source

pub fn try_as_ascii(&self) -> Result<&str, Lat1Error>

Returns the string in UTF-8 encoding, only if the string is pure ASCII. Otherwise, a Lat1Error::NonAscii is returned.

source

pub fn as_ascii(&self) -> &str

Returns the string in UTF-8 encoding, only if the string is pure ASCII.

§Panics

This function panics if the string contains non-ASCII chars.

source

pub unsafe fn as_ascii_unchecked(&self) -> &str

Returns the string in UTF-8 encoding.

§Safety

If the string contains non-ASCII characters, the returned string will be invalid UTF-8.

source

pub fn to_utf8(&self) -> Cow<'_, str>

Returns the string converted to UTF-8.

Cow::Borrowed is returned if the string is pure ASCII, otherwise a conversion to UTF-8 is performed and Cow::Owned is returned.

Trait Implementations§

source§

impl Borrow<Lat1Str> for Lat1String

source§

fn borrow(&self) -> &Lat1Str

Immutably borrows from an owned value. Read more
source§

impl Debug for Lat1Str

source§

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

Formats the value using the given formatter. Read more
source§

impl Display for Lat1Str

source§

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

Formats the value using the given formatter. Read more
source§

impl ToOwned for Lat1Str

§

type Owned = Lat1String

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> Self::Owned

Creates owned data from borrowed data, usually by cloning. Read more
1.63.0 · source§

fn clone_into(&self, target: &mut Self::Owned)

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

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
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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more