1#![doc = include_str!("../README.md")]
2#![warn(missing_docs)]
3
4mod args;
5mod cache;
6mod extractor;
7mod upstream;
8
9pub use args::{Arg, Args, Skipped};
10
11#[diagnostic::on_unimplemented(
17 message = "`{Self}` cannot be used as a skipped field in `#[derive(CacheableResponse)]`",
18 note = "skipped fields are not stored in cache and are reconstructed using `Default::default()` on cache hit",
19 note = "either implement `Default` for `{Self}` or remove the `#[cacheable_response(skip)]` attribute"
20)]
21pub trait SkippedFieldDefault {
22 fn skipped_default() -> Self;
24}
25
26impl<T: Default> SkippedFieldDefault for T {
27 fn skipped_default() -> Self {
28 Self::default()
29 }
30}
31
32#[diagnostic::on_unimplemented(
37 message = "`{Self}` cannot be used as a cached field in `#[derive(CacheableResponse)]`",
38 note = "non-skipped fields are stored in cache and must implement `Clone` for cache storage",
39 note = "either implement `Clone` for `{Self}` or add the `#[cacheable_response(skip)]` attribute"
40)]
41pub trait CachedFieldClone {
42 fn cached_clone(&self) -> Self;
44}
45
46impl<T: Clone> CachedFieldClone for T {
47 fn cached_clone(&self) -> Self {
48 self.clone()
49 }
50}
51pub use cache::{
52 Cache, CacheAccess, CacheBuilder, NoBackend, NoContext, NoPolicy, WithBackend, WithContext,
53 WithPolicy,
54};
55pub use extractor::{FnExtractor, KeyExtract};
56pub use upstream::FnUpstream;
57
58#[cfg(feature = "derive")]
61pub use hitbox_derive::{CacheableRequest, CacheableResponse, KeyExtract, cached};
62
63pub mod prelude {
65 pub use crate::{Arg, Args, Cache, FnExtractor, FnUpstream, KeyExtract, Skipped};
66
67 #[cfg(feature = "derive")]
69 pub use hitbox_derive::{CacheableRequest, CacheableResponse, cached};
70
71 pub use hitbox::KeyPart;
73 pub use hitbox::policy::PolicyConfig;
74 pub use hitbox::{CacheContext, CacheStatus, ResponseSource};
75}