Skip to main content

StreamSource

Enum StreamSource 

Source
pub enum StreamSource<'a> {
    Contiguous(&'a [u8]),
    Split {
        base: &'a [u8],
        staged: &'a [u8],
    },
}
Expand description

Where a ByteSpan carried by a stream in some object graph resolves to actual bytes.

Two variants, because pdfcer has exactly two kinds of readable document (module docs): a loaded file, whose spans all index one buffer, and an editing session, whose spans index the base file or the R45 staging buffer under one combined coordinate system.

Copy, because it is a pair of shared borrows and threading it through a render walk by value is cheaper and clearer than by reference.

§Examples

use pdfcer_model::span::ByteSpan;
use pdfcer_model::view::StreamSource;

let base = b"BASE-BYTES";
let staged = b"STAGED";
let src = StreamSource::Split { base, staged };

// A base-side span reads the base half.
assert_eq!(src.slice(ByteSpan::new(0, 4)), Some(&b"BASE"[..]));
// A staged span is expressed as `base.len() + local` (R45).
assert_eq!(src.slice(ByteSpan::new(base.len(), 6)), Some(&b"STAGED"[..]));
// A span that crosses the boundary is a provenance bug: refused.
assert_eq!(src.slice(ByteSpan::new(base.len() - 1, 3)), None);

Variants§

§

Contiguous(&'a [u8])

One buffer: a plain Document’s retained file bytes. Spans index it directly, exactly as ByteSpan::slice does.

§

Split

Two disjoint buffers under one coordinate system: an EditSession’s base file plus its R45 staging buffer.

A span with start < base.len() belongs to base; a span with start >= base.len() belongs to staged at local offset start - base.len(). See the module docs for why a span can never belong to both.

Fields

§base: &'a [u8]

The base revision as loaded from disk.

§staged: &'a [u8]

Stream payloads authored this session, whose spans are offset by base.len() (see EditSession::stage_bytes).

Implementations§

Source§

impl<'a> StreamSource<'a>

Source

pub fn slice(&self, span: ByteSpan) -> Option<&'a [u8]>

The bytes span covers, or None if it cannot be served.

None has exactly three causes, all of them logic errors rather than data errors, and all of them degraded rather than panicked per the crate’s panic-free policy:

  1. the span is out of bounds for the buffer it names;
  2. the span straddles the base/staging boundary (module docs — structurally impossible today, refused so that it stays that way);
  3. the span was produced against a different document’s buffer.

Callers turn None into their own named refusal — the renderer counts it as an undecodable stream, pageops stages an empty payload — rather than substituting plausible bytes.

Source

pub const fn len(&self) -> usize

Total addressable length of this source, in the span coordinate system.

Diagnostic only — used by DocumentView’s Debug and by tests asserting the R45 offset scheme (see EditSession::stage_bytes). Deliberately NOT a way to get at a buffer: there is no accessor returning the concatenation, because materializing one is precisely the cost this type exists to avoid.

Source

pub const fn is_empty(&self) -> bool

Whether this source addresses no bytes at all.

Trait Implementations§

Source§

impl<'a> Clone for StreamSource<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for StreamSource<'a>

Source§

impl<'a> Debug for StreamSource<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Eq for StreamSource<'a>

Source§

impl<'a> PartialEq for StreamSource<'a>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for StreamSource<'a>

Auto Trait Implementations§

§

impl<'a> Forget for StreamSource<'a>

§

impl<'a> Freeze for StreamSource<'a>

§

impl<'a> RefUnwindSafe for StreamSource<'a>

§

impl<'a> Send for StreamSource<'a>

§

impl<'a> Sync for StreamSource<'a>

§

impl<'a> Unpin for StreamSource<'a>

§

impl<'a> UnsafeUnpin for StreamSource<'a>

§

impl<'a> UnwindSafe for StreamSource<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.