crates_docs/tools/docs/
mod.rs1pub mod cache;
4pub mod html;
5pub mod lookup_crate;
6pub mod lookup_item;
7pub mod search;
8
9use crate::cache::Cache;
10use std::sync::Arc;
11
12pub struct DocService {
14 client: reqwest::Client,
15 cache: Arc<dyn Cache>,
16 doc_cache: cache::DocCache,
17}
18
19impl DocService {
20 pub fn new(cache: Arc<dyn Cache>) -> Self {
22 let doc_cache = cache::DocCache::new(cache.clone());
23 Self {
24 client: reqwest::Client::builder()
25 .user_agent(format!("CratesDocsMCP/{}", crate::VERSION))
26 .timeout(std::time::Duration::from_secs(30))
27 .build()
28 .expect("Failed to create HTTP client"),
29 cache,
30 doc_cache,
31 }
32 }
33
34 #[must_use]
36 pub fn client(&self) -> &reqwest::Client {
37 &self.client
38 }
39
40 #[must_use]
42 pub fn cache(&self) -> &Arc<dyn Cache> {
43 &self.cache
44 }
45
46 #[must_use]
48 pub fn doc_cache(&self) -> &cache::DocCache {
49 &self.doc_cache
50 }
51}
52
53impl Default for DocService {
54 fn default() -> Self {
55 let cache = Arc::new(crate::cache::memory::MemoryCache::new(1000));
56 Self::new(cache)
57 }
58}
59
60pub use lookup_crate::LookupCrateTool;
62pub use lookup_item::LookupItemTool;
63pub use search::SearchCratesTool;