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) -> Self

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) -> Self

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 hash_of(&self, path: &str) -> Result<Option<ContentHash>, ReadError>

The hash of a file’s bytes, or None if nothing readable is there.

Goes through the same resolution every other read does, so it is confined the same way and recorded as a dependency exactly as Self::read would be — a caller that asked only for the hash still depended on the file, and an entry that did not list it would validate after the file changed.

What it saves is the text: a caller holding a parse of these bytes wants to know whether the parse is still the right one, and that is a comparison against a digest the memo already computed. Returning the String for it would clone a whole declaration file per importer to answer a question about thirty-two bytes.

None covers absence and a file that is there but is not text. A binary file is hashed — the dependency it becomes carries that digest — but it cannot be parsed, and this method answers a caller asking whether it holds the current parse of these bytes. For a file no parse can be made of, the answer is no however the bytes hash.

§Errors

ReadError if the path escapes the root or is absolute — the same refusals Self::read makes, for the same reasons.

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

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

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.