pub struct SourceDocument {
pub name: String,
pub format: InputFormat,
pub bytes: Vec<u8>,
pub path: Option<PathBuf>,
pub base_url: Option<String>,
}Expand description
A loaded input document: its name, detected format, and raw bytes.
Fields§
§name: String§format: InputFormat§bytes: Vec<u8>§path: Option<PathBuf>The filesystem path it was loaded from, if any (from_file). Used to
resolve relative <img src> paths when image fetching is enabled; None
for in-memory sources.
base_url: Option<String>The URL this document was fetched from, if any. Used to resolve
relative / protocol-relative <img src> against the page’s origin when
image fetching is enabled (an HTML page fetched from the web references
its images by relative path). None for local / in-memory sources.
Implementations§
Source§impl SourceDocument
impl SourceDocument
Sourcepub fn from_file(path: impl AsRef<Path>) -> Result<Self, ConversionError>
pub fn from_file(path: impl AsRef<Path>) -> Result<Self, ConversionError>
Load a document from a filesystem path, detecting the format from the extension.
Sourcepub fn from_bytes(
name: impl Into<String>,
format: InputFormat,
bytes: Vec<u8>,
) -> Self
pub fn from_bytes( name: impl Into<String>, format: InputFormat, bytes: Vec<u8>, ) -> Self
Construct directly from in-memory bytes (no disk access).
Sourcepub fn with_base_url(self, url: impl Into<String>) -> Self
pub fn with_base_url(self, url: impl Into<String>) -> Self
Record the URL this document was fetched from (for resolving relative
<img src> against the page origin when image fetching is enabled).
Sourcepub fn base_dir(&self) -> Option<&Path>
pub fn base_dir(&self) -> Option<&Path>
The directory containing the source file, for resolving relative asset
paths. None for in-memory sources.
Sourcepub fn text(&self) -> Result<&str, ConversionError>
pub fn text(&self) -> Result<&str, ConversionError>
View the bytes as UTF-8 text, for text-based backends. A leading UTF-8
BOM is dropped (docling#4098/#4109, 2.123.1–2.124): Excel and Google
Sheets write one when exporting “CSV UTF-8”, and kept it prefixes the
first cell/line — # Title/= Title stops being a heading, WebVTT’s
signature check misses WEBVTT, JSON parsing rejects the document
outright. One strip here covers every text backend.
Trait Implementations§
Source§impl Clone for SourceDocument
impl Clone for SourceDocument
Source§fn clone(&self) -> SourceDocument
fn clone(&self) -> SourceDocument
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for SourceDocument
impl RefUnwindSafe for SourceDocument
impl Send for SourceDocument
impl Sync for SourceDocument
impl Unpin for SourceDocument
impl UnsafeUnpin for SourceDocument
impl UnwindSafe for SourceDocument
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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