//! Collection of cargo workspace data models. //! //! To start parsing types, construct a `CargoWorkspace`, which you //! can then modify with commands found in [`ops`](../ops/index.html). mod cargo; pub use cargo::{CargoCrate, CargoWorkspace}; mod _crate; pub use _crate::Crate; mod publish; pub use publish::{MutationSet, PubMutation}; mod graph; pub use graph::DepGraph; pub type CrateId = usize; use crate::{ops::Op, query::Query}; use std::path::PathBuf; /// A fully parsed workspace pub struct Workspace { pub root: PathBuf, dgraph: DepGraph, } impl Workspace { /// Create a parsed workspace by passing in the stage1 parse data pub fn process(cws: CargoWorkspace) -> Self { let CargoWorkspace { root, crates } = cws; let mut dgraph = DepGraph::new(); crates.into_iter().for_each(|cc| dgraph.add_crate(cc)); dgraph.finalise(); Self { root, dgraph } } /// Execute a query on this workspace to find crate IDs pub fn query(&self, q: Query) -> Vec<CrateId> { q.execute(&self.dgraph) } /// Execute an operation on a set of crates this in workspace pub fn execute(&mut self, op: Op, target: Vec<CrateId>) { op.execute(target, self.root.clone(), &mut self.dgraph) } }