Skip to main content

ZonReader

Struct ZonReader 

Source
pub struct ZonReader<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> ZonReader<'a>

Source

pub fn new(buffer: &'a [u8]) -> Result<Self, &'static str>

Examples found in repository?
examples/basic.rs (line 17)
3fn main() {
4    println!("Running ZON Basic Example...");
5
6    // 1. Write
7    let mut writer = ZonWriter::new();
8    let text_off = writer.write_string("Hello Zero-Copy World!");
9    let num_off = writer.write_u32(42);
10    
11    writer.set_root(text_off);
12    
13    println!("Written {} bytes.", writer.len());
14    
15    // 2. Read
16    let buffer = writer.as_bytes();
17    let reader = ZonReader::new(buffer).expect("Buffer verification failed");
18    
19    let root = reader.read_u32(8).unwrap();
20    let text = reader.read_string(root).unwrap();
21    let num = reader.read_u32(num_off).unwrap();
22    
23    println!("Read Root String: {}", text);
24    println!("Read Number: {}", num);
25    
26    assert_eq!(text, "Hello Zero-Copy World!");
27    assert_eq!(num, 42);
28    
29    println!("Success!");
30}
Source

pub fn read_u32(&self, offset: u32) -> Result<u32, &'static str>

Examples found in repository?
examples/basic.rs (line 19)
3fn main() {
4    println!("Running ZON Basic Example...");
5
6    // 1. Write
7    let mut writer = ZonWriter::new();
8    let text_off = writer.write_string("Hello Zero-Copy World!");
9    let num_off = writer.write_u32(42);
10    
11    writer.set_root(text_off);
12    
13    println!("Written {} bytes.", writer.len());
14    
15    // 2. Read
16    let buffer = writer.as_bytes();
17    let reader = ZonReader::new(buffer).expect("Buffer verification failed");
18    
19    let root = reader.read_u32(8).unwrap();
20    let text = reader.read_string(root).unwrap();
21    let num = reader.read_u32(num_off).unwrap();
22    
23    println!("Read Root String: {}", text);
24    println!("Read Number: {}", num);
25    
26    assert_eq!(text, "Hello Zero-Copy World!");
27    assert_eq!(num, 42);
28    
29    println!("Success!");
30}
Source

pub fn read_string(&self, offset: u32) -> Result<&'a str, &'static str>

Examples found in repository?
examples/basic.rs (line 20)
3fn main() {
4    println!("Running ZON Basic Example...");
5
6    // 1. Write
7    let mut writer = ZonWriter::new();
8    let text_off = writer.write_string("Hello Zero-Copy World!");
9    let num_off = writer.write_u32(42);
10    
11    writer.set_root(text_off);
12    
13    println!("Written {} bytes.", writer.len());
14    
15    // 2. Read
16    let buffer = writer.as_bytes();
17    let reader = ZonReader::new(buffer).expect("Buffer verification failed");
18    
19    let root = reader.read_u32(8).unwrap();
20    let text = reader.read_string(root).unwrap();
21    let num = reader.read_u32(num_off).unwrap();
22    
23    println!("Read Root String: {}", text);
24    println!("Read Number: {}", num);
25    
26    assert_eq!(text, "Hello Zero-Copy World!");
27    assert_eq!(num, 42);
28    
29    println!("Success!");
30}

Auto Trait Implementations§

§

impl<'a> Freeze for ZonReader<'a>

§

impl<'a> RefUnwindSafe for ZonReader<'a>

§

impl<'a> Send for ZonReader<'a>

§

impl<'a> Sync for ZonReader<'a>

§

impl<'a> Unpin for ZonReader<'a>

§

impl<'a> UnsafeUnpin for ZonReader<'a>

§

impl<'a> UnwindSafe for ZonReader<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.