ingraph 0.1.0

A declaration-driven indexing framework: records and nodes are written as Rust types, and the storage rows, the dataflow between them and the GraphQL query surface are emitted from the declaration.
Documentation
use super::*;

/// The boolean filter — equality and membership, and the one kind with NO type parameter: `bool` is
/// the only type it guards, so there is nothing for a parameter to range over.
///
/// Four of [`ScalarFilter`]'s eight operators are here and four are not, and ONE rule decides which.
/// A GraphQL operand is frequently a VARIABLE, and a query document has no expression language to
/// compute with one — so an operator survives here when its QUESTION is meaningful and its OPERAND
/// may be unknown until execution. A variable rescues an operator whose operand is unknown. It does
/// not rescue an operator whose question is meaningless.
///
/// `ne` is the first case. A client that means "not `$flag`" writes `ne: $flag`, because
/// `eq: !$flag` is not something a query document can write at all. Whether the two coincide for a
/// LITERAL operand is a property of the LOWERING rather than of the two-valued domain, so it is not
/// this type's to decide either way.
///
/// `in_`/`not_in` are the same case, and "over a two-valued domain membership is degenerate" is that
/// case misread from the author's chair. `in: [true, false]` matches every row and `in: [true]` is
/// exactly `eq: true` — for a reader who knows the operand. A generated or generic client emits
/// `{ field: { in: $values } }` over every field type alike and learns what `$values` holds at
/// execution time; withhold the slots and that client, and the code generator behind it, needs a
/// boolean special case. `in: []` is the sharper half: a computed set that came out empty means
/// MATCH NOTHING, which is a set operand like any other and not a shape `eq` or `ne` can be given —
/// so a two-slot filter makes the client detect the empty case and emit something structurally
/// different.
///
/// No ordering, and the variable rescues nothing there. `false < true` is defined in Rust, but
/// `gt: $flag` asks whether one flag exceeds another, which is meaningless however the operand
/// arrives — `gt`/`gte`/`lt`/`lte` stay out, and a schema offering them would be inviting a client to
/// ask it.
///
/// Nullability needs nothing added here. `Option<bool>` resolves to [`Nullable<BooleanFilter>`]
/// through the framework's one `Option` blanket, and the null test lives only in that wrapper — as
/// it does for every other kind.
///
/// [`Nullable<BooleanFilter>`]: Nullable
#[derive(Debug, Clone, PartialEq)]
pub struct BooleanFilter {
  pub(crate) eq: Option<bool>,
  pub(crate) ne: Option<bool>,
  pub(crate) in_: Option<Box<[bool]>>,
  pub(crate) not_in: Option<Box<[bool]>>,
}

impl BooleanFilter {
  /// The empty filter — no operator set.
  #[inline]
  pub const fn new() -> Self {
    Self {
      eq: None,
      ne: None,
      in_: None,
      not_in: None,
    }
  }

  /// True while NO operator slot is set — so a lowering would emit nothing for this field.
  ///
  /// Inherent, not the backend traits' provided `is_empty`: "is anything set" is a property of the
  /// FILTER, identical on every backend, and asking it should not make a caller name a dialect (with
  /// two families compiled, `f.is_empty()` through the traits is `E0283`). The inherent method wins
  /// method resolution, so every call site reads the same either way.
  ///
  /// A SET membership slot is non-empty even when the list inside it is: `in: []` is the operator
  /// present with an empty operand, which asks for no rows, where an absent `in_` asks for all of
  /// them. The question is field presence, never operand length.
  #[inline]
  pub const fn is_empty(&self) -> bool {
    self.eq.is_none() && self.ne.is_none() && self.in_.is_none() && self.not_in.is_none()
  }

  opt_accessor!(eq: bool => with_eq, set_eq, maybe_eq, update_eq);
  opt_accessor!(ne: bool => with_ne, set_ne, maybe_ne, update_ne);
  opt_accessor!(in_: [bool] => with_in_, set_in_, maybe_in_, update_in_);
  opt_accessor!(not_in: [bool] => with_not_in, set_not_in, maybe_not_in, update_not_in);
}

impl Default for BooleanFilter {
  #[inline]
  fn default() -> Self {
    Self::new()
  }
}

/// The bound's row: `new()` and the inherent `with_eq`, reached where the kind is a parameter rather
/// than a spelling.
impl EqualsFilter<bool> for BooleanFilter {
  #[inline]
  fn equals(value: bool) -> Self {
    Self::new().with_eq(value)
  }
}

impl GraphqlFilter for BooleanFilter {
  #[inline]
  fn is_empty(&self) -> bool {
    Self::is_empty(self)
  }
}