fbxcel/pull_parser/position.rs
1//! Syntactic position.
2
3/// Syntactic position.
4///
5/// This contains not only byte-position, but also additional information such
6/// as node path and attribute index.
7///
8/// This type is implemented based on FBX 7.4 data structure, and may change in
9/// future if FBX syntax has breaking changes.
10#[derive(Debug, Clone, PartialEq, Eq, Hash)]
11pub struct SyntacticPosition {
12 /// Byte position.
13 pub(crate) byte_pos: u64,
14 /// Beginning byte position of the node or attribute.
15 pub(crate) component_byte_pos: u64,
16 /// Node path.
17 ///
18 /// This is a vector of pairs of node indices in siblings (i.e. the number
19 /// of preceding siblings) and node names.
20 pub(crate) node_path: Vec<(usize, String)>,
21 /// Node attribute index (if the position points an attribute).
22 pub(crate) attribute_index: Option<usize>,
23}
24
25impl SyntacticPosition {
26 /// Returns the byte position.
27 #[inline]
28 #[must_use]
29 pub fn byte_pos(&self) -> u64 {
30 self.byte_pos
31 }
32
33 /// Returns the beginning byte position of the node or attribute.
34 #[inline]
35 #[must_use]
36 pub fn component_byte_pos(&self) -> u64 {
37 self.component_byte_pos
38 }
39
40 /// Returns the node path.
41 ///
42 /// This is a vector of pairs of node indices in siblings (i.e. the number
43 /// of preceding siblings) and node names.
44 #[inline]
45 #[must_use]
46 pub fn node_path(&self) -> &[(usize, String)] {
47 &self.node_path
48 }
49
50 /// Returns the node attribute index (if the position points an attribute).
51 #[inline]
52 #[must_use]
53 pub fn attribute_index(&self) -> Option<usize> {
54 self.attribute_index
55 }
56}