pub struct Context {
pub project_root: PathBuf,
pub matched: Vec<String>,
}Expand description
宿主传给插件的上下文。只读。
Fields§
§project_root: PathBuf项目根目录。
仅供拼日志 / 错误信息用 —— 不许拿它去读文件,见 crate 文档里的约束表。
之所以还是传进来:插件报错时说一句“请在 <path> 下执行“是有用的。
matched: Vec<String>本次检测命中的文件,相对 project_root。
来源:宿主在检测阶段本来就要 stat 这个插件 manifest 里声明的那些文件, 命中的就带下来。所以插件拿到这些信息是零额外成本的。
这是插件了解“项目长什么样“的唯一渠道。 例:yarn 插件靠
Context::has_matched(".yarnrc.yml") 区分 classic 与 berry,
全过程不读一个文件。
Implementations§
Trait Implementations§
impl Eq for Context
impl StructuralPartialEq for Context
Auto Trait Implementations§
impl Freeze for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnsafeUnpin for Context
impl UnwindSafe for Context
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more