pub struct FixedDecoder<'o, const S: usize> { /* private fields */ }Expand description
Fixed size Decoder
Implementations§
Source§impl<'i, const S: usize> FixedDecoder<'i, S>
impl<'i, const S: usize> FixedDecoder<'i, S>
Sourcepub fn init() -> Self
pub fn init() -> Self
Init decoder
Examples found in repository?
examples/decode_fixed.rs (line 6)
3fn main() {
4 let s = "%F0%9F%92%A9";
5
6 let mut d = FixedDecoder::<4>::init();
7 let res = d.decode(s).unwrap();
8
9 assert_eq!(res, 4);
10 let t = core::str::from_utf8(d.cur_block().as_slice());
11
12 assert_eq!(t, Ok("💩"));
13
14 println!("{} -> {}", s, t.unwrap());
15}Sourcepub fn cur_block(&self) -> &[u8; S]
pub fn cur_block(&self) -> &[u8; S]
Current block output
Examples found in repository?
examples/decode_fixed.rs (line 10)
3fn main() {
4 let s = "%F0%9F%92%A9";
5
6 let mut d = FixedDecoder::<4>::init();
7 let res = d.decode(s).unwrap();
8
9 assert_eq!(res, 4);
10 let t = core::str::from_utf8(d.cur_block().as_slice());
11
12 assert_eq!(t, Ok("💩"));
13
14 println!("{} -> {}", s, t.unwrap());
15}Sourcepub fn decode(&mut self, raw: &'i str) -> Result<usize, DecoderError>
pub fn decode(&mut self, raw: &'i str) -> Result<usize, DecoderError>
Decode and return resulting decoded size Panic This will panic if the output would go out of bounds
Examples found in repository?
examples/decode_fixed.rs (line 7)
3fn main() {
4 let s = "%F0%9F%92%A9";
5
6 let mut d = FixedDecoder::<4>::init();
7 let res = d.decode(s).unwrap();
8
9 assert_eq!(res, 4);
10 let t = core::str::from_utf8(d.cur_block().as_slice());
11
12 assert_eq!(t, Ok("💩"));
13
14 println!("{} -> {}", s, t.unwrap());
15}Trait Implementations§
Auto Trait Implementations§
impl<'o, const S: usize> Freeze for FixedDecoder<'o, S>
impl<'o, const S: usize> RefUnwindSafe for FixedDecoder<'o, S>
impl<'o, const S: usize> Send for FixedDecoder<'o, S>
impl<'o, const S: usize> Sync for FixedDecoder<'o, S>
impl<'o, const S: usize> Unpin for FixedDecoder<'o, S>
impl<'o, const S: usize> UnwindSafe for FixedDecoder<'o, S>
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