Module skytable::types [−][src]
Expand description
Types
This module contains a collection of enumerations and traits that are used for converting multiple types, either primitve or user-defined, into Skyhash serializable items.
Implementing a Skyhash serializable type
If you have an object that can be turned into a String
or a sequence of String
objects, then
your type can be serialized by Skyhash (this might change in the future with more types being supported).
Here is a simple example:
use skytable::actions::Actions; use skytable::types::{IntoSkyhashAction, IntoSkyhashBytes, GetIterator}; use skytable::Query; /// Our custom element that adds "cool" to the end of every string when serialized struct CoolString(String); impl IntoSkyhashBytes for CoolString { fn into_string(&self) -> String { let mut st = self.0.to_string(); // add cool st.push_str("cool"); st } } /// Our custom sequence of `CoolString` objects struct CoolStringCollection(Vec<CoolString>); impl IntoSkyhashAction for CoolStringCollection { fn push_into_query(&self, query: &mut Query) { self.0.iter().for_each(|item| query.push(item.into_string())); } fn incr_len_by(&self) -> usize { self.0.len() } } // And finally implement `GetIterator` for use with some actions that need them impl GetIterator<CoolString> for CoolStringCollection { fn get_iter(&self) -> std::slice::Iter<'_, CoolString> { self.0.iter() } } // You can now directly append your custom element to queries fn main() { let mut q = Query::new(); let cool = CoolString(String::from("sayan is ")); q.push(cool); let other_cools = CoolStringCollection(vec![ CoolString("ferris is ".to_owned()), CoolString("llvm is ".to_owned()) ]); q.push(other_cools); assert_eq!(q, Query::from(vec!["sayan is cool", "ferris is cool", "llvm is cool"])); }
Enums
SnapshotResult | Result of an |
Traits
GetIterator | Implement this trait for methods in |
IntoSkyhashAction | Anything that implements this trait can directly add itself to the bytes part of a |
IntoSkyhashBytes | Anything that implements this trait can be turned into a |