pub struct Document {
pub title: Option<String>,
pub metadata: Metadata,
pub blocks: Vec<Block>,
pub block_pages: Vec<usize>,
pub citations: Vec<Citation>,
}Fields§
§title: Option<String>§metadata: Metadata§blocks: Vec<Block>§block_pages: Vec<usize>The 1-based page each block starts on, parallel to Self::blocks
(block_pages[i] is the page of blocks[i]).
§Why this exists
Reconstruction always knew the page — it builds one block list per page and then flattens them — and until now it simply threw that away. That made the Document Engine unusable for every consumer that has to cite what it extracted: a citation without a page is not one a reader can follow, and “provenance” that cannot be checked is a promise rather than a fact.
This was found the hard way. The kopitiam-legal engine needed page
provenance for statutes, could not get it, and worked around the gap by
calling reconstruct() one page at a time so the page was known by
construction — which silently gave up the cross-page paragraph merging
(merge_page_breaks) that legal text needs constantly, since statutes
split provisions across pages all the time. It paid a real cost to
recover a number this crate already had.
Every provenance-carrying consumer needs it — legal, insurance, health, finance, literature all cite by page — so it belongs here rather than being rediscovered and worked around five more times.
§A block that spans a page break
Records the page it started on. A paragraph merged across a page
break by crate::reconstruct therefore reports the earlier page,
which is the right answer for a citation: it is where a reader should
begin looking.
citations: Vec<Citation>Citations detected in paragraph text, for provenance reporting. See
Citation – these are pointers into already-rendered text, not
separate content.
Implementations§
Source§impl Document
impl Document
Sourcepub fn page_of(&self, index: usize) -> Option<usize>
pub fn page_of(&self, index: usize) -> Option<usize>
The 1-based page that blocks[index] starts on.
Returns None for an out-of-range index, and — deliberately — also for
a Document constructed without page information (e.g. via
Default), rather than guessing page 1. A wrong page in a citation is
worse than an absent one: it sends a reader to the wrong place and looks
authoritative doing it.
Sourcepub fn blocks_with_pages(&self) -> impl Iterator<Item = (&Block, Option<usize>)>
pub fn blocks_with_pages(&self) -> impl Iterator<Item = (&Block, Option<usize>)>
Iterates blocks paired with the page each starts on.
Yields None for the page when a Document carries no page
information, so a consumer that requires provenance can detect that
rather than silently attribute everything to page 1.
Trait Implementations§
impl StructuralPartialEq for Document
Auto Trait Implementations§
impl Freeze for Document
impl RefUnwindSafe for Document
impl Send for Document
impl Sync for Document
impl Unpin for Document
impl UnsafeUnpin for Document
impl UnwindSafe for Document
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more