- 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.
60 lines
2 KiB
Rust
60 lines
2 KiB
Rust
//! Package querying example for the APT-DNF Bridge crate.
|
|
|
|
use apt_dnf_bridge::PackageDatabase;
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
println!("APT-DNF Bridge - Package Query Example");
|
|
println!("===================================");
|
|
|
|
let mut db = PackageDatabase::new_with_logging();
|
|
|
|
// Search for packages
|
|
println!("Searching for packages matching 'vim'...");
|
|
let packages = db.find_packages("vim").await?;
|
|
println!("Found {} packages:", packages.len());
|
|
|
|
for (i, pkg) in packages.iter().take(5).enumerate() {
|
|
println!(" {}: {}", i + 1, pkg.name);
|
|
}
|
|
|
|
if packages.len() > 5 {
|
|
println!(" ... and {} more", packages.len() - 5);
|
|
}
|
|
|
|
// Get detailed information about a specific package
|
|
println!("\nGetting detailed info for 'vim'...");
|
|
if let Some(pkg_info) = db.get_package_info("vim").await? {
|
|
println!("Package: {}", pkg_info.name);
|
|
println!("Version: {}", pkg_info.version);
|
|
println!("Architecture: {}", pkg_info.architecture);
|
|
if let Some(desc) = &pkg_info.description {
|
|
println!("Description: {}", desc);
|
|
}
|
|
if let Some(size) = pkg_info.size {
|
|
println!("Size: {} bytes", size);
|
|
}
|
|
} else {
|
|
println!("Package 'vim' not found");
|
|
}
|
|
|
|
// Check if a package is installed
|
|
println!("\nChecking if 'vim' is installed...");
|
|
let is_installed = db.is_installed("vim").await?;
|
|
println!("vim is installed: {}", is_installed);
|
|
|
|
// List some installed packages
|
|
println!("\nListing some installed packages...");
|
|
let installed = db.get_installed_packages().await?;
|
|
println!("Found {} installed packages", installed.len());
|
|
|
|
for (i, pkg) in installed.iter().take(10).enumerate() {
|
|
println!(" {}: {} {}", i + 1, pkg.name, pkg.version);
|
|
}
|
|
|
|
if installed.len() > 10 {
|
|
println!(" ... and {} more", installed.len() - 10);
|
|
}
|
|
|
|
Ok(())
|
|
}
|