Skip to content

Commit

Permalink
have Lazy resolve into MaybeRef
Browse files Browse the repository at this point in the history
  • Loading branch information
s3bk committed Jan 5, 2025
1 parent 83e4a97 commit 0378c6d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions examples/src/bin/form.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn run() -> Result<(), PdfError> {

let page0 = file.get_page(0).unwrap();
let annots = page0.annotations.load(&file.resolver()).expect("can't load annotations");
for annot in &annots {
for annot in &*annots {
if let Some(ref a) = annot.appearance_streams {
let normal = file.resolver().get(a.normal);
if let Ok(normal) = normal {
Expand Down Expand Up @@ -122,4 +122,4 @@ fn main() {
if let Err(e) = run() {
println!("{e}");
}
}
}
9 changes: 6 additions & 3 deletions pdf/src/object/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,9 +451,12 @@ impl<T: Object> DeepClone for Lazy<T> {
})
}
}
impl<T: Object> Lazy<T> {
pub fn load(&self, resolve: &impl Resolve) -> Result<T> {
T::from_primitive(self.primitive.clone(), resolve)
impl<T: Object + DataSize> Lazy<T> {
pub fn load(&self, resolve: &impl Resolve) -> Result<MaybeRef<T>> {
match self.primitive {
Primitive::Reference(r) => resolve.get(Ref::new(r)).map(MaybeRef::Indirect),
ref p => T::from_primitive(p.clone(), resolve).map(|o| MaybeRef::Direct(Arc::new(o))),
}
}
}
impl<T: Object> Object for Lazy<T> {
Expand Down

0 comments on commit 0378c6d

Please sign in to comment.