pub trait Key<'a, T: Deserialize<'a> + Eq + Hash + Serialize> {
// Required method
fn key(&self) -> T;
}Expand description
The key to a keyed resource.
Implement this on the type of the value of a map to extract the key from it.
§Examples
If you have a User resource, then it’ll have an ID of some sort. For example, return the integer ID of a User struct:
use serde_derive::{Deserialize, Serialize};
use serde_mappable_seq::Key;
struct User {
id: u64,
email: String,
name: String,
}
impl Key<'_, u64> for User {
fn key(&self) -> u64 {
self.id
}
}