pub struct PercentCodec;Expand description
Encodes and decodes percent-encoded UTF-8 text.
Its low-level Codec<Value = u8, Unit = u8> implementation converts one
byte to either one unreserved ASCII unit or a %XX escape. UTF-8 validation
remains part of the owned decode helper.
Implementations§
Source§impl PercentCodec
impl PercentCodec
Sourcepub fn decode(&self, text: &str) -> MiscCodecResult<String>
pub fn decode(&self, text: &str) -> MiscCodecResult<String>
Decodes percent-encoded UTF-8 text.
§Parameters
text: Percent-encoded text.
§Returns
Decoded UTF-8 text.
§Errors
Returns MiscCodecError when a percent escape is malformed or decoded
bytes are not valid UTF-8.
Trait Implementations§
Source§impl Clone for PercentCodec
impl Clone for PercentCodec
Source§fn clone(&self) -> PercentCodec
fn clone(&self) -> PercentCodec
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Codec for PercentCodec
impl Codec for PercentCodec
Source§fn encode_len(&self, value: &u8) -> usize
fn encode_len(&self, value: &u8) -> usize
Returns the exact percent-encoded width for one byte.
Source§unsafe fn decode(
&mut self,
input: &[u8],
input_index: usize,
) -> Result<(u8, NonZeroUsize), DecodeFailure<Self::DecodeError>>
unsafe fn decode( &mut self, input: &[u8], input_index: usize, ) -> Result<(u8, NonZeroUsize), DecodeFailure<Self::DecodeError>>
Decodes one raw byte or %XX escape.
§Safety
The caller must provide an input index with at least one readable unit and a slice satisfying the codec trait’s decode preconditions.
Source§unsafe fn encode(
&mut self,
value: &u8,
output: &mut [u8],
output_index: usize,
) -> Result<usize, Self::EncodeError>
unsafe fn encode( &mut self, value: &u8, output: &mut [u8], output_index: usize, ) -> Result<usize, Self::EncodeError>
Encodes one byte using percent encoding.
§Safety
The caller must provide enough writable output units for
Self::encode_len.
Source§unsafe fn decode_eof(
&mut self,
input: &[u8],
input_index: usize,
) -> Result<(u8, NonZeroUsize), DecodeFailure<Self::DecodeError>>
unsafe fn decode_eof( &mut self, input: &[u8], input_index: usize, ) -> Result<(u8, NonZeroUsize), DecodeFailure<Self::DecodeError>>
Decodes one value after end of input has been confirmed.
§Safety
The caller must provide an input index with at least one readable unit and a slice satisfying the codec trait’s EOF decode preconditions.
Source§const MIN_UNITS_PER_VALUE: usize = 1
const MIN_UNITS_PER_VALUE: usize = 1
Source§const MAX_ENCODE_UNITS_PER_VALUE: usize = 3
const MAX_ENCODE_UNITS_PER_VALUE: usize = 3
Source§const MAX_DECODE_UNITS_PER_VALUE: usize = 3
const MAX_DECODE_UNITS_PER_VALUE: usize = 3
Source§type DecodeError = MiscCodecError
type DecodeError = MiscCodecError
Source§type EncodeError = MiscCodecError
type EncodeError = MiscCodecError
Source§const MAX_ENCODE_RESET_UNITS: usize = 0
const MAX_ENCODE_RESET_UNITS: usize = 0
Source§const MAX_ENCODE_FINISH_UNITS: usize = 0
const MAX_ENCODE_FINISH_UNITS: usize = 0
Source§const MAX_DECODE_RESET_VALUES: usize = 0
const MAX_DECODE_RESET_VALUES: usize = 0
Source§const MAX_DECODE_FINISH_VALUES: usize = 0
const MAX_DECODE_FINISH_VALUES: usize = 0
Source§fn can_encode_value(&self, _value: &Self::Value) -> bool
fn can_encode_value(&self, _value: &Self::Value) -> bool
value is in this codec’s encodable value domain. Read moreSource§unsafe fn encode_reset(
&mut self,
_output: &mut [Self::Unit],
_output_index: usize,
) -> Result<usize, Self::EncodeError>
unsafe fn encode_reset( &mut self, _output: &mut [Self::Unit], _output_index: usize, ) -> Result<usize, Self::EncodeError>
Source§unsafe fn encode_finish(
&mut self,
_output: &mut [Self::Unit],
_output_index: usize,
) -> Result<usize, Self::EncodeError>
unsafe fn encode_finish( &mut self, _output: &mut [Self::Unit], _output_index: usize, ) -> Result<usize, Self::EncodeError>
Source§unsafe fn decode_reset(
&mut self,
_output: &mut [Self::Value],
_output_index: usize,
) -> Result<usize, Self::DecodeError>
unsafe fn decode_reset( &mut self, _output: &mut [Self::Value], _output_index: usize, ) -> Result<usize, Self::DecodeError>
Source§unsafe fn decode_finish(
&mut self,
_output: &mut [Self::Value],
_output_index: usize,
) -> Result<usize, Self::DecodeError>
unsafe fn decode_finish( &mut self, _output: &mut [Self::Value], _output_index: usize, ) -> Result<usize, Self::DecodeError>
output. Read more