1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
use super::types::Type; use crate::util::generate_uuid_v1; use std::hash::{Hash, Hasher}; use uuid::Uuid; /// A vertex. /// /// Vertices are how you would represent nouns in the datastore. An example /// might be a user, or a movie. All vertices have a unique ID and a type. #[derive(Clone, Debug)] pub struct Vertex { /// The id of the vertex. pub id: Uuid, /// The type of the vertex. pub t: Type, } impl Vertex { /// Creates a new vertex with an ID generated via UUIDv1. These vertex IDs /// are trivially guessable and consequently less secure, but likely index /// better depending on the datastore. This method is suggested unless you /// need vertex IDs to not be trivially guessable. /// /// # Arguments /// /// * `t` - The type of the vertex. pub fn new(t: Type) -> Self { Self::with_id(generate_uuid_v1(), t) } /// Creates a new vertex with a specified id. /// /// # Arguments /// /// * `id` - The id of the vertex. /// * `t` - The type of the vertex. pub fn with_id(id: Uuid, t: Type) -> Self { Vertex { id, t } } } impl PartialEq for Vertex { fn eq(&self, other: &Vertex) -> bool { self.id == other.id } } impl Hash for Vertex { fn hash<H: Hasher>(&self, state: &mut H) { self.id.hash(state); } } impl Eq for Vertex {}