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