pub trait ValueBounds: Serialize + for<'a> Deserialize<'a> + Clone + Send + Sync + 'static { }
Expand description

ValueLoader::Value cached by groupcache must satisfy ValueBounds:

  • serializable/deserializable: because they’re sent over the network,
  • cloneable: because value is loaded once and then multiplexed to all callers via clone,
  • Send + Sync + ’static: because they’re shared across potentially many threads.

Typical data structs should automatically conform to this trait.

    use serde::{Deserialize, Serialize};
    #[derive(Clone, Deserialize, Serialize)]
    struct DatabaseEntity {
        id: String,
        value: String,
    }

For small datastructures plain struct should suffice but if cached ValueLoader::Value was large enough it might be worth it to wrap it inside Arc so that cached values are are stored in memory only once and reference the same piece of data.

    use std::sync::Arc;
    use serde::{Deserialize, Serialize};

    #[derive(Clone, Deserialize, Serialize)]
    struct Wrapped (Arc<Entity>);

    #[derive(Clone, Deserialize, Serialize)]
    struct Entity {
        id: String,
        value: String,
    }

Object Safety§

This trait is not object safe.

Implementors§

source§

impl<T: Serialize + for<'a> Deserialize<'a> + Clone + Send + Sync + 'static> ValueBounds for T

Automatically implement ValueBounds for types that satisfy the trait.