Skip to main content

WorkspaceRoots

Struct WorkspaceRoots 

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

The canonical workspace roots plus the lexical aliases they may be named by.

A path is admitted by WorkspaceRoots::validate only if it passes the lexical pre-check against the canonical roots and their aliases (configured form, logical $PWD) and its physical, canonical form lies under a canonical root; the aliases only widen the pre-check.

Cheap to clone (both lists are shared). Fields are private so every instance upholds the invariants: aliases are absolute, simplified, lexically normalized and distinct from the canonical roots.

Implementations§

Source§

impl WorkspaceRoots

Source

pub fn from_configured(roots: &[ConfiguredRoot]) -> Result<Self, Error>

Builds the root set for the workspace.roots of a configuration.

Relative roots are resolved against the process working directory and must exist; an empty list means the working directory itself. Absolute roots that cannot be canonicalized (for example a directory created after startup) fall back to their longest existing prefix. The configured spelling, the working-directory spelling and the logical $PWD spelling are kept as aliases, but only when they verifiably resolve to the same root, so a client naming a root the way it was configured (for example a /var temp dir that canonicalizes to /private/var) is still admitted.

The working directory is read only when a root needs it, so a fully-absolute list does not fail startup over an unreadable cwd.

§Errors

Returns Error::Config for a relative root that cannot be canonicalized and Error::Io when the working directory is needed but unreadable.

§Examples
use mcpls_core::bridge::WorkspaceRoots;
use mcpls_core::config::ConfiguredRoot;

let roots = WorkspaceRoots::from_configured(&[ConfiguredRoot::new(std::env::temp_dir())?])?;
assert!(!roots.is_empty());
Source

pub async fn validate(&self, path: &ClientPath) -> Result<WorkspacePath, Error>

Validates a client path against the roots, canonicalizing it on the blocking pool so a slow filesystem cannot stall a runtime worker.

See Self::validate_blocking for the checks and errors.

§Errors

As Self::validate_blocking, plus Error::TaskFailed when the blocking task panics.

Source

pub fn validate_blocking( &self, path: &ClientPath, ) -> Result<WorkspacePath, Error>

Validates a client path against the roots on the calling thread.

The lexical check (absolute, ./.. resolved, against the canonical roots and their aliases) is only a pre-filter: it rejects an out-of-workspace path without touching the filesystem and can only reject, never accept. The decision that counts uses the physical path: the original path is canonicalized (so .. after a symlink is resolved against the real directory) and that canonical form must lie under a canonical root. The returned path is the canonical one.

Touches the filesystem; async callers use Self::validate.

§Errors

Returns Error::NoWorkspaceRoots if no root is configured – fails closed rather than allowing unrestricted access – and Error::PathOutsideWorkspace if the path is outside every root. When the lexical check admitted the path but it cannot be canonicalized, Error::FileIo is returned (for example it does not exist), or Error::MalformedPath when the path itself is malformed (it runs through a regular file, or has an invalid or over-long name).

Source

pub fn canonical(&self) -> &[PathBuf]

The canonical roots, in configuration order.

Source

pub fn is_empty(&self) -> bool

Whether no root is configured (path validation then fails closed).

Trait Implementations§

Source§

impl Clone for WorkspaceRoots

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 WorkspaceRoots

Source§

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

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

impl Default for WorkspaceRoots

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

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

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

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

impl<T> WithSubscriber for T

Source§

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

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

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