pub trait PackageManager: Send + Sync {
// Required methods
fn name(&self) -> &'static str;
fn detect(&self, project_path: &Path) -> bool;
fn bloat_dirs(&self, project_path: &Path) -> Vec<BloatDir>;
fn enforce_lockfile(
&self,
project_path: &Path,
policy: EnforcePolicy,
) -> Result<()>;
fn restore(&self, project_path: &Path) -> Result<()>;
// Provided method
fn lockfiles(&self) -> &'static [&'static str] { ... }
}Expand description
The core trait that every package manager adapter must implement.
Each adapter is responsible for:
- Detecting whether it applies to a given project directory
- Listing the bloat directories it manages
- Enforcing lockfile consistency before deletion
- Restoring dependencies from lockfiles
Required Methods§
Sourcefn name(&self) -> &'static str
fn name(&self) -> &'static str
Human-readable name for this adapter (e.g., “npm”, “pnpm”, “uv”).
Sourcefn detect(&self, project_path: &Path) -> bool
fn detect(&self, project_path: &Path) -> bool
Check if this adapter applies to the given project directory.
Typically checks for the presence of a specific lockfile or config file.
Sourcefn bloat_dirs(&self, project_path: &Path) -> Vec<BloatDir>
fn bloat_dirs(&self, project_path: &Path) -> Vec<BloatDir>
List all bloat directories this adapter manages in the given project.
Only returns directories that actually exist on disk.
Sourcefn enforce_lockfile(
&self,
project_path: &Path,
policy: EnforcePolicy,
) -> Result<()>
fn enforce_lockfile( &self, project_path: &Path, policy: EnforcePolicy, ) -> Result<()>
Prove the lockfile can rebuild what is about to be deleted.
This is a safety-critical method. It MUST succeed before any bloat directory is deleted. If this fails, deletion for this adapter is aborted.
See EnforcePolicy for the one rule every adapter follows.
Provided Methods§
Sourcefn lockfiles(&self) -> &'static [&'static str]
fn lockfiles(&self) -> &'static [&'static str]
The file this manager rebuilds its bloat directory from.
Two callers. Conflict resolution breaks ties between managers that share a bloat
directory — npm, pnpm, yarn and bun all own the same node_modules — by comparing
these files’ timestamps. devp doctor names them, because a missing one is the
most common reason a project is not pruneable.
More than one entry means the manager accepts any of them (bun’s binary and text lockfiles). An empty slice means the manager has no single file to point at.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".