pub struct Coding(/* private fields */);
Expand description
Coding information derived from a Windows code page.
Implementations§
Source§impl Coding
impl Coding
Sourcepub fn new(cp: u16) -> Result<Self, ConvertError>
pub fn new(cp: u16) -> Result<Self, ConvertError>
Get an encoding for the given code page.
§Errors
Will fail with ConvertError::UnknownCodepage
or
ConvertError::UnsupportedCodepage
if an encoding
for the given page is unavailable.
Sourcepub fn encode<'a, S>(&self, src: S) -> Result<Vec<u8>, ConvertError>
pub fn encode<'a, S>(&self, src: S) -> Result<Vec<u8>, ConvertError>
Encode a UTF-8 string into a byte vector according to this encoding.
§Errors
Returns ConvertError::StringEncoding
if any
character cannot be encoded.
Sourcepub fn decode<'a>(&self, src: &'a [u8]) -> Result<Cow<'a, str>, ConvertError>
pub fn decode<'a>(&self, src: &'a [u8]) -> Result<Cow<'a, str>, ConvertError>
Decode a byte vector into UTF-8 Cow
<
str
>
according
to this encoding.
§Errors
Returns ConvertError::StringDecoding
if any
character cannot be decoded.
Sourcepub fn decode_lossy<'a>(&self, src: &'a [u8]) -> Cow<'a, str>
pub fn decode_lossy<'a>(&self, src: &'a [u8]) -> Cow<'a, str>
Decode a byte vector into UTF-8 Cow
<
str
>
according
to this encoding. Replace any bytes that cannot be
encoded with the Unicode
“replacement character”
(\u{fffd}
).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Coding
impl RefUnwindSafe for Coding
impl Send for Coding
impl Sync for Coding
impl Unpin for Coding
impl UnwindSafe for Coding
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