Skip to main content

Files

Struct Files 

Source
pub struct Files<'a> { /* private fields */ }
Expand description

The file operations of one task: paths resolve against the task directory, and every access is recorded, with every file a write changed.

Implementations§

Source§

impl<'a> Files<'a>

Source

pub const fn new( dir: &'a AbsolutePath, accesses: &'a mut Accesses, changes: &'a mut FileChanges, ) -> Self

The file operations of the task in dir, recording into accesses and, for writes that change a file, into changes.

Source

pub fn noting(self, outcomes: Option<&'a mut AccessOutcomes>) -> Self

The file operations, which also note how each access ended into outcomes when it is Some, for the observation report of kizz run --output.

Source

pub fn resolve(&self, path: &str) -> AbsolutePath

The absolute path of path, relative to the task directory unless absolute.

Source

pub fn read_bytes_if_present( &mut self, path: &AbsolutePath, ) -> Result<Option<Vec<u8>>, FileError>

Read the bytes of the file at path, or None when it is missing; the file is recorded as read, or probed when missing.

§Errors

Returns FileError when the file exists but cannot be read.

Source

pub fn read_bytes(&mut self, path: &AbsolutePath) -> Result<Vec<u8>, FileError>

Read the bytes of the file at path.

§Errors

Returns FileError when the file is missing or cannot be read.

Source

pub fn read_text(&mut self, path: &str) -> Result<String, FileError>

Read the file at path as text, with bytes that are not valid UTF-8 replaced.

§Errors

Returns FileError when the file is missing or cannot be read.

Source

pub fn write_bytes( &mut self, path: &str, content: &[u8], ) -> Result<bool, FileError>

Write content to the file at path, creating parent directories, unless the file already holds exactly content. Returns whether the file was written; a written file is noted as changed. A write that leaves the file as it was succeeds; each parent directory it created has the outcome of creating them.

§Errors

Returns FileError when a directory cannot be created or the file cannot be written.

Source

pub fn read_json(&mut self, path: &str) -> Result<Value, FileError>

Read the file at path as JSON.

§Errors

Returns FileError when the file is missing, cannot be read, or is not valid JSON.

Source

pub fn write_json( &mut self, path: &str, value: &Value, indent: usize, ) -> Result<bool, FileError>

Write value to the file at path as stable JSON with indent spaces per level and a trailing newline, unless the file already holds exactly that text. Returns whether the file was written.

§Errors

Returns FileError when the file cannot be written.

Source

pub fn exists(&mut self, path: &str) -> bool

Whether path exists, following symbolic links; the path is recorded as probed.

Source

pub fn list(&mut self, path: &str) -> Result<Vec<String>, FileError>

The names of the entries of the directory at path, sorted, with bytes that are not valid UTF-8 replaced.

§Errors

Returns FileError when the directory is missing or cannot be read.

Source

pub fn glob(&mut self, pattern: &str) -> Result<Vec<String>, FileError>

The paths that match the glob pattern, sorted.

The pattern is split at its first component with a glob character: the components before it name the directory the search starts in, relative to the task directory unless absolute, and the rest is matched against paths below it. *, ?, [...], and {a,b} stay within one component, and ** matches any number of components. Names that start with . match like any other. Each match is the starting directory as written, joined with the matching path. Every directory read is recorded as listed, and a missing one as probed; a pattern without glob characters probes its one path.

§Errors

Returns FileError when the pattern is not valid or a directory cannot be read.

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for Files<'a>

§

impl<'a> Freeze for Files<'a>

§

impl<'a> RefUnwindSafe for Files<'a>

§

impl<'a> Send for Files<'a>

§

impl<'a> Sync for Files<'a>

§

impl<'a> Unpin for Files<'a>

§

impl<'a> UnsafeUnpin for Files<'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
§

impl<T> AsTypeStaticRegistered for T

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ToAst for T

§

fn ast(self, begin: usize, end: usize) -> Spanned<Self>

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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more