Skip to main content

View

Struct View 

Source
pub struct View<S> { /* private fields */ }
Expand description

A view into the content of a Snapshot that can be used to read or write into it.

There are two types of views:

  • CowView: A copy-on-write view where changes to the view do not affect the root snapshot.
  • MutView: A mutable view where changes to the view modify the root snapshot.

Normal rust borrowing semantics apply, where only one mutable view can exist at a time, and multiple immutable views can exist simultaneously. Both views are tied to the lifetime with which they borrow the snapshot, so they cannot outlive the snapshot they reference.

A third type of view ArcView is similar to CowView but must be created from a reference-counted Arc<Snapshot>. Unlike CowView, it has no lifetime requirements.

Implementations§

Source§

impl<S> View<S>

Source

pub fn len(&self) -> usize

Returns the length of the view in bytes.

Source

pub fn is_empty(&self) -> bool

Returns true if the view is empty.

Source

pub fn as_slice(&self) -> &[u8]

Returns a slice containing the entire view. This is equicalent to &view[..],

Source

pub fn as_mut_slice(&mut self) -> &mut [u8]

Returns a mutable slice containing the entire view. This is equicalent to &mut view[..],

Source

pub fn as_ptr(&self) -> *const u8

Returns the base pointer of the view.

Source

pub fn as_mut_ptr(&mut self) -> *mut u8

Returns the base mutable pointer of the view.

Source

pub fn take_snapshot(&self) -> Result<Snapshot>

Creates a new snapshot from the current content of this view, including any changes made to it.

Note: This method copies the entire content of the view and depending on the size of the snapshot, it can be slow.

Source

pub fn restore(&mut self) -> Result<()>

Discard any changes made to this copy-on-write view, restoring it to the original content of the root snapshot. Restoring a view also reverts any memory protection applied to the view. Restoring a view does not change its address.

Trait Implementations§

Source§

impl<S: Debug> Debug for View<S>

Source§

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

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

impl<S> Drop for View<S>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<I: SliceIndex<[u8]>, S> Index<I> for View<S>

Source§

type Output = <I as SliceIndex<[u8]>>::Output

The returned type after indexing.
Source§

fn index(&self, index: I) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<I: SliceIndex<[u8]>, S> IndexMut<I> for View<S>

Source§

fn index_mut(&mut self, index: I) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
Source§

impl<S> Send for View<S>

Source§

impl<S> Sync for View<S>

Auto Trait Implementations§

§

impl<S> Freeze for View<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for View<S>
where S: RefUnwindSafe,

§

impl<S> Unpin for View<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for View<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for View<S>
where S: UnwindSafe,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.