pub struct PageRange(/* private fields */);Expand description
A parsed page range: zero-based page indices, in the order named, with duplicates kept.
Implementations§
Source§impl PageRange
impl PageRange
Sourcepub fn of(indices: impl IntoIterator<Item = impl Into<PageIndex>>) -> Self
pub fn of(indices: impl IntoIterator<Item = impl Into<PageIndex>>) -> Self
A range naming exactly these zero-based indices.
Sourcepub fn parse(text: &str, count: u32) -> Result<Self, Error>
pub fn parse(text: &str, count: u32) -> Result<Self, Error>
Parse "1,3-5" against a document of count pages.
Numbers in the text are one-based; the indices returned are zero-based.
§Errors
Error::BadPageRange for anything the grammar rejects — an illegal
character, a page number outside 1..=count, a descending range, a
three-part entry, or an empty entry. One bad entry fails the whole
string.
use pdfrum_edit::PageRange;
let range = PageRange::parse("1,3-5", 10)?;
assert_eq!(range.indices().iter().map(|p| p.get()).collect::<Vec<_>>(), [0, 2, 3, 4]);
// Order is preserved and duplicates are kept.
let dupes = PageRange::parse("2,1,1", 10)?;
assert_eq!(dupes.indices().iter().map(|p| p.get()).collect::<Vec<_>>(), [1, 0, 0]);
// One bad entry discards everything.
assert!(PageRange::parse("1,clams", 10).is_err());Trait Implementations§
impl Eq for PageRange
impl StructuralPartialEq for PageRange
Auto Trait Implementations§
impl Freeze for PageRange
impl RefUnwindSafe for PageRange
impl Send for PageRange
impl Sync for PageRange
impl Unpin for PageRange
impl UnsafeUnpin for PageRange
impl UnwindSafe for PageRange
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
Mutably borrows from an owned value. Read more