Trait skytable::response::FromResponse
source · pub trait FromResponse: Sized {
// Required method
fn from_response(resp: Response) -> ClientResult<Self>;
}
Expand description
Types that can be parsed from a Response
§Example implementation
Assume that our schema looks like create model mymodel(username: string, password: string, null email: string)
. Here’s
how we can directly get this without any fuss:
use skytable::{
ClientResult, Config, query,
response::{FromResponse, Response}
};
struct User {
username: String,
password: String,
email: Option<String>,
}
impl FromResponse for User {
fn from_response(resp: Response) -> ClientResult<Self> {
let (username, password, email): (String, String, Option<String>) = FromResponse::from_response(resp)?;
Ok(Self { username, password, email })
}
}
let mut db = Config::new_default("username", "password").connect().unwrap();
let myuser: User = db.query_parse(
&query!("select username, password, email FROM myspace.mymodel WHERE username = ?", "username")
).unwrap();
assert_eq!(myuser.username, "bob");
Required Methods§
sourcefn from_response(resp: Response) -> ClientResult<Self>
fn from_response(resp: Response) -> ClientResult<Self>
Decode the target type from the Response
Object Safety§
This trait is not object safe.