[−][src]Enum sit_core::encoding::Encoding
Available encodings
Variants
Base32
Base32 encoding
Methods from Deref<Target = Encoding>
pub fn encode_len(&self, len: usize) -> usize
[src]
pub fn encode_len(&self, len: usize) -> usize
Returns the encoded length of an input of length len
See encode_mut
for when to use it.
pub fn encode_mut(&self, input: &[u8], output: &mut [u8])
[src]
pub fn encode_mut(&self, input: &[u8], output: &mut [u8])
Encodes input
in output
Panics
Panics if the output
length does not match the result of
encode_len
for the input
length.
Examples
use data_encoding::BASE64; let input = b"Hello world"; let output = &mut buffer[0 .. BASE64.encode_len(input.len())]; BASE64.encode_mut(input, output); assert_eq!(output, b"SGVsbG8gd29ybGQ=");
pub fn encode(&self, input: &[u8]) -> String
[src]
pub fn encode(&self, input: &[u8]) -> String
Returns encoded input
Examples
use data_encoding::BASE64; assert_eq!(BASE64.encode(b"Hello world"), "SGVsbG8gd29ybGQ=");
pub fn decode_len(&self, len: usize) -> Result<usize, DecodeError>
[src]
pub fn decode_len(&self, len: usize) -> Result<usize, DecodeError>
Returns the decoded length of an input of length len
See decode_mut
for when to use it.
Errors
Returns an error if len
is invalid. The error kind is Length
and
the position is the greatest valid input length.
pub fn decode_mut(
&self,
input: &[u8],
output: &mut [u8]
) -> Result<usize, DecodePartial>
[src]
pub fn decode_mut(
&self,
input: &[u8],
output: &mut [u8]
) -> Result<usize, DecodePartial>
Decodes input
in output
Returns the length of the decoded output. This length may be smaller than the output length if the input contained padding or ignored characters. The output bytes after the returned length are not initialized and should not be read.
Panics
Panics if the output
length does not match the result of
decode_len
for the input
length. Also panics if decode_len
fails
for the input
length.
Errors
Returns an error if input
is invalid. See decode
for more details.
The are two differences though:
Length
may be returned only if the encoding allows ignored characters, because otherwise this is already checked bydecode_len
.- The
read
first bytes of the input have been successfully decoded to thewritten
first bytes of the output.
Examples
use data_encoding::BASE64; let input = b"SGVsbA==byB3b3JsZA=="; let output = &mut buffer[0 .. BASE64.decode_len(input.len()).unwrap()]; let len = BASE64.decode_mut(input, output).unwrap(); assert_eq!(&output[0 .. len], b"Hello world");
pub fn decode(&self, input: &[u8]) -> Result<Vec<u8>, DecodeError>
[src]
pub fn decode(&self, input: &[u8]) -> Result<Vec<u8>, DecodeError>
Returns decoded input
Errors
Returns an error if input
is invalid. The error kind can be:
Length
if the input length is invalid. The position is the greatest valid input length.Symbol
if the input contains an invalid character. The position is the first invalid character.Trailing
if the input has non-zero trailing bits. This is only possible if the encoding checks trailing bits. The position is the first character containing non-zero trailing bits.Padding
if the input has an invalid padding length. This is only possible if the encoding uses padding. The position is the first padding character of the first padding of invalid length.
Examples
use data_encoding::BASE64; assert_eq!(BASE64.decode(b"SGVsbA==byB3b3JsZA==").unwrap(), b"Hello world");
pub fn bit_width(&self) -> usize
[src]
pub fn bit_width(&self) -> usize
Returns the bit-width
pub fn is_canonical(&self) -> bool
[src]
pub fn is_canonical(&self) -> bool
Returns whether the encoding is canonical
An encoding is not canonical if one of the following conditions holds:
- trailing bits are not checked
- padding is used
- characters are ignored
- characters are translated
pub fn specification(&self) -> Specification
[src]
pub fn specification(&self) -> Specification
Returns the encoding specification
Trait Implementations
impl Clone for Encoding
[src]
impl Clone for Encoding
fn clone(&self) -> Encoding
[src]
fn clone(&self) -> Encoding
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Default for Encoding
[src]
impl Default for Encoding
impl Debug for Encoding
[src]
impl Debug for Encoding
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Deref for Encoding
[src]
impl Deref for Encoding
type Target = Encoding
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
fn deref(&self) -> &Self::Target
Dereferences the value.
impl Serialize for Encoding
[src]
impl Serialize for Encoding
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl<'de> Deserialize<'de> for Encoding
[src]
impl<'de> Deserialize<'de> for Encoding
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
type Owned = T
fn to_owned(&self) -> T
[src]
fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
fn clone_into(&self, target: &mut T)
[src]
fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
impl<T> Same for T
impl<T> Same for T
type Output = T
Should always be Self