pub struct SourceDocument { /* private fields */ }Expand description
An immutable, contiguous source document with stable line coordinates.
The source text is retained as one allocation. line_starts makes line lookup
and byte spans constant time without copying or normalizing the document.
Implementations§
Source§impl SourceDocument
impl SourceDocument
Sourcepub fn new(text: impl AsRef<str>) -> Result<Self, SourceUnavailable>
pub fn new(text: impl AsRef<str>) -> Result<Self, SourceUnavailable>
Captures one immutable source document.
§Errors
Returns a typed unavailable reason when the source exceeds the complete-file byte or line limits.
Sourcepub fn try_from_text(text: &str) -> Result<Self, SourceUnavailable>
pub fn try_from_text(text: &str) -> Result<Self, SourceUnavailable>
Captures exact byte identity while normalizing rendered line endings like patch parsing.
§Errors
Returns a typed unavailable reason before allocating normalized lines when the source exceeds the complete-file byte or line limits.
Sourcepub fn line_span(&self, number: usize) -> Option<Range<usize>>
pub fn line_span(&self, number: usize) -> Option<Range<usize>>
Returns the zero-based byte span of a one-based source line.
pub fn text(&self) -> &str
pub fn line_starts(&self) -> &[usize]
pub const fn identity(&self) -> Fingerprint
pub fn line_count(&self) -> usize
pub const fn content_id(&self) -> Fingerprint
pub const fn sequence_id(&self) -> SourceSequenceId
pub const fn byte_len(&self) -> u64
pub const fn trailing_newline(&self) -> bool
Trait Implementations§
Source§impl Clone for SourceDocument
impl Clone for SourceDocument
Source§fn clone(&self) -> SourceDocument
fn clone(&self) -> SourceDocument
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SourceDocument
impl Debug for SourceDocument
Source§impl<'de> Deserialize<'de> for SourceDocument
impl<'de> Deserialize<'de> for SourceDocument
Source§fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>
Deserialize this value from the given Serde deserializer. Read more
impl Eq for SourceDocument
Source§impl PartialEq for SourceDocument
impl PartialEq for SourceDocument
Auto 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
Mutably borrows from an owned value. Read more