Struct Parser

Source
pub struct Parser<R> { /* private fields */ }
Expand description

Pull parser for FBX 7.4 binary or compatible later versions.

Implementations§

Source§

impl<R: Read> Parser<R>

Source

pub const PARSER_VERSION: ParserVersion = ParserVersion::V7400

Parser version.

Source

pub fn from_reader(header: FbxHeader, reader: R) -> Result<Self>

Creates a new Parser from the given reader.

Returns an error if the given FBX version in unsupported.

Source

pub fn from_seekable_reader(header: FbxHeader, reader: R) -> Result<Self>
where R: Seek,

Creates a new Parser from the given seekable reader.

Returns an error if the given FBX version in unsupported.

Source

pub fn set_warning_handler<F>(&mut self, warning_handler: F)
where F: 'static + FnMut(Warning, &SyntacticPosition) -> Result<()>,

Sets the warning handler.

The warning handler will receive warnings and their syntactic positions each time the warnings happen.

If the handler returned Ok(()), the warning is considered non-critical and parsing can be continued. If the handler returned Err(_), the warning is considered critical, and the parsing cannot be continued.

§Examples
let mut parser = fbxcel::pull_parser::v7400::Parser::from_reader(header, reader)
    .expect("Failed to create parser");
parser.set_warning_handler(|warning, pos| {
    // Print warning.
    eprintln!("WARNING: {} (pos={:?})", warning, pos);
    // To ignore the warning and continue processing, return `Ok(())`.
    // To treat the given warning as a critical error, return
    // `Err(warning.into())`.
    Ok(())
});
Source

pub fn fbx_version(&self) -> FbxVersion

Returns FBX version.

Source

pub fn current_node_name(&self) -> &str

Returns the name of the current node.

§Panics

This panics if there are no open nodes.

Source

pub fn current_depth(&self) -> usize

Returns current node depth.

Implicit root node is considered to be depth 0.

Source

pub fn next_event(&mut self) -> Result<Event<'_, R>>

Returns next event if successfully read.

You should not call next_event() if a parser functionality has been already failed and returned error. If you call next_event() with failed parser, error created from OperationError::AlreadyAborted will be returned.

Source

pub fn skip_current_node(&mut self) -> Result<()>

Ignores events until the current node closes.

This discards parser events until the EndNode event for the current node is read. The last EndNode (for the current node) is also discarded.

This method seeks to the node end position without any additional parsing, since the parser already knows the node end position. Because of this, some errors can be overlooked, or detected at the different position from the true error position.

To detect errors correctly, you should use next_event manually. See an example to how to do this.

§Panics

Panics if there are no open nodes, i.e. when current_depth() returns 0.

§Examples
let mut parser = fbxcel::pull_parser::v7400::Parser::from_reader(header, reader)
    .expect("Failed to create parser");
// Do something here.
// Something done.
let depth = parser.current_depth();
if depth > 0 {
    parser.skip_current_node().expect("Failed to skip current node");
    assert_eq!(parser.current_depth(), depth - 1);
}

parser.skip_current_node() is almost same as the code below, except for error handling.

fn skip_current_node<R: std::io::Read>(parser: &mut Parser<R>) -> Result<()> {
    loop {
        match parser.next_event()? {
            Event::StartNode(_) => skip_current_node(parser)?,
            Event::EndNode => return Ok(()),
            Event::EndFbx(_) => panic!("Attempt to skip implicit top-level node"),
        }
    }
}
Source

pub fn position(&self) -> SyntacticPosition

Returns the syntactic position of the current node.

Note that this allocates memory.

Source

pub fn is_used(&self) -> bool

Returns whether the parser is already used or brand-new.

Returns true if the parser emitted some events in the past, returns false if the parser have not emitted any events.

§Examples
let mut parser = fbxcel::pull_parser::v7400::Parser::from_reader(header, reader)
    .expect("Failed to create parser");
assert!(!parser.is_used());
parser.set_warning_handler(|warning, pos| {
    // Print warning.
    eprintln!("WARNING: {} (pos={:?})", warning, pos);
    // To ignore the warning and continue processing, return `Ok(())`.
    // To treat the given warning as a critical error, return
    // `Err(warning.into())`.
    Ok(())
});
assert!(!parser.is_used(), "Parser emitted no events yet");
let _ = parser.next_event();
assert!(parser.is_used(), "Parser emitted an event");

Trait Implementations§

Source§

impl<R: Debug> Debug for Parser<R>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

impl<R> !RefUnwindSafe for Parser<R>

§

impl<R> !Send for Parser<R>

§

impl<R> !Sync for Parser<R>

§

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

§

impl<R> !UnwindSafe for Parser<R>

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.