pdfplumber_core/page_object.rs
1//! PageObject enum for custom filtering.
2//!
3//! [`PageObject`] wraps references to different page object types (characters,
4//! lines, rectangles, curves, images) so that a single predicate function can
5//! inspect any object on a page.
6
7use crate::{Char, Curve, Image, Line, Rect};
8
9/// An enum wrapping references to different page object types.
10///
11/// Used as the argument to filter predicates, allowing users to match on
12/// specific object types and inspect their properties.
13///
14/// # Example
15///
16/// ```ignore
17/// // Keep only characters with font "Helvetica" and all non-char objects
18/// page.filter(|obj| match obj {
19/// PageObject::Char(c) => c.fontname == "Helvetica",
20/// _ => true,
21/// });
22/// ```
23pub enum PageObject<'a> {
24 /// A character object.
25 Char(&'a Char),
26 /// A line object.
27 Line(&'a Line),
28 /// A rectangle object.
29 Rect(&'a Rect),
30 /// A curve object.
31 Curve(&'a Curve),
32 /// An image object.
33 Image(&'a Image),
34}