pub struct AndCondition { /* private fields */ }
Implementations§
Source§impl AndCondition
impl AndCondition
Sourcepub fn new(field_name: String, field_value: String) -> Self
pub fn new(field_name: String, field_value: String) -> Self
Examples found in repository?
examples/00_usage.rs (line 82)
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 update_field_value(&mut self, field_value: String)
pub fn resolve_field_name(&self) -> &String
pub fn resolve_field_value(&self) -> &String
Trait Implementations§
Source§impl Clone for AndCondition
impl Clone for AndCondition
Source§fn clone(&self) -> AndCondition
fn clone(&self) -> AndCondition
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 AndCondition
impl Debug for AndCondition
Source§impl PartialEq for AndCondition
impl PartialEq for AndCondition
impl Eq for AndCondition
impl StructuralPartialEq for AndCondition
Auto Trait Implementations§
impl Freeze for AndCondition
impl RefUnwindSafe for AndCondition
impl Send for AndCondition
impl Sync for AndCondition
impl Unpin for AndCondition
impl UnwindSafe for AndCondition
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.