Skip to main content

Comparison

Enum Comparison 

Source
pub enum Comparison {
    Equal(ParseValue),
    EqualOperator(ParseValue),
    NotEqual(ParseValue),
    GreaterThan(ParseValue),
    GreaterThanOrEqual(ParseValue),
    LessThan(ParseValue),
    LessThanOrEqual(ParseValue),
    In(Vec<ParseValue>),
    NotIn(Vec<ParseValue>),
    Exists(bool),
    All(Vec<ParseValue>),
    Regex {
        pattern: String,
        options: Option<String>,
    },
}
Expand description

How one field is compared to one value.

Variants§

§

Equal(ParseValue)

Bare equality: {"field": value}. Lowers to the value itself, with no operator wrapper.

§

EqualOperator(ParseValue)

Explicit $eq: {"field": {"$eq": value}}.

Deliberately not the same variant as Comparison::Equal, because the two do not lower the same way. Bare equality puts the value directly under the field, so it cannot share the field with another operator: {"n": 5} and {"n": {"$gt": 1}} are two whole documents for one key and merging them means one overwrites the other. $eq is an operator like any other and composes, which is the entire reason upstream’s replaceEquality rewrites a mixed constraint into this form rather than leaving it bare (RestQuery.js:828-849).

Folding the two together compiles, passes a round-trip test, and silently undoes that rewrite one layer below where it was applied.

It also must not pin an objectId. ParsedWhere::pinned_object_id reads the shorthand form only, matching upstream’s direct query.objectId read (DatabaseController.js:1838), and a separate variant is what keeps {"objectId": {"$eq": "x"}} out of that path.

§

NotEqual(ParseValue)

§

GreaterThan(ParseValue)

§

GreaterThanOrEqual(ParseValue)

§

LessThan(ParseValue)

§

LessThanOrEqual(ParseValue)

§

In(Vec<ParseValue>)

§

NotIn(Vec<ParseValue>)

§

Exists(bool)

§

All(Vec<ParseValue>)

$all: the array field contains every listed value.

§

Regex

$regex, with $options folded in.

The two arrive as separate keys and upstream keeps them separate all the way down, relying on reverse-alphabetical key iteration so that $regex is handled before $options (MongoTransform.js:670-675). Folding them into one variant here removes the ordering dependency without changing what reaches the backend, because a lone $options is meaningless and a lone $regex gets None.

Fields

§pattern: String
§options: Option<String>

Implementations§

Source§

impl Comparison

Source

pub fn from_operator(op: &str, value: ParseValue) -> Result<Self, ParseError>

Map a Parse $ operator onto a comparison.

Returns INVALID_QUERY for anything unsupported. That is the whole point: the alternative, ignoring it, returns more rows than the caller asked for.

$regex and $options are not handled here, because they are two keys producing one comparison. The caller assembles them; see parse_operators in parse-rust-rest.

Trait Implementations§

Source§

impl Clone for Comparison

Source§

fn clone(&self) -> Comparison

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 Comparison

Source§

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

Formats the value using the given formatter. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V