Skip to main content

ContentsShape

Enum ContentsShape 

Source
pub enum ContentsShape {
    Absent,
    Single(ObjRef),
    Array(Vec<ObjRef>),
}
Expand description

Where a regenerated element lands in the page’s /Contents.

The /Contents entry is a stream, an array of streams, or absent, and adding or removing an element moves it between those shapes. The rules are not symmetric, which is the point of naming them:

  • absent gaining an element becomes a lone stream at index 0;
  • a lone stream gaining a second becomes an array [old new], and the new one is index 1;
  • an array gaining one appends, at len - 1;
  • a lone stream losing index 0 loses the /Contents key entirely;
  • an array losing elements keeps being an array — even down to one element, and even down to none. Collapsing a one-element array back to a bare stream would be tidier and is deliberately not done: a second stream may well be added next, and every object’s recorded index would have to move again.

Variants§

§

Absent

No /Contents at all.

§

Single(ObjRef)

One stream, reached through /Contents directly.

§

Array(Vec<ObjRef>)

An array of stream references.

Implementations§

Source§

impl ContentsShape

Source

pub fn read(page_dict: &Dict, r: &impl Resolve) -> Self

Read the shape out of a page dictionary.

Anything that is neither a stream nor an array of streams — a dangling reference, a number, a name — reads as ContentsShape::Absent, which is how a page with unusable contents behaves everywhere else.

Source

pub fn with_added(&self, added: ObjRef) -> (usize, Self)

The index a newly added element takes, and the shape afterwards.

Source

pub fn with_removed( &self, removed: &BTreeSet<usize>, ) -> (Self, BTreeMap<usize, usize>)

The shape after removed elements are dropped, and the map from each surviving element’s old index to its new one.

Every object whose index is not in the map — one whose own element was removed, and one that was still streamless — collapses to index 0. That is the C++’s default-inserting map read literally, and it is deliberate: those objects were not written by this regeneration and their recorded index has to point somewhere.

Both halves of the map are usize: a /Contents index is a position in an array, and there is no negative sentinel.

Source

pub fn to_object(&self, array_ref: Option<ObjRef>) -> Option<Object>

The /Contents value this shape writes, given the object number a fresh array would take.

None for ContentsShape::Absent, which removes the key.

Source

pub fn elements(&self) -> Vec<ObjRef>

The element references, in order.

Trait Implementations§

Source§

impl Clone for ContentsShape

Source§

fn clone(&self) -> ContentsShape

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 Debug for ContentsShape

Source§

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

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

impl Eq for ContentsShape

Source§

impl PartialEq for ContentsShape

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ContentsShape

Auto Trait Implementations§

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.