pub trait WorkspaceDiscovery {
// Required methods
fn discover(&self, root: &Path) -> Result<Workspace>;
fn find_members(&self, root: &Path) -> Result<Vec<WorkspaceMember>>;
fn validate_member(&self, member_path: &Path) -> Result<bool>;
}Expand description
Discovers workspace configuration from a root directory.
Implementations of this trait handle the package manager-specific logic for finding workspace members, validating their structure, and building a complete workspace representation.
§Example
use cuenv_workspaces::{WorkspaceDiscovery, Workspace};
use std::path::Path;
struct CargoDiscovery;
impl WorkspaceDiscovery for CargoDiscovery {
fn discover(&self, root: &Path) -> Result<Workspace> {
// Find Cargo.toml, parse workspace members, etc.
todo!()
}
fn find_members(&self, root: &Path) -> Result<Vec<WorkspaceMember>> {
// Use glob patterns from Cargo.toml to find member crates
todo!()
}
fn validate_member(&self, member_path: &Path) -> Result<bool> {
// Check for Cargo.toml in member directory
todo!()
}
}Required Methods§
Sourcefn discover(&self, root: &Path) -> Result<Workspace>
fn discover(&self, root: &Path) -> Result<Workspace>
Discovers the complete workspace configuration from a root directory.
This method should:
- Locate the workspace configuration file (e.g.,
package.json,Cargo.toml) - Parse workspace member patterns
- Find all workspace members
- Validate each member
- Build and return a complete
Workspace
§Errors
Returns an error if:
- The workspace configuration file is not found
- The configuration is invalid
- Members cannot be discovered or validated
Sourcefn find_members(&self, root: &Path) -> Result<Vec<WorkspaceMember>>
fn find_members(&self, root: &Path) -> Result<Vec<WorkspaceMember>>
Finds all workspace members using glob patterns or other discovery mechanisms.
This method should scan the workspace root for members based on the
package manager’s conventions (e.g., packages/* for npm workspaces,
members = [...] for Cargo).
§Errors
Returns an error if member discovery fails (e.g., invalid glob patterns, I/O errors).
Sourcefn validate_member(&self, member_path: &Path) -> Result<bool>
fn validate_member(&self, member_path: &Path) -> Result<bool>
Validates that a potential workspace member has the required manifest files.
For example:
- npm/Bun/pnpm/Yarn: Check for
package.json - Cargo: Check for
Cargo.toml
§Errors
Returns an error if validation cannot be performed (e.g., I/O errors).
Returns Ok(false) if the member is invalid, Ok(true) if valid.