Skip to main content

FileResolver

Struct FileResolver 

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

Resolve references against a filesystem.

By default that is the real filesystem, with references resolved to absolute paths. Give it a crate::MapFs and it touches no disk at all; give it a root and no reference can name anything outside that directory, however many .. segments it carries.

Implementations§

Source§

impl FileResolver

Source

pub fn new() -> Self

A resolver over the real filesystem.

Source

pub fn with_pathfinder( self, pathfinder: impl Fn(&str) -> String + Send + Sync + 'static, ) -> Self

Transform each raw reference before resolving it.

Source

pub fn with_preload(self, preload: BTreeMap<String, String>) -> Self

Serve these paths from memory before touching the filesystem. The map crate::preload_files returns goes here.

Source

pub fn with_fs(self, filesystem: impl SourceFs + 'static) -> Self

Read from filesystem instead of the one the plugin options name.

Source

pub fn with_shared_fs(self, filesystem: SharedFs) -> Self

Read from an already shared filesystem handle.

Source

pub fn with_root(self, root: impl Into<String>) -> Self

Confine every candidate path to root.

The root and every candidate are resolved through the filesystem first (SourceFs::real_path), then compared by whole segment. So neither ../../etc/passwd nor a sibling directory whose name merely starts with the root’s can be reached, a relative root names the same directory a relative candidate does, and a symbolic link inside the root is judged by where it POINTS rather than by where it sits. A link that resolves to nothing at all is refused outright, since its target could be created before a read reaches it.

What this cannot do is stop a link created in the instant between the check and the read: the check answers for the filesystem as it was. A root whose contents another process can write needs a filesystem that enforces the boundary, not a resolver.

Neither the canonical TypeScript nor the Go port has this: they resolve wherever the reference points. It is additive, so a resolver without a root behaves exactly as they do.

Trait Implementations§

Source§

impl Clone for FileResolver

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FileResolver

Source§

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

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

impl Default for FileResolver

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Resolver for FileResolver

Source§

fn resolve( &self, reference: Option<&str>, input: &ResolverInput<'_>, ) -> Resolution

Resolve reference to a Resolution. A reference that names nothing returns Resolution::not_found; raising the error is the plugin’s job, not the resolver’s.

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.