Reader

Struct Reader 

Source
pub struct Reader<R> { /* private fields */ }

Implementations§

Source§

impl<R> Reader<R>
where R: Read,

Source

pub fn new(r: R) -> Self
where R: Read,

Examples found in repository?
examples/port.rs (line 20)
7fn main() {
8    let (sender, receiver) = mpsc::channel::<Vec<u8>>();
9
10    // port -> beam
11    let mut writer = ei::Writer::new(io::stdout());
12
13    thread::spawn(move || {
14        while let Ok(vec) = receiver.recv() {
15            writer.send(vec.as_slice()).unwrap()
16        }
17    });
18
19    // beam -> port
20    let mut reader = ei::Reader::new(io::stdin());
21
22    while let Ok(vec) = reader.recv() {
23        let s = sender.clone();
24        thread::spawn(move || {
25            let req: (u8, i64, i64, ei::Pid, ei::Atom, ei::Ref) =
26                ei::deserialize!(vec.as_slice()).unwrap();
27
28            let res = match req.0 {
29                0x61 => {
30                    let res = (ei::atom!("ok"), add(req.1, req.2), req.3, req.4, req.5);
31                    ei::serialize!(&res).unwrap()
32                }
33                0x73 => {
34                    let res = (ei::atom!("ok"), sub(req.1, req.2), req.3, req.4, req.5);
35                    ei::serialize!(&res).unwrap()
36                }
37                _ => {
38                    let res = (ei::atom!("error"), ei::atom!("undef"), req.3, req.4, req.5);
39                    ei::serialize!(&res).unwrap()
40                }
41            };
42
43            s.send(res).unwrap();
44        });
45    }
46}
Source

pub fn read_exact_u8(&mut self) -> Result<Vec<u8>, Error>

Source

pub fn read_exact_u16(&mut self) -> Result<Vec<u8>, Error>

Source

pub fn read_exact_u32(&mut self) -> Result<Vec<u8>, Error>

Source

pub fn read_exact_usize(&mut self, len: usize) -> Result<Vec<u8>, Error>

Source

pub fn read_string_u8(&mut self) -> Result<String, Error>

Source

pub fn read_string_u16(&mut self) -> Result<String, Error>

Source

pub fn read_exact(&mut self, buf: &mut [u8]) -> Result<(), Error>

Source

pub fn read_i16(&mut self) -> Result<i16, Error>

Source

pub fn read_i32(&mut self) -> Result<i32, Error>

Source

pub fn read_u8(&mut self) -> Result<u8, Error>

Source

pub fn read_u16(&mut self) -> Result<u16, Error>

Source

pub fn read_u32(&mut self) -> Result<u32, Error>

Source

pub fn read_u64(&mut self) -> Result<u64, Error>

Source

pub fn read_f64(&mut self) -> Result<f64, Error>

Source§

impl<R> Reader<R>
where R: Read,

Source

pub fn recv(&mut self) -> Result<Vec<u8>, Error>

Examples found in repository?
examples/port.rs (line 22)
7fn main() {
8    let (sender, receiver) = mpsc::channel::<Vec<u8>>();
9
10    // port -> beam
11    let mut writer = ei::Writer::new(io::stdout());
12
13    thread::spawn(move || {
14        while let Ok(vec) = receiver.recv() {
15            writer.send(vec.as_slice()).unwrap()
16        }
17    });
18
19    // beam -> port
20    let mut reader = ei::Reader::new(io::stdin());
21
22    while let Ok(vec) = reader.recv() {
23        let s = sender.clone();
24        thread::spawn(move || {
25            let req: (u8, i64, i64, ei::Pid, ei::Atom, ei::Ref) =
26                ei::deserialize!(vec.as_slice()).unwrap();
27
28            let res = match req.0 {
29                0x61 => {
30                    let res = (ei::atom!("ok"), add(req.1, req.2), req.3, req.4, req.5);
31                    ei::serialize!(&res).unwrap()
32                }
33                0x73 => {
34                    let res = (ei::atom!("ok"), sub(req.1, req.2), req.3, req.4, req.5);
35                    ei::serialize!(&res).unwrap()
36                }
37                _ => {
38                    let res = (ei::atom!("error"), ei::atom!("undef"), req.3, req.4, req.5);
39                    ei::serialize!(&res).unwrap()
40                }
41            };
42
43            s.send(res).unwrap();
44        });
45    }
46}

Auto Trait Implementations§

§

impl<R> Freeze for Reader<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for Reader<R>
where R: RefUnwindSafe,

§

impl<R> Send for Reader<R>
where R: Send,

§

impl<R> Sync for Reader<R>
where R: Sync,

§

impl<R> Unpin for Reader<R>
where R: Unpin,

§

impl<R> UnwindSafe for Reader<R>
where R: UnwindSafe,

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.