ply_rs::parser

Struct Parser

Source
pub struct Parser<E: PropertyAccess> { /* private fields */ }
Expand description

Reads data given by a Read trait into Ply components.

In most cases read_ply() should suffice. If you need finer control over the read process, there are methods down to the line/element level.

§Examples

The most common case is probably to read from a file:

// set up a reader, in this case a file.
let path = "example_plys/greg_turk_example1_ok_ascii.ply";
let mut f = std::fs::File::open(path).unwrap();

// create a parser
let p = parser::Parser::<ply::DefaultElement>::new();

// use the parser: read the entire file
let ply = p.read_ply(&mut f);

// Did it work?
assert!(ply.is_ok());

If you need finer control, you can start splitting the read operations down to the line/element level.

In the follwoing case we first read the header, and then continue with the payload. We need to build a Ply our selves.

// set up a reader as before.
// let mut f = ... ;
// We need to wrap our `Read` into something providing `BufRead`
let mut buf_read = std::io::BufReader::new(f);

// create a parser
let p = parser::Parser::<ply::DefaultElement>::new();

// use the parser: read the header
let header = p.read_header(&mut buf_read);
// Did it work?
let header = header.unwrap();

// read the payload
let payload = p.read_payload(&mut buf_read, &header);
// Did it work?
let payload = payload.unwrap();

// May be create your own Ply:
let ply = ply::Ply {
    header: header,
    payload: payload,
};

println!("Ply: {:#?}", ply);

Implementations§

Source§

impl<E: PropertyAccess> Parser<E>

Source

pub fn new() -> Self

Creates a new Parser<E>, where E is the type to store the element data in.

To get started quickly try DefaultElement from the ply module.

Source

pub fn read_ply<T: Read>(&self, source: &mut T) -> Result<Ply<E>>

Expects the complete content of a PLY file.

A PLY file starts with “ply\n”. read_ply reads until all elements have been read as defined in the header of the PLY file.

Source§

impl<E: PropertyAccess> Parser<E>

#Header

Source

pub fn read_header<T: BufRead>(&self, reader: &mut T) -> Result<Header>

Reads header until and inclusive end_header.

A ply file starts with “ply\n”. The header and the payload are separated by a line end_header\n. This method reads all headere elemnts up to end_header.

Source

pub fn read_header_line(&self, line: &str) -> Result<Line>

Source§

impl<E: PropertyAccess> Parser<E>

§Payload

Source

pub fn read_payload<T: BufRead>( &self, reader: &mut T, header: &Header, ) -> Result<Payload<E>>

Reads payload. Encoding is chosen according to the encoding field in header.

Source

pub fn read_payload_for_element<T: BufRead>( &self, reader: &mut T, element_def: &ElementDef, header: &Header, ) -> Result<Vec<E>>

Reads entire list of elements from payload. Encoding is chosen according to header.

Make sure to read the elements in the order as they are defined in the header.

Source§

impl<E: PropertyAccess> Parser<E>

§Ascii

Source

pub fn read_ascii_element( &self, line: &str, element_def: &ElementDef, ) -> Result<E>

Read a single element. Assume it is encoded in ascii.

Make sure all elements are parsed in the order they are defined in the header.

Source§

impl<E: PropertyAccess> Parser<E>

§Binary

Source

pub fn read_big_endian_element<T: Read>( &self, reader: &mut T, element_def: &ElementDef, ) -> Result<E>

Reads a single element as declared in èlement_def. Assumes big endian encoding.

Make sure all elements are parsed in the order they are defined in the header.

Source

pub fn read_little_endian_element<T: Read>( &self, reader: &mut T, element_def: &ElementDef, ) -> Result<E>

Reads a single element as declared in èlement_def. Assumes big endian encoding.

Make sure all elements are parsed in the order they are defined in the header.

Auto Trait Implementations§

§

impl<E> Freeze for Parser<E>

§

impl<E> RefUnwindSafe for Parser<E>
where E: RefUnwindSafe,

§

impl<E> Send for Parser<E>
where E: Send,

§

impl<E> Sync for Parser<E>
where E: Sync,

§

impl<E> Unpin for Parser<E>
where E: Unpin,

§

impl<E> UnwindSafe for Parser<E>
where E: 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.