Skip to main content

LockFileProvider

Trait LockFileProvider 

Source
pub trait LockFileProvider: Send + Sync {
    // Required methods
    fn locate_lockfile(&self, manifest_uri: &Url) -> Option<PathBuf>;
    fn parse_lockfile<'a>(
        &'a self,
        lockfile_path: &'a Path,
    ) -> Pin<Box<dyn Future<Output = Result<ResolvedPackages>> + Send + 'a>>;
}
Expand description

Lock file provider trait for ecosystem-specific implementations.

Implementations parse lock files for a specific package ecosystem (Cargo.lock, package-lock.json, etc.) and extract resolved versions.

§Examples

use deps_core::lockfile::{LockFileProvider, ResolvedPackages};
use std::path::{Path, PathBuf};
use url::Url;

struct MyLockParser;

impl LockFileProvider for MyLockParser {
    fn locate_lockfile(&self, manifest_uri: &Url) -> Option<PathBuf> {
        let manifest_path = manifest_uri.to_file_path().ok()?;
        let lock_path = manifest_path.with_file_name("my.lock");
        lock_path.exists().then_some(lock_path)
    }

    fn parse_lockfile<'a>(&'a self, lockfile_path: &'a Path) -> std::pin::Pin<Box<dyn std::future::Future<Output = deps_core::error::Result<ResolvedPackages>> + Send + 'a>> {
        Box::pin(async move {
            // Parse lock file format and extract packages
            Ok(ResolvedPackages::new())
        })
    }
}

Required Methods§

Source

fn locate_lockfile(&self, manifest_uri: &Url) -> Option<PathBuf>

Locates the lock file for a given manifest URI.

Returns None if:

  • Lock file doesn’t exist
  • Manifest path cannot be determined from URI
  • Workspace root search fails
§Arguments
  • manifest_uri - URI of the manifest file (Cargo.toml, package.json, etc.)
§Returns

Path to lock file if found

Source

fn parse_lockfile<'a>( &'a self, lockfile_path: &'a Path, ) -> Pin<Box<dyn Future<Output = Result<ResolvedPackages>> + Send + 'a>>

Parses a lock file and extracts resolved packages.

§Arguments
  • lockfile_path - Path to the lock file
§Returns

ResolvedPackages on success, error if parse fails

§Errors

Returns an error if:

  • File cannot be read
  • File format is invalid
  • Required fields are missing

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§