Skip to main content

FileAccess

Struct FileAccess 

Source
pub struct FileAccess { /* private fields */ }
Expand description

Tracked, confined access to the project’s files.

Implementations§

Source§

impl FileAccess

Source

pub fn new(root: &Path) -> FileAccess

Anchor reads at a project root, canonicalizing it.

Every containment check compares against the root, so it has to be canonical or a symlinked checkout would fail every check. Callers that already hold a canonical root should use FileAccess::rooted instead — this is one syscall, and the engine builds an access per file.

Source

pub fn rooted(root: PathBuf) -> FileAccess

Anchor reads at an already-canonical root.

Cheap enough to call per file, which is what the engine does: a fresh access per file makes it structurally impossible for one file’s reads to be recorded against another’s, rather than making it depend on a reset being called in the right place.

Source

pub fn root(&self) -> &Path

The project root reads are confined to.

Source

pub fn read(&self, path: &str) -> Result<Option<String>, ReadError>

Read a file’s text, or None if nothing is there.

§Errors

ReadError if the path escapes the root, is absolute, or holds something that is not text. Absence is not an error — a rule asking whether a config is present should not have to catch to find out.

Source

pub fn exists(&self, path: &str) -> Result<bool, ReadError>

Whether a file is there.

A file that exists but is not text still exists — this answers the question asked, where returning false would claim something untrue about the filesystem.

§Errors

ReadError if the path escapes the root or is absolute.

Source

pub fn dependencies(&self) -> Vec<TrackedRead>

Everything read so far, in path order.

Source

pub fn clear(&self)

Forget everything, for an embedder reusing one access across several files.

The engine does not use this — it builds an access per file, so there is nothing to forget. Kept because reuse is a reasonable thing for an embedder to want, and a half-populated access is not.

Trait Implementations§

Source§

impl Debug for FileAccess

Source§

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

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> ParallelSend for T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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, <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.