gqb 0.10.1

GQL Query Builder API.
Documentation
/// Hold the name of a variable in the query.
#[derive(Debug, Eq, PartialEq, Clone, Copy, Hash)]
pub struct Variable
{
  pub(crate) suffix: &'static str,
  pub(crate) id: usize,
}

impl std::fmt::Display for Variable
{
  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
  {
    write!(f, "{}{}", self.suffix, self.id)
  }
}

/// Represent a variable with a type
#[derive(Debug, Eq, PartialEq, Clone, Copy, Hash)]
pub struct TypedVariable<T>
where
  T: TryFrom<graphcore::Value>,
{
  v: Variable,
  _marker: std::marker::PhantomData<T>,
}

impl<T> std::fmt::Display for TypedVariable<T>
where
  T: TryFrom<graphcore::Value>,
{
  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result
  {
    write!(f, "{} ({})", self.v, std::any::type_name::<T>())
  }
}

impl<T> From<TypedVariable<T>> for Variable
where
  T: TryFrom<graphcore::Value>,
{
  fn from(value: TypedVariable<T>) -> Self
  {
    value.v
  }
}

macro_rules! __variable {
  ($idx:tt) => {
    Variable
  };
}

pub(crate) use __variable;

pub trait FromVariable
{
  fn from_variable(variable: Variable) -> Self;
}

impl FromVariable for Variable
{
  fn from_variable(variable: Variable) -> Self
  {
    variable
  }
}

impl<T> FromVariable for TypedVariable<T>
where
  T: TryFrom<graphcore::Value>,
{
  fn from_variable(variable: Variable) -> Self
  {
    TypedVariable {
      v: variable,
      _marker: std::marker::PhantomData,
    }
  }
}