Struct ply_rs::parser::Parser [] [src]

pub struct Parser<E: PropertyAccess> { /* fields omitted */ }

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);

Methods

impl<E: PropertyAccess> Parser<E>
[src]

[src]

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.

[src]

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.

impl<E: PropertyAccess> Parser<E>
[src]

Header

[src]

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.

[src]

impl<E: PropertyAccess> Parser<E>
[src]

Payload

[src]

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

[src]

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.

impl<E: PropertyAccess> Parser<E>
[src]

Ascii

[src]

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.

impl<E: PropertyAccess> Parser<E>
[src]

Binary

[src]

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.

[src]

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.