Skip to main content

WriteTarget

Struct WriteTarget 

Source
pub struct WriteTarget(/* private fields */);
Expand description

A write target the city has cleared: no alias at the name or at any directory above it, so a write here lands exactly where the name says.

The invariant lives at the one constructor and the field is private, so an unchecked path cannot be spelled - every write face takes this value and nothing else (trybuild tests/ui/write_target.rs). What the value proves is that the name held no alias at the moment at asked; the window between that question and the write is the filesystem’s, which is why the walking faces ask the same rule at their own sampling point.

Implementations§

Source§

impl WriteTarget

Source

pub fn at(op: &'static str, path: &Path) -> Result<WriteTarget, StorageError>

The one constructor: path and every directory above it are examined, and any alias refuses the write whole.

§Errors

StorageError::Alias naming the alias and its kind; StorageError::Io when a component exists and cannot be examined.

Source

pub fn within( op: &'static str, root: &Path, path: &Path, ) -> Result<WriteTarget, StorageError>

Clears path for a write inside root, the directory the person chose: path and every directory between it and root are examined, and root and everything above it are not, because where a person keeps a city is their placement rather than a write a run could redirect (crates/storage/spec/Bundle.lean §8-12). A path outside root is examined up to the filesystem root, as WriteTarget::at does.

The bound is found by comparing path components as spelled, so the caller builds path by joining onto the same root it passes; a root in another spelling (a trailing separator, a . component, other case on Windows) is not found, and the walk falls back to the filesystem root, which is safe but loses the bound.

§Errors

As WriteTarget::at, for an alias at or below the bound.

Source

pub fn as_path(&self) -> &Path

Source

pub fn replace(self, bytes: &[u8]) -> Result<(), StorageError>

Replaces the file at this name with bytes: a staging file beside it, flushed, given the replaced file’s permissions and renamed over the name (crates/storage/Spec.lean §8-12, §8-32). A reader finds the old file or the whole new one.

§Errors

StorageError::Io for a write, flush, permission copy or rename the filesystem refuses; the name keeps its previous content.

Source

pub fn create(self, bytes: &[u8]) -> Result<(), StorageError>

Creates the file at this name only when nothing stands there: the name is claimed by the filesystem at the moment of the write, so of two racing creates one succeeds (crates/storage/spec/Alias.lean §8-32).

§Errors

StorageError::NameTaken when anything stands at the name, with nothing written; StorageError::Io for a create, write or flush the filesystem refuses.

Trait Implementations§

Source§

impl Debug for WriteTarget

Names the path it cleared and nothing else: there is no hidden state to show and a write target’s whole story is where it lands.

Source§

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

Formats the value using the given formatter. Read more

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> 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 = !

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.