pub struct ElementGraph { /* private fields */ }Expand description
Index-based graph of relationships between document elements.
Built from a &[Element] slice, the graph stores parent/child and next/prev
relationships as indices into the original slice. No ownership is taken and
no lifetimes are introduced — the graph is a standalone value that can be
stored, cloned, or sent across threads independently of the elements.
§Example
use oxidize_pdf::parser::PdfDocument;
use oxidize_pdf::pipeline::ElementGraph;
let doc = PdfDocument::open("document.pdf")?;
let (elements, graph) = doc.partition_graph(Default::default())?;
for title_idx in graph.top_level_sections() {
println!("Section: {}", elements[title_idx].text());
for &child_idx in graph.children_of(title_idx) {
println!(" {}", elements[child_idx].text());
}
}§Parent / child semantics
An element at index i is a child of the nearest preceding Title element
whose text matches elements[i].metadata().parent_heading. A Title element
whose own parent_heading equals its own text is treated as a root (no parent)
unless a different preceding title has the same text.
Implementations§
Source§impl ElementGraph
impl ElementGraph
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Number of elements in the graph (equals the length of the source slice).
Sourcepub fn parent_of(&self, idx: usize) -> Option<usize>
pub fn parent_of(&self, idx: usize) -> Option<usize>
Returns the index of the parent element of idx, or None if it is a root.
§Panics
Panics if idx >= self.len().
Sourcepub fn children_of(&self, idx: usize) -> &[usize]
pub fn children_of(&self, idx: usize) -> &[usize]
Sourcepub fn next_of(&self, idx: usize) -> Option<usize>
pub fn next_of(&self, idx: usize) -> Option<usize>
Returns the index of the element immediately after idx, or None if idx
is the last element.
§Panics
Panics if idx >= self.len().
Sourcepub fn prev_of(&self, idx: usize) -> Option<usize>
pub fn prev_of(&self, idx: usize) -> Option<usize>
Returns the index of the element immediately before idx, or None if idx
is the first element.
§Panics
Panics if idx >= self.len().
Sourcepub fn elements_in_section(&self, title_idx: usize) -> Vec<usize>
pub fn elements_in_section(&self, title_idx: usize) -> Vec<usize>
Returns the child indices of a Title element (i.e., the elements belonging to its section).
This is an alias for children_of with a semantically
clearer name for the common case of iterating a document section.
Sourcepub fn top_level_sections(&self) -> Vec<usize>
pub fn top_level_sections(&self) -> Vec<usize>
Returns the indices of all Title elements that have no parent (top-level sections).
Auto Trait Implementations§
impl Freeze for ElementGraph
impl RefUnwindSafe for ElementGraph
impl Send for ElementGraph
impl Sync for ElementGraph
impl Unpin for ElementGraph
impl UnsafeUnpin for ElementGraph
impl UnwindSafe for ElementGraph
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more