pub struct Latin1String { /* private fields */ }
Expand description
An owned latin-1 encoded string
Implementations§
Source§impl Latin1String
impl Latin1String
Sourcepub fn encode(string: &str) -> Cow<'_, Latin1Str>
pub fn encode(string: &str) -> Cow<'_, Latin1Str>
Create a new instance from a rust string.
Note: This encodes any unavailable unicode codepoints as their equivalent HTML-Entity.
This is an implementation detail of the encoding_rs
crate and not really useful for this crate.
use latin1str::Latin1String;
assert_eq!(Latin1String::encode("Hello World!").as_bytes(), b"Hello World!");
assert_eq!(Latin1String::encode("Frühling").as_bytes(), b"Fr\xFChling");
Sourcepub fn read_cstring<R: BufRead>(reader: &mut R) -> Result<Self, Error>
pub fn read_cstring<R: BufRead>(reader: &mut R) -> Result<Self, Error>
Create a new instance by reading from a BufRead
until a null terminator is found
or the end of the string is reached.
use std::io::{Read, Cursor};
use latin1str::Latin1String;
let bytes = b"Hello World!\0";
let mut cur = Cursor::new(bytes);
let s = Latin1String::read_cstring(&mut cur).unwrap();
assert_eq!(s.decode().as_ref(), "Hello World!");
assert_eq!(cur.read(&mut []).ok(), Some(0));
Methods from Deref<Target = Latin1Str>§
Sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub 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!")
Trait Implementations§
Source§impl Borrow<Latin1Str> for Latin1String
impl Borrow<Latin1Str> for Latin1String
Source§impl Clone for Latin1String
impl Clone for Latin1String
Source§fn clone(&self) -> Latin1String
fn clone(&self) -> Latin1String
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Deref for Latin1String
impl Deref for Latin1String
Source§impl From<&Latin1Str> for Latin1String
impl From<&Latin1Str> for Latin1String
Source§fn from(src: &Latin1Str) -> Latin1String
fn from(src: &Latin1Str) -> Latin1String
Converts to this type from the input type.
Source§impl Ord for Latin1String
impl Ord for Latin1String
Source§fn cmp(&self, other: &Latin1String) -> Ordering
fn cmp(&self, other: &Latin1String) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq<&Latin1Str> for Latin1String
impl PartialEq<&Latin1Str> for Latin1String
Source§impl PartialEq<Latin1Str> for Latin1String
impl PartialEq<Latin1Str> for Latin1String
Source§impl PartialEq<Latin1String> for &Latin1Str
impl PartialEq<Latin1String> for &Latin1Str
Source§impl PartialEq<Latin1String> for Latin1Str
impl PartialEq<Latin1String> for Latin1Str
Source§impl PartialEq for Latin1String
impl PartialEq for Latin1String
Source§impl PartialOrd for Latin1String
impl PartialOrd for Latin1String
impl Eq for Latin1String
impl StructuralPartialEq for Latin1String
Auto Trait Implementations§
impl Freeze for Latin1String
impl RefUnwindSafe for Latin1String
impl Send for Latin1String
impl Sync for Latin1String
impl Unpin for Latin1String
impl UnwindSafe for Latin1String
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more