---
source: graph-api-derive/src/render.rs
expression: formatted
---
#[derive(PartialEq, Eq, Clone, Copy, Hash, Debug)]
pub enum VertexLabel {
Person,
Project,
Rust,
}
impl graph_api_lib::Label for VertexLabel {
type Index = VertexIndex;
fn variants() -> &'static [VertexLabel] {
static VARIANTS: [VertexLabel; 3usize] = [
VertexLabel::Person,
VertexLabel::Project,
VertexLabel::Rust,
];
&VARIANTS
}
fn indexes(&self) -> &'static [VertexIndex] {
match self {
VertexLabel::Person => {
static INDEXES: [VertexIndex; 5usize] = [
VertexIndex::PersonName,
VertexIndex::PersonAge,
VertexIndex::PersonUniqueId,
VertexIndex::PersonUsername,
VertexIndex::PersonBiography,
];
&INDEXES
}
VertexLabel::Project => {
static INDEXES: [VertexIndex; 0usize] = [];
&INDEXES
}
VertexLabel::Rust => {
static INDEXES: [VertexIndex; 0usize] = [];
&INDEXES
}
}
}
fn ordinal(&self) -> usize {
*self as usize
}
fn name(&self) -> &'static str {
match self {
VertexLabel::Person => stringify!(Person),
VertexLabel::Project => stringify!(Project),
VertexLabel::Rust => stringify!(Rust),
}
}
}
#[derive(PartialEq, Eq, Clone, Copy, Hash, Debug)]
pub enum VertexIndex {
PersonName,
PersonAge,
PersonUniqueId,
PersonUsername,
PersonBiography,
}
impl graph_api_lib::Index for VertexIndex {
fn ty(&self) -> core::any::TypeId {
match self {
VertexIndex::PersonName => core::any::TypeId::of::<String>(),
VertexIndex::PersonAge => core::any::TypeId::of::<u64>(),
VertexIndex::PersonUniqueId => core::any::TypeId::of::<Uuid>(),
VertexIndex::PersonUsername => core::any::TypeId::of::<String>(),
VertexIndex::PersonBiography => core::any::TypeId::of::<String>(),
}
}
fn ordinal(&self) -> usize {
match self {
VertexIndex::PersonName => 0usize,
VertexIndex::PersonAge => 1usize,
VertexIndex::PersonUniqueId => 2usize,
VertexIndex::PersonUsername => 3usize,
VertexIndex::PersonBiography => 4usize,
}
}
fn index_type(&self) -> graph_api_lib::IndexType {
match self {
VertexIndex::PersonName => graph_api_lib::IndexType::Hash,
VertexIndex::PersonAge => graph_api_lib::IndexType::Range,
VertexIndex::PersonUniqueId => graph_api_lib::IndexType::Hash,
VertexIndex::PersonUsername => graph_api_lib::IndexType::Range,
VertexIndex::PersonBiography => graph_api_lib::IndexType::FullText,
}
}
}
impl graph_api_lib::Element for Vertex {
type Label = VertexLabel;
fn label(&self) -> Self::Label {
match self {
Vertex::Person { .. } => VertexLabel::Person,
Vertex::Project(_) => VertexLabel::Project,
Vertex::Rust => VertexLabel::Rust,
}
}
fn value(
&self,
index: &<Self::Label as graph_api_lib::Label>::Index,
) -> Option<graph_api_lib::Value> {
match (self, index) {
(Vertex::Person { name, .. }, VertexIndex::PersonName) => Some((name).into()),
(Vertex::Person { age, .. }, VertexIndex::PersonAge) => Some((age).into()),
(Vertex::Person { unique_id, .. }, VertexIndex::PersonUniqueId) => {
Some((unique_id).into())
}
(Vertex::Person { username, .. }, VertexIndex::PersonUsername) => {
Some((username).into())
}
(Vertex::Person { biography, .. }, VertexIndex::PersonBiography) => {
Some((biography).into())
}
(_, _) => None,
}
}
}
impl Vertex {
pub fn person<'search, Graph>() -> graph_api_lib::VertexSearch<'search, Graph>
where
Graph: graph_api_lib::Graph<Vertex = Vertex>
+ graph_api_lib::SupportsVertexLabelIndex,
{
graph_api_lib::VertexSearch::label(VertexLabel::Person)
}
pub fn project<'search, Graph>() -> graph_api_lib::VertexSearch<'search, Graph>
where
Graph: graph_api_lib::Graph<Vertex = Vertex>
+ graph_api_lib::SupportsVertexLabelIndex,
{
graph_api_lib::VertexSearch::label(VertexLabel::Project)
}
pub fn rust<'search, Graph>() -> graph_api_lib::VertexSearch<'search, Graph>
where
Graph: graph_api_lib::Graph<Vertex = Vertex>
+ graph_api_lib::SupportsVertexLabelIndex,
{
graph_api_lib::VertexSearch::label(VertexLabel::Rust)
}
pub fn person_by_name<'search, Graph>(
value: &'search str,
) -> graph_api_lib::VertexSearch<'search, Graph>
where
Graph: graph_api_lib::Graph<Vertex = Vertex>
+ graph_api_lib::SupportsVertexHashIndex,
{
graph_api_lib::VertexSearch::get(VertexIndex::PersonName, value)
}
pub fn person_by_age<'search, Graph>(
value: u64,
) -> graph_api_lib::VertexSearch<'search, Graph>
where
Graph: graph_api_lib::Graph<Vertex = Vertex>
+ graph_api_lib::SupportsVertexHashIndex,
{
graph_api_lib::VertexSearch::get(VertexIndex::PersonAge, value)
}
pub fn person_by_unique_id<'search, Graph>(
value: Uuid,
) -> graph_api_lib::VertexSearch<'search, Graph>
where
Graph: graph_api_lib::Graph<Vertex = Vertex>
+ graph_api_lib::SupportsVertexHashIndex,
{
graph_api_lib::VertexSearch::get(VertexIndex::PersonUniqueId, value)
}
pub fn person_by_username<'search, Graph>(
value: &'search str,
) -> graph_api_lib::VertexSearch<'search, Graph>
where
Graph: graph_api_lib::Graph<Vertex = Vertex>
+ graph_api_lib::SupportsVertexHashIndex,
{
graph_api_lib::VertexSearch::get(VertexIndex::PersonUsername, value)
}
pub fn person_by_biography<'search, Graph>(
value: &'search str,
) -> graph_api_lib::VertexSearch<'search, Graph>
where
Graph: graph_api_lib::Graph<Vertex = Vertex>
+ graph_api_lib::SupportsVertexFullTextIndex,
{
graph_api_lib::VertexSearch::full_text(VertexIndex::PersonBiography, value)
}
pub fn person_by_age_range<'search, Graph>(
range: std::ops::Range<u64>,
) -> graph_api_lib::VertexSearch<'search, Graph>
where
Graph: graph_api_lib::Graph<Vertex = Vertex>
+ graph_api_lib::SupportsVertexRangeIndex,
{
graph_api_lib::VertexSearch::range(VertexIndex::PersonAge, range)
}
pub fn person_by_username_range<'search, Graph>(
range: std::ops::Range<&'search str>,
) -> graph_api_lib::VertexSearch<'search, Graph>
where
Graph: graph_api_lib::Graph<Vertex = Vertex>
+ graph_api_lib::SupportsVertexRangeIndex,
{
graph_api_lib::VertexSearch::range(VertexIndex::PersonUsername, range)
}
}
pub use __vertex_projection_vertex_person::Person;
pub use __vertex_projection_vertex_person::PersonMut;
mod __vertex_projection_vertex_person {
use super::*;
pub struct Person<'reference, Element> {
_phantom: std::marker::PhantomData<Element>,
non_indexed: &'reference usize,
name: &'reference String,
age: &'reference u64,
unique_id: &'reference Uuid,
username: &'reference String,
biography: &'reference String,
}
impl<'reference, Element> Person<'reference, Element> {
pub fn non_indexed<'a>(&self) -> usize {
*self.non_indexed
}
pub fn name(&self) -> &str {
self.name
}
pub fn age<'a>(&self) -> u64 {
*self.age
}
pub fn unique_id<'a>(&self) -> Uuid {
*self.unique_id
}
pub fn username(&self) -> &str {
self.username
}
pub fn biography(&self) -> &str {
self.biography
}
}
pub struct PersonMut<'reference, Element, MutationListener>
where
Element: graph_api_lib::Element,
MutationListener: graph_api_lib::MutationListener<'reference, Element>,
{
_phantom: std::marker::PhantomData<Element>,
__listener: MutationListener,
non_indexed: &'reference mut usize,
name: &'reference mut String,
age: &'reference mut u64,
unique_id: &'reference mut Uuid,
username: &'reference mut String,
biography: &'reference mut String,
}
impl<
'reference,
Element,
MutationListener,
> PersonMut<'reference, Element, MutationListener>
where
Element: graph_api_lib::Element<Label = VertexLabel>,
MutationListener: graph_api_lib::MutationListener<'reference, Element>,
{
pub fn non_indexed<'a>(&self) -> usize {
*self.non_indexed
}
pub fn name(&self) -> &str {
self.name
}
pub fn age<'a>(&self) -> u64 {
*self.age
}
pub fn unique_id<'a>(&self) -> Uuid {
*self.unique_id
}
pub fn username(&self) -> &str {
self.username
}
pub fn biography(&self) -> &str {
self.biography
}
pub fn set_non_indexed(&mut self, value: usize) {
*self.non_indexed = value;
}
pub fn set_name(&mut self, value: String) {
self.__listener
.update(VertexIndex::PersonName, (&*self.name).into(), (&value).into());
*self.name = value;
}
pub fn set_age(&mut self, value: u64) {
self.__listener
.update(VertexIndex::PersonAge, (&*self.age).into(), (&value).into());
*self.age = value;
}
pub fn set_unique_id(&mut self, value: Uuid) {
self.__listener
.update(
VertexIndex::PersonUniqueId,
(&*self.unique_id).into(),
(&value).into(),
);
*self.unique_id = value;
}
pub fn set_username(&mut self, value: String) {
self.__listener
.update(
VertexIndex::PersonUsername,
(&*self.username).into(),
(&value).into(),
);
*self.username = value;
}
pub fn set_biography(&mut self, value: String) {
self.__listener
.update(
VertexIndex::PersonBiography,
(&*self.biography).into(),
(&value).into(),
);
*self.biography = value;
}
}
impl<'reference> graph_api_lib::Project<'reference, Vertex>
for Person<'reference, Vertex> {
fn project(weight: &'reference Vertex) -> Option<Self> {
if let Vertex::Person {
non_indexed,
name,
age,
unique_id,
username,
biography,
} = weight {
Some(Person {
_phantom: std::default::Default::default(),
non_indexed,
name,
age,
unique_id,
username,
biography,
})
} else {
None
}
}
}
impl<
'reference,
MutationListener,
> graph_api_lib::ProjectMut<'reference, Vertex, MutationListener>
for PersonMut<'reference, Vertex, MutationListener>
where
MutationListener: graph_api_lib::MutationListener<'reference, Vertex>,
{
fn project_mut(
weight: &'reference mut Vertex,
mutation_listener: MutationListener,
) -> Option<Self> {
if let Vertex::Person {
non_indexed,
name,
age,
unique_id,
username,
biography,
} = weight {
Some(PersonMut {
_phantom: std::default::Default::default(),
__listener: mutation_listener,
non_indexed,
name,
age,
unique_id,
username,
biography,
})
} else {
None
}
}
}
}
pub trait VertexExt<'graph, Mutability, Graph, Walker>
where
Walker: graph_api_lib::VertexWalker<'graph, Graph = Graph>,
Graph: graph_api_lib::Graph<Vertex = Vertex>,
{
fn filter_person(
self,
) -> graph_api_lib::VertexWalkerBuilder<
'graph,
Mutability,
Graph,
impl graph_api_lib::VertexWalker<
'graph,
Graph = Graph,
Context = Walker::Context,
>,
>;
fn filter_by_person<F: Fn(Person<Graph::Vertex>, &Walker::Context) -> bool>(
self,
filter: F,
) -> graph_api_lib::VertexWalkerBuilder<
'graph,
Mutability,
Graph,
impl graph_api_lib::VertexWalker<
'graph,
Graph = Graph,
Context = Walker::Context,
>,
>;
fn filter_project(
self,
) -> graph_api_lib::VertexWalkerBuilder<
'graph,
Mutability,
Graph,
impl graph_api_lib::VertexWalker<
'graph,
Graph = Graph,
Context = Walker::Context,
>,
>;
fn filter_by_project<F: Fn(&Project, &Walker::Context) -> bool>(
self,
filter: F,
) -> graph_api_lib::VertexWalkerBuilder<
'graph,
Mutability,
Graph,
impl graph_api_lib::VertexWalker<
'graph,
Graph = Graph,
Context = Walker::Context,
>,
>;
fn filter_rust(
self,
) -> graph_api_lib::VertexWalkerBuilder<
'graph,
Mutability,
Graph,
impl graph_api_lib::VertexWalker<
'graph,
Graph = Graph,
Context = Walker::Context,
>,
>;
}
impl<'graph, Mutability, Graph, Walker> VertexExt<'graph, Mutability, Graph, Walker>
for graph_api_lib::VertexWalkerBuilder<'graph, Mutability, Graph, Walker>
where
Walker: graph_api_lib::VertexWalker<'graph, Graph = Graph>,
Graph: graph_api_lib::Graph<Vertex = Vertex>,
{
fn filter_person(
self,
) -> graph_api_lib::VertexWalkerBuilder<
'graph,
Mutability,
Graph,
impl graph_api_lib::VertexWalker<
'graph,
Graph = Graph,
Context = Walker::Context,
>,
> {
self.filter(|f, _| match graph_api_lib::VertexReference::weight(f) {
Vertex::Person { .. } => true,
_ => false,
})
}
fn filter_by_person<F: Fn(Person<Graph::Vertex>, &Walker::Context) -> bool>(
self,
filter: F,
) -> graph_api_lib::VertexWalkerBuilder<
'graph,
Mutability,
Graph,
impl graph_api_lib::VertexWalker<
'graph,
Graph = Graph,
Context = Walker::Context,
>,
> {
self.filter(move |f, c| {
if let Some(projection) = graph_api_lib::VertexReference::project(f) {
(filter)(projection, c)
} else {
false
}
})
}
fn filter_project(
self,
) -> graph_api_lib::VertexWalkerBuilder<
'graph,
Mutability,
Graph,
impl graph_api_lib::VertexWalker<
'graph,
Graph = Graph,
Context = Walker::Context,
>,
> {
self.filter(|f, _| match graph_api_lib::VertexReference::weight(f) {
Vertex::Project { .. } => true,
_ => false,
})
}
fn filter_by_project<F: Fn(&Project, &Walker::Context) -> bool>(
self,
filter: F,
) -> graph_api_lib::VertexWalkerBuilder<
'graph,
Mutability,
Graph,
impl graph_api_lib::VertexWalker<
'graph,
Graph = Graph,
Context = Walker::Context,
>,
> {
self.filter(move |f, c| match graph_api_lib::VertexReference::weight(f) {
Vertex::Project(param0) => (filter)(param0, c),
_ => false,
})
}
fn filter_rust(
self,
) -> graph_api_lib::VertexWalkerBuilder<
'graph,
Mutability,
Graph,
impl graph_api_lib::VertexWalker<
'graph,
Graph = Graph,
Context = Walker::Context,
>,
> {
self.filter(|f, _| match graph_api_lib::VertexReference::weight(f) {
Vertex::Rust { .. } => true,
_ => false,
})
}
}