latin1str

Struct Latin1Str

Source
pub struct Latin1Str { /* private fields */ }
Expand description

A borrowed latin-1 encoded string (like &str)

Implementations§

Source§

impl Latin1Str

Source

pub const unsafe fn from_bytes_unchecked(text: &[u8]) -> &Self

Turns some bytes into a Latin1Str slice

§Safety

The byte slice may not contain any null bytes

Source

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

Wrap all bytes before the first nul as a Latin1Str

This method will never fail

let s = Latin1Str::from_bytes_until_nul(b"Hello\0World!");
assert_eq!(s.as_bytes(), b"Hello");
let s = Latin1Str::from_bytes_until_nul(b"Hello World!");
assert_eq!(s.as_bytes(), b"Hello World!");
Source

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

👎Deprecated: Use from_bytes_until_nul instead
Source

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

Get the bytes of the string

let s = Latin1Str::from_bytes_until_nul(b"Hello World!");
assert_eq!(s.as_bytes(), b"Hello World!")
Source

pub const fn len(&self) -> usize

Get the bytes of the string

Source

pub const fn is_empty(&self) -> bool

Check whether the str is empty

assert!(Latin1Str::from_bytes_until_nul(b"").is_empty());
assert!(!Latin1Str::from_bytes_until_nul(b"a").is_empty());
Source

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

Decode the string

let s = Latin1Str::from_bytes_until_nul(b"Fr\xFChling");
assert_eq!(s.decode().as_ref(), "Frühling");

Trait Implementations§

Source§

impl Borrow<Latin1Str> for Latin1String

Source§

fn borrow(&self) -> &Latin1Str

Immutably borrows from an owned value. Read more
Source§

impl Debug for &Latin1Str

Source§

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

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

impl<'a> From<&'a CStr> for &'a Latin1Str

Source§

fn from(v: &'a CStr) -> Self

Converts to this type from the input type.
Source§

impl From<&Latin1Str> for Latin1String

Source§

fn from(src: &Latin1Str) -> Latin1String

Converts to this type from the input type.
Source§

impl Ord for Latin1Str

Source§

fn cmp(&self, other: &Latin1Str) -> Ordering

This method returns an Ordering between self and other. Read more
Source§

impl PartialEq<&Latin1Str> for Latin1String

Source§

fn eq(&self, other: &&Latin1Str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Latin1Str> for Latin1String

Source§

fn eq(&self, other: &Latin1Str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Latin1String> for &Latin1Str

Source§

fn eq(&self, other: &Latin1String) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<Latin1String> for Latin1Str

Source§

fn eq(&self, other: &Latin1String) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for Latin1Str

Source§

fn eq(&self, other: &Latin1Str) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Latin1Str

Source§

fn partial_cmp(&self, other: &Latin1Str) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl ToOwned for Latin1Str

Source§

type Owned = Latin1String

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
Source§

impl Eq for Latin1Str

Source§

impl StructuralPartialEq for Latin1Str

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