Skip to content

Commit

Permalink
unwrap_or_default() (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
iganev authored May 17, 2024
1 parent e362735 commit 42b2806
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,11 @@ impl PopplerDocument {
}

pub fn pages(&self) -> PagesIter {
PagesIter { total: self.get_n_pages(), index: 0, doc: self }
PagesIter {
total: self.get_n_pages(),
index: 0,
doc: self,
}
}
}

Expand Down Expand Up @@ -152,7 +156,7 @@ impl PopplerPage {
pub fn get_text(&self) -> Option<&str> {
match unsafe { ffi::poppler_page_get_text(self.0) } {
ptr if ptr.is_null() => None,
ptr => unsafe { Some(CStr::from_ptr(ptr).to_str().unwrap()) },
ptr => unsafe { Some(CStr::from_ptr(ptr).to_str().unwrap_or_default()) },
}
}
}
Expand All @@ -161,7 +165,7 @@ impl PopplerPage {
pub struct PagesIter<'a> {
total: usize,
index: usize,
doc: &'a PopplerDocument
doc: &'a PopplerDocument,
}

impl<'a> Iterator for PagesIter<'a> {
Expand All @@ -178,7 +182,6 @@ impl<'a> Iterator for PagesIter<'a> {
}
}


#[cfg(test)]
mod tests {
use crate::PopplerDocument;
Expand Down Expand Up @@ -326,7 +329,7 @@ mod tests {
assert!(w == src_w);
assert!(h == src_h);

println!("page {}/{} -- {}x{}", index+1, total, w, h);
println!("page {}/{} -- {}x{}", index + 1, total, w, h);
count += 1;
}

Expand Down

0 comments on commit 42b2806

Please sign in to comment.