Skip to main content

crates_docs/tools/docs/
mod.rs

1//! Document query tools module
2
3pub mod cache;
4pub mod lookup;
5pub mod search;
6
7use crate::cache::Cache;
8use std::sync::Arc;
9
10/// Document service
11pub struct DocService {
12    client: reqwest::Client,
13    cache: Arc<dyn Cache>,
14    doc_cache: cache::DocCache,
15}
16
17impl DocService {
18    /// Create a new document service
19    pub fn new(cache: Arc<dyn Cache>) -> Self {
20        let doc_cache = cache::DocCache::new(cache.clone());
21        Self {
22            client: reqwest::Client::builder()
23                .user_agent(format!("CratesDocsMCP/{}", crate::VERSION))
24                .timeout(std::time::Duration::from_secs(30))
25                .build()
26                .expect("Failed to create HTTP client"),
27            cache,
28            doc_cache,
29        }
30    }
31
32    /// Get HTTP client
33    #[must_use]
34    pub fn client(&self) -> &reqwest::Client {
35        &self.client
36    }
37
38    /// Get cache
39    #[must_use]
40    pub fn cache(&self) -> &Arc<dyn Cache> {
41        &self.cache
42    }
43
44    /// Get document cache
45    #[must_use]
46    pub fn doc_cache(&self) -> &cache::DocCache {
47        &self.doc_cache
48    }
49}
50
51impl Default for DocService {
52    fn default() -> Self {
53        let cache = Arc::new(crate::cache::memory::MemoryCache::new(1000));
54        Self::new(cache)
55    }
56}
57
58/// 重新导出工具
59pub use lookup::LookupCrateTool;
60pub use lookup::LookupItemTool;
61pub use search::SearchCratesTool;