Skip to main content

FindSpec

Enum FindSpec 

Source
pub enum FindSpec {
    FindRel(Vec<Element>),
    FindColl(Element),
    FindTuple(Vec<Element>),
    FindScalar(Element),
}
Expand description

A definition of the first part of a find query: the [:find ?foo ?bar…] bit.

There are four different kinds of find specs, allowing you to query for a single value, a collection of values from different entities, a single tuple (relation), or a collection of tuples.

Examples:



  let elements = vec![
    Element::Variable("?foo".to_var()),
    Element::Variable("?bar".to_var()),
  ];
  let rel = FindSpec::FindRel(elements);

  if let FindSpec::FindRel(elements) = rel {
    assert_eq!(2, elements.len());
  }

Variants§

§

FindRel(Vec<Element>)

Returns an array of arrays, represented as a single array with length a multiple of width.

§

FindColl(Element)

Returns an array of scalars, usually homogeneous. This is equivalent to mapping over the results of a FindRel, returning the first value of each.

§

FindTuple(Vec<Element>)

Returns a single tuple: a heterogeneous array of scalars. Equivalent to taking the first result from a FindRel.

§

FindScalar(Element)

Returns a single scalar value. Equivalent to taking the first result from a FindColl.

Implementations§

Source§

impl FindSpec

Returns true if the provided FindSpec returns at most one result.

Source

pub fn is_unit_limited(&self) -> bool

Source

pub fn expected_column_count(&self) -> usize

Source

pub fn requires_distinct(&self) -> bool

Returns true if the provided FindSpec cares about distinct results.

I use the words “cares about” because find is generally defined in terms of producing distinct results at the Datalog level.

Two of the find specs (scalar and tuple) produce only a single result. Those don’t need to be run with SELECT DISTINCT, because we’re only consuming a single result. Those queries will be run with LIMIT 1.

Additionally, some projections cannot produce duplicate results: [:find (max ?x) …], for example.

This function gives us the hook to add that logic when we’re ready.

Beyond this, DISTINCT is not always needed. For example, in some kinds of accumulation or sampling projections we might not need to do it at the SQL level because we’re consuming into a dupe-eliminating data structure like a Set, or we know that a particular query cannot produce duplicate results.

Source

pub fn columns<'s>(&'s self) -> Box<dyn Iterator<Item = &'s Element> + 's>

Trait Implementations§

Source§

impl Clone for FindSpec

Source§

fn clone(&self) -> FindSpec

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FindSpec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for FindSpec

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for FindSpec

Source§

impl PartialEq for FindSpec

Source§

fn eq(&self, other: &FindSpec) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for FindSpec

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.