arch_toolkit/aur/traits.rs
1//! Traits for AUR operations, enabling testability via mock implementations.
2
3use crate::error::Result;
4use crate::types::{AurComment, AurPackage, AurPackageDetails};
5use async_trait::async_trait;
6
7/// What: Trait for AUR operations, enabling testability via mock implementations.
8///
9/// Inputs: None (trait definition)
10///
11/// Output: Trait that defines the interface for AUR operations
12///
13/// Details:
14/// - Defines the core AUR operations: search, info, comments, and pkgbuild
15/// - Allows users to create mock implementations for unit testing
16/// - The `Aur<'a>` struct implements this trait for real AUR operations
17/// - Mock implementations can be used to test code without hitting real APIs
18#[async_trait]
19pub trait AurApi: Send + Sync {
20 /// What: Search for packages in the AUR by name.
21 ///
22 /// Inputs:
23 /// - `query`: Search query string
24 ///
25 /// Output:
26 /// - `Result<Vec<AurPackage>>` containing search results, or an error
27 ///
28 /// Details:
29 /// - Searches the AUR for packages matching the query
30 /// - Returns empty vector if no results found (not an error)
31 async fn search(&self, query: &str) -> Result<Vec<AurPackage>>;
32
33 /// What: Fetch detailed information for one or more AUR packages.
34 ///
35 /// Inputs:
36 /// - `names`: Slice of package names to fetch info for
37 ///
38 /// Output:
39 /// - `Result<Vec<AurPackageDetails>>` containing package details, or an error
40 ///
41 /// Details:
42 /// - Fetches comprehensive information for the specified packages
43 /// - Returns empty vector if no packages found (not an error)
44 async fn info(&self, names: &[&str]) -> Result<Vec<AurPackageDetails>>;
45
46 /// What: Fetch AUR package comments.
47 ///
48 /// Inputs:
49 /// - `pkgname`: Package name to fetch comments for
50 ///
51 /// Output:
52 /// - `Result<Vec<AurComment>>` with parsed comments, or an error
53 ///
54 /// Details:
55 /// - Fetches comments from the AUR package page
56 /// - Comments are sorted by date (latest first)
57 async fn comments(&self, pkgname: &str) -> Result<Vec<AurComment>>;
58
59 /// What: Fetch PKGBUILD content for an AUR package.
60 ///
61 /// Inputs:
62 /// - `package`: Package name to fetch PKGBUILD for
63 ///
64 /// Output:
65 /// - `Result<String>` with PKGBUILD text, or an error
66 ///
67 /// Details:
68 /// - Fetches the raw PKGBUILD content for the specified package
69 async fn pkgbuild(&self, package: &str) -> Result<String>;
70}