pub trait KeyExtract {
// Required method
fn extract(&self) -> Vec<KeyPart>;
}Expand description
Trait for types that can contribute to a cache key.
Implement this trait for your custom types to control how they appear in cache keys. Blanket implementations are provided for common primitive types.
§Example
ⓘ
use hitbox_fn::KeyExtract;
use hitbox_core::KeyPart;
struct UserId(u64);
impl KeyExtract for UserId {
fn extract(&self) -> Vec<KeyPart> {
vec![KeyPart::new("user_id", Some(self.0.to_string()))]
}
}§Automatic composition
When all elements of a tuple implement KeyExtract, the tuple automatically
implements it too by concatenating all key parts:
ⓘ
// If UserId and TenantId both implement KeyExtract,
// then Args<(UserId, TenantId)> automatically implements KeyExtract
let args = Args((UserId(42), TenantId("acme".into())));
let parts = args.extract();
// parts = [KeyPart("user_id", "42"), KeyPart("tenant", "acme")]