Skip to main content

MarkerResolver

Struct MarkerResolver 

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

The built-in ProjectResolver: walk up for a marker, else pwd.

§Examples

use lattice_core::{MarkerResolver, ProjectKind, ProjectResolver};

let root = std::env::temp_dir().join(format!("lattice-doc-project-{}", std::process::id()));
std::fs::create_dir_all(root.join("src"))?;
std::fs::write(root.join("Cargo.toml"), "")?;

let resolver = MarkerResolver::with_default_markers(std::env::temp_dir());
// A file that does not exist yet still resolves, via its parent.
let project = resolver.for_path(&root.join("src/main.rs"));
assert_eq!(project.root, root);
assert_eq!(project.kind, ProjectKind::Marker("Cargo.toml".into()));
assert!(project.is_rooted());

Implementations§

Source§

impl MarkerResolver

Source

pub fn new(markers: Vec<String>, pwd: PathBuf) -> Self

Build a resolver over markers, falling back to pwd.

The marker list arrives as a parameter rather than being read from a typed option here because lattice-config depends on this crate — core cannot name the option type. The host reads project.root-markers and passes it in, which is also what keeps this crate free of a config dependency for one Vec<String>.

Source

pub fn with_default_markers(pwd: PathBuf) -> Self

The default marker set (DEFAULT_ROOT_MARKERS) over pwd.

Trait Implementations§

Source§

impl Debug for MarkerResolver

Source§

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

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

impl ProjectResolver for MarkerResolver

Source§

fn for_path(&self, path: &Path) -> Project

The project containing path, which may be a file or a directory. Total — see the module docs.
Source§

fn set_pwd(&self, pwd: PathBuf)

Re-point the working directory the ProjectKind::Pwd fallback uses. Called on :cd. Drops the cache, because entries that fell back to the old pwd are now wrong.
Source§

fn set_markers(&self, markers: Vec<String>)

Replace the marker set. Called when project.root-markers changes, and at boot once config has been applied. Read more
Source§

fn invalidate(&self)

Drop every cached answer — :project-refresh, after a git init mid-session. The cache is an optimisation and never a source of truth, so this changes latency and nothing else.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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.