pub(crate) mod encoding;
pub mod version;
pub use self::version::ResolveVersion;
use self::encoding::EncodableLockfile;
use crate::{
error::{Error, Result},
metadata::Metadata,
package::Package,
patch::Patch,
};
use std::{fs, path::Path, str::FromStr, string::ToString};
#[cfg(feature = "dependency-tree")]
use crate::dependency::Tree;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct Lockfile {
pub version: ResolveVersion,
pub packages: Vec<Package>,
pub root: Option<Package>,
pub metadata: Metadata,
pub patch: Patch,
}
impl Lockfile {
pub fn load(path: impl AsRef<Path>) -> Result<Self> {
fs::read_to_string(path.as_ref())?.parse()
}
#[cfg(feature = "dependency-tree")]
pub fn dependency_tree(&self) -> Result<Tree> {
Tree::new(self)
}
}
impl FromStr for Lockfile {
type Err = Error;
fn from_str(toml_string: &str) -> Result<Self> {
Ok(toml::from_str(toml_string)?)
}
}
impl ToString for Lockfile {
fn to_string(&self) -> String {
EncodableLockfile::from(self).to_string()
}
}