pub struct OrCondition { /* private fields */ }
Implementations§
Source§impl OrCondition
impl OrCondition
Sourcepub fn new(conditions: Vec<AndCondition>) -> Self
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}
pub fn resolve_conditions_for_edit(&mut self) -> &mut Vec<AndCondition>
pub fn resolve_conditions(&self) -> &Vec<AndCondition>
Trait Implementations§
Source§impl Clone for OrCondition
impl Clone for OrCondition
Source§fn clone(&self) -> OrCondition
fn clone(&self) -> OrCondition
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for OrCondition
impl Debug for OrCondition
Source§impl Display for OrCondition
impl Display for OrCondition
Source§impl PartialEq for OrCondition
impl PartialEq for OrCondition
impl Eq for OrCondition
impl StructuralPartialEq for OrCondition
Auto Trait Implementations§
impl Freeze for OrCondition
impl RefUnwindSafe for OrCondition
impl Send for OrCondition
impl Sync for OrCondition
impl Unpin for OrCondition
impl UnwindSafe for OrCondition
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
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>
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)
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)
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.