pub enum Mapping {
Associative(Associative),
Error(Error),
Execute(Execute),
Standard(Standard),
Empty(Empty),
}Expand description
Mapping is used in response::Result and
Query::results()
§Examples
Match your response::Result to a concrete Response
use rqlite_client::response::{self, Result};
use rqlite_client::{Mapping, Response};
// // for description of the data structure
// let response_result: Result =
// Ok(Response::Query(response::query::Query {
// results: vec![Mapping::Error(response::mapping::Error {
// error: String::new(),
// })],
// sequence_number: None,
// time: None,
// }));
let response_result: Option<Result> = None;
if let Some(Ok(response_result)) = response_result {
let query = response::Query::from(response_result);
for result in query.results() {
match result {
Mapping::Error(err) => err.to_string(),
_ => "no error".to_string(),
};
}
}Convert Result to an own data struct
use rqlite_client::response::{self, Query, Result};
use rqlite_client::response::mapping::Timed;
use rqlite_client::{Mapping, Response};
struct MyData {
timing: std::time::Duration,
}
impl TryFrom<&Mapping> for MyData {
type Error = rqlite_client::Error;
fn try_from(r: &Mapping) -> std::result::Result<Self, Self::Error> {
match r {
Mapping::Associative(r) => Ok(MyData {
timing: r.duration().unwrap(),
}),
Mapping::Standard(r) => Ok(MyData {
timing: r.duration().unwrap(),
}),
_ => Err(rqlite_client::Error::from("not expected MyData")),
}
}
}
let response_result: Option<Result> = None;
if let Some(Ok(response_result)) = response_result {
let query = response::Query::from(response_result);
let my_data = query
.results()
.filter_map(|r| MyData::try_from(r).ok())
.collect::<Vec<MyData>>();
}Variants§
Associative(Associative)
See Associative
Error(Error)
See Error
Execute(Execute)
See Execute
Standard(Standard)
See Standard
Empty(Empty)
See Empty
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Mapping
impl<'de> Deserialize<'de> for Mapping
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for Mapping
Auto Trait Implementations§
impl Freeze for Mapping
impl RefUnwindSafe for Mapping
impl Send for Mapping
impl Sync for Mapping
impl Unpin for Mapping
impl UnsafeUnpin for Mapping
impl UnwindSafe for Mapping
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