pub struct PageIndex(/* private fields */);Expand description
A zero-based page index.
PageIndex(0) is the first page. It is not a count: a three-page
document has page_count() == 3 and valid indices 0, 1 and 2, and
Document::page_count deliberately stays u32 rather than becoming a
one-past-the-end PageIndex — a count answers “how many”, an index answers
“which one”, and giving them the same type would let one be passed where
the other is meant, which is the whole reason this newtype exists.
Nor is it validated. Nothing stops PageIndex::new(9000) on a two-page
document; what it names is checked where it is used, and the answer there
is a Result or an Option. A destination that resolves to no page at all
is Option<PageIndex> and never a sentinel.
From<u32> exists so impl Into<PageIndex> arguments accept a literal:
doc.page(0) needs no wrapping at the call site.
use pdfrum_common::PageIndex;
let first = PageIndex::new(0);
assert_eq!(first.get(), 0);
assert_eq!(first.to_string(), "0");
assert_eq!(PageIndex::from(4), PageIndex::new(4));
assert!(PageIndex::new(1) < PageIndex::new(2));