DeriveKey

Trait DeriveKey 

Source
pub trait DeriveKey<V>:
    Send
    + Sync
    + 'static {
    type Key: Serialize + DeserializeOwned + Ord + Clone + Send;

    // Required method
    fn derive(value: &V) -> Self::Key;
}
Expand description

Describes how to derive a secondary index key from a record value.

Implement this trait on a marker struct, one per secondary index. For composite indices in the future, set Key to a tuple type — no change to this trait is required.

§Example

use serde::{Serialize, Deserialize};
use highlandcows_isam::DeriveKey;

#[derive(Serialize, Deserialize, Clone)]
struct User { name: String, city: String }

struct CityIndex;
impl DeriveKey<User> for CityIndex {
    type Key = String;
    fn derive(value: &User) -> String { value.city.clone() }
}

Required Associated Types§

Source

type Key: Serialize + DeserializeOwned + Ord + Clone + Send

The type of the derived secondary key.

Required Methods§

Source

fn derive(value: &V) -> Self::Key

Derive the secondary key from a value.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§