pub struct Client { /* private fields */ }Expand description
An async client for the System One API. It needs a tokio runtime with the
time driver enabled, which #[tokio::main] provides.
Cloning is cheap and shares the connection pool.
use typesafe::{Choice, Client, Noul, Questions};
let client = Client::new(); // reads TYPESAFE_API_KEY
let questions = Questions::new()
.ask("billing", Noul::new("Is this ticket about billing?"))
.ask("tone", Choice::new("What is the customer's tone?").options(["calm", "angry"]));
let response = client.system_one("I was charged twice!", &questions).await?;
if response.noul("billing").unwrap().yes() {
println!("billing, tone {}", response.choice("tone").unwrap().choice);
}Implementations§
Source§impl Client
impl Client
Sourcepub fn new() -> Self
pub fn new() -> Self
A client configured from the environment (Config::from_env).
§Panics
If the TLS backend can’t be initialized, as reqwest::Client::new
does. Client::with_config returns that as an error instead.
pub fn with_config(config: Config) -> Result<Self, Error>
pub fn config(&self) -> &Config
Sourcepub fn is_configured(&self) -> bool
pub fn is_configured(&self) -> bool
Whether the client has an API key.
Sourcepub async fn system_one<S: Serialize + ?Sized>(
&self,
state: &S,
questions: &Questions,
) -> Result<Response, Error>
pub async fn system_one<S: Serialize + ?Sized>( &self, state: &S, questions: &Questions, ) -> Result<Response, Error>
Asks questions about state in one request.
state is a string, or anything that serializes to a JSON object or
array. A struct keeps its field order on the wire.
Sourcepub async fn system_one_with<S: Serialize + ?Sized>(
&self,
state: &S,
questions: &Questions,
options: &CallOptions,
) -> Result<Response, Error>
pub async fn system_one_with<S: Serialize + ?Sized>( &self, state: &S, questions: &Questions, options: &CallOptions, ) -> Result<Response, Error>
system_one with per-call overrides.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Client
impl !UnwindSafe for Client
impl Freeze for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl UnsafeUnpin for Client
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