Trait skytable::types::IntoSkyhashAction
source · [−]pub trait IntoSkyhashAction: Send + Sync {
fn push_into_query(&self, data: &mut Query);
fn incr_len_by(&self) -> usize;
}
Expand description
Anything that implements this trait can directly add itself to the bytes part of a Query
object
Implementing this trait
This trait does not need to be implemented manually for some basic objects. Once you implement
IntoSkyhashBytes
, it is implemented automatically. This trait will need to be implemented manually
for other objects however. For example:
use skytable::types::IntoSkyhashAction;
use skytable::Query;
struct MyVecWrapper(Vec<String>);
impl IntoSkyhashAction for MyVecWrapper {
fn push_into_query(&self, q: &mut Query) {
self.0.iter().for_each(|element| q.push(element));
}
fn incr_len_by(&self) -> usize {
self.0.len()
}
}
Unexpected behavior
As you can see, it is easy enough for someone to miss an element while implementing (maybe not the best example)
IntoSkyhashAction::push_into_query()
and also misguide the client driver about the length in the
implementation for IntoSkyhashAction::incr_len_by()
. This is why you should stay on the guard
while implementing it.
Required methods
fn push_into_query(&self, data: &mut Query)
fn push_into_query(&self, data: &mut Query)
Extend the bytes of a Vec
of bytes
fn incr_len_by(&self) -> usize
fn incr_len_by(&self) -> usize
Returns the number of items Self
will add to the query