OrCondition

Struct OrCondition 

Source
pub struct OrCondition { /* private fields */ }

Implementations§

Source§

impl OrCondition

Source

pub fn new(conditions: Vec<AndCondition>) -> Self

Examples found in repository?
examples/00_usage.rs (lines 79-84)
40fn main() {
41    // Specify home location for indexes
42    let home = ".store".to_string();
43    // Specify index name
44    let index_name = "usage".to_string();
45
46    // Prepare builder
47    let mut builder = SurferBuilder::default();
48    builder.set_home(&home);
49
50    let data = UserInfo::default();
51    builder.add_struct(index_name.clone(), &data);
52
53    // Prepare Surf
54    let mut surf = Surf::try_from(builder).unwrap();
55
56    // Prepare data to insert & search
57
58    // User 1: John Doe
59    let first = "John".to_string();
60    let last = "Doe".to_string();
61    let age = 20u8;
62    let john_doe = UserInfo::new(first, last, age);
63
64    // User 2: Jane Doe
65    let first = "Jane".to_string();
66    let last = "Doe".to_string();
67    let age = 18u8;
68    let jane_doe = UserInfo::new(first, last, age);
69
70    // See examples for more options
71    let users = vec![john_doe.clone(), jane_doe.clone()];
72    let _ = surf.insert(&index_name, &users).unwrap();
73
74    block_thread(1);
75
76    // See examples for more options
77    // Similar to SELECT * FROM users WHERE (age = 20 AND last = "Doe") OR (first = "Jane")
78    let conditions = vec![
79        OrCondition::new(
80            // (age = 20 AND last = "Doe")
81            vec![
82                AndCondition::new("age".to_string(), "20".to_string()),
83                AndCondition::new("last".to_string(), "doe".to_string())
84            ]),
85        OrCondition::new(
86            // (first = "Jane")
87            vec![
88                AndCondition::new("first".to_string(), "jane".to_string())
89            ])
90    ];
91
92    // Validate John and Jane Doe
93    let mut computed = surf.select::<UserInfo>(&index_name, &conditions).unwrap().unwrap();
94    let mut expected = vec![john_doe.clone(), jane_doe.clone(), ];
95    expected.sort();
96    computed.sort();
97    assert_eq!(expected, computed);
98
99    // Validated John's record - Alternate shortcut for query using one field only
100    let computed = surf.read_all_structs_by_field(&index_name, "age", "20");
101    let computed: Vec<UserInfo> = computed.unwrap().unwrap();
102    assert_eq!(vec![john_doe], computed);
103
104    // Delete John's record
105    let result = surf.delete(&index_name, "age", "20");
106    assert!(result.is_ok());
107
108    // John's was removed
109    let computed = surf.read_all_structs_by_field(&index_name, "age", "20");
110    let computed: Vec<UserInfo> = computed.unwrap().unwrap();
111    assert!(computed.is_empty());
112
113
114    // Clean-up
115    let path = surf.which_index(&index_name).unwrap();
116    let _ = remove_dir_all(&path);
117    let _ = remove_dir_all(&home);
118}
Source

pub fn resolve_conditions_for_edit(&mut self) -> &mut Vec<AndCondition>

Source

pub fn resolve_conditions(&self) -> &Vec<AndCondition>

Trait Implementations§

Source§

impl Clone for OrCondition

Source§

fn clone(&self) -> OrCondition

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for OrCondition

Source§

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

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

impl Display for OrCondition

Source§

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

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

impl From<(String, String)> for OrCondition

Source§

fn from((field_name, field_value): (String, String)) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for OrCondition

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Eq for OrCondition

Source§

impl StructuralPartialEq for OrCondition

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> 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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> Erased for T

Source§

impl<T> Fruit for T
where T: Send + Downcast,