gqb 0.10.1

GQL Query Builder API.
Documentation
use crate::{IntoCreateEdgeTemplate, prelude::*};

/// Trait for multi-edge creation.
pub trait CreateEdges
{
  /// Output of multi-edge creation
  type Output;
  /// Fill the builder
  fn fill(self, builder: &mut Builder) -> Self::Output;
}

macro_rules! impl_create_edges {
  ($n:tt $($idx:tt $t:ident),*) => {
    impl<$($t),*> CreateEdges
        for ($($t,)*)
    where
        $($t: IntoCreateEdgeTemplate),*
    {
      type Output = ($($t::VariableType,)*);

      fn fill(self, builder: &mut Builder) -> Self::Output {
        ($(
          builder.create_edge(self.$idx),
        )*)
      }
    }
  };
}

// Generate implementations for 1..=20
macro_rules! impl_all {
  ($($n:tt $($idx:tt $t:ident),*;)*) => {
      $(impl_create_edges!($n $($idx $t),*);)*
  };
}

impl_all! {
  1 0 T0;
  2 0 T0, 1 T1;
  3 0 T0, 1 T1, 2 T2;
  4 0 T0, 1 T1, 2 T2, 3 T3;
  5 0 T0, 1 T1, 2 T2, 3 T3, 4 T4;
  6 0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5;
  7 0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6;
  8 0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7;
  9 0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8;
  10 0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8, 9 T9;
  11 0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8, 9 T9, 10 T10;
  12 0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8, 9 T9, 10 T10, 11 T11;
  13 0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8, 9 T9, 10 T10, 11 T11, 12 T12;
  14 0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8, 9 T9, 10 T10, 11 T11, 12 T12, 13 T13;
  15 0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8, 9 T9, 10 T10, 11 T11, 12 T12, 13 T13, 14 T14;
  16 0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8, 9 T9, 10 T10, 11 T11, 12 T12, 13 T13, 14 T14, 15 T15;
  17 0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8, 9 T9, 10 T10, 11 T11, 12 T12, 13 T13, 14 T14, 15 T15, 16 T16;
  18 0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8, 9 T9, 10 T10, 11 T11, 12 T12, 13 T13, 14 T14, 15 T15, 16 T16, 17 T17;
  19 0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8, 9 T9, 10 T10, 11 T11, 12 T12, 13 T13, 14 T14, 15 T15, 16 T16, 17 T17, 18 T18;
  20 0 T0, 1 T1, 2 T2, 3 T3, 4 T4, 5 T5, 6 T6, 7 T7, 8 T8, 9 T9, 10 T10, 11 T11, 12 T12, 13 T13, 14 T14, 15 T15, 16 T16, 17 T17, 18 T18, 19 T19;
}

impl<T> CreateEdges for Vec<T>
where
  T: IntoCreateEdgeTemplate,
{
  type Output = Vec<T::VariableType>;
  fn fill(self, builder: &mut Builder) -> Self::Output
  {
    let mut out = Vec::<T::VariableType>::new();
    for t in self
    {
      out.push(builder.create_edge(t));
    }
    out
  }
}