- Core crate: Minimal shell-out implementation - Advanced crate: Pluggable backends and enhanced features - Main crate: Re-exports core + optional advanced features - Feature flags: Users choose complexity level - Examples: Working demonstrations of both approaches - Documentation: Clear README explaining the structure Implements the refined two-crate approach with workspace + feature flags.
54 lines
1.9 KiB
Rust
54 lines
1.9 KiB
Rust
//! Basic usage example for the APT-DNF Bridge crate.
|
|
|
|
use apt_dnf_bridge::{Package, Repository, Transaction};
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
println!("APT-DNF Bridge - Basic Usage Example");
|
|
println!("=================================");
|
|
|
|
// Create a package
|
|
let vim = Package::new("vim", "2:8.1.2269-1ubuntu5.14", "amd64");
|
|
println!("Created package: {}", vim.spec());
|
|
|
|
// Create a transaction with logging enabled
|
|
let mut tx = Transaction::new_with_logging();
|
|
println!("Created empty transaction with logging enabled");
|
|
|
|
// Add operations to the transaction
|
|
tx.add_install(vim.clone()).await?;
|
|
println!("Added install operation for: {}", vim.name);
|
|
|
|
// Check transaction status
|
|
println!("Transaction has {} operations", tx.len());
|
|
println!("Transaction is empty: {}", tx.is_empty());
|
|
|
|
// Note: In a real scenario, you would call:
|
|
// tx.resolve().await?; // Resolve dependencies
|
|
// tx.commit().await?; // Commit the transaction
|
|
|
|
// But for this example, we'll just show the structure
|
|
println!("Transaction operations:");
|
|
for (i, op) in tx.operations().iter().enumerate() {
|
|
match op {
|
|
apt_dnf_bridge::Operation::Install(pkg) => {
|
|
println!(" {}: Install {}", i + 1, pkg.name);
|
|
}
|
|
apt_dnf_bridge::Operation::Remove(pkg) => {
|
|
println!(" {}: Remove {}", i + 1, pkg.name);
|
|
}
|
|
apt_dnf_bridge::Operation::Upgrade(pkg) => {
|
|
println!(" {}: Upgrade {}", i + 1, pkg.name);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Create a repository
|
|
let mut repo = Repository::new("debian", "http://deb.debian.org/debian")?;
|
|
repo.add_component("main");
|
|
repo.add_component("contrib");
|
|
println!("Created repository: {} at {}", repo.name, repo.url);
|
|
println!("Components: {:?}", repo.components);
|
|
|
|
Ok(())
|
|
}
|