Skip to main content

rig_core/operation/
cached_content.rs

1//! Explicit context-cache operations. Listing pages are one call each; the
2//! model's `list` follows them.
3//!
4//! ```
5//! use rig_core::operation::ContextCache;
6//! use rig_core::wire::Operation;
7//!
8//! fn caches<Op: Operation>() {}
9//! caches::<ContextCache>();
10//! ```
11
12use crate::error::ProviderError;
13use crate::providers::gemini::cached_content::{CachedContentReply, CachedContentRequest};
14use crate::wire::{Call, Fold, Free, Operation, Reply};
15
16/// Creates, reads, lists, updates expiry, or deletes explicit context caches.
17/// Requests use [`CachedContentRequest`]; a listing reads one page per call.
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub struct ContextCache;
20
21impl Operation for ContextCache {
22    type Request = CachedContentRequest;
23    type Event = std::convert::Infallible;
24    type End = CachedContentReply;
25    type Response = CachedContentReply;
26    type Fold = CachedContentFold;
27    type Emit = Free;
28
29    fn fold(_request: &Self::Request, _call: &mut Call<'_>) -> Self::Fold {
30        CachedContentFold
31    }
32}
33
34/// The reply's one answer: a reply with no body at all ends as
35/// [`CachedContentReply::Acknowledged`]. Finishing never fails.
36#[derive(Default)]
37pub struct CachedContentFold;
38
39impl Fold<ContextCache> for CachedContentFold {
40    fn absorb(&mut self, event: &std::convert::Infallible) -> Result<(), ProviderError> {
41        match *event {}
42    }
43
44    fn finish(
45        self,
46        end: CachedContentReply,
47        _reply: Reply,
48    ) -> Result<CachedContentReply, ProviderError> {
49        Ok(end)
50    }
51}