pub struct BlockingClient { /* private fields */ }Available on crate feature
blocking only.Expand description
Blocking wrapper around Client using a current-thread Tokio runtime.
Do not use this type from inside an existing Tokio runtime (block_on will panic).
Enable with typesafe-rs = { version = "0.1", features = ["blocking"] }.
Implementations§
Source§impl BlockingClient
impl BlockingClient
Sourcepub fn new(config: ClientConfig) -> Result<Self, Error>
pub fn new(config: ClientConfig) -> Result<Self, Error>
Build a blocking client. See Client::new.
Sourcepub fn new_with_env(
config: ClientConfig,
lookup: impl FnMut(&str) -> Option<String>,
) -> Result<Self, Error>
pub fn new_with_env( config: ClientConfig, lookup: impl FnMut(&str) -> Option<String>, ) -> Result<Self, Error>
Like Client::new_with_env.
Sourcepub fn system_one(
&self,
state: impl Serialize,
questions: Questions,
) -> Result<SystemOneResponse, Error>
pub fn system_one( &self, state: impl Serialize, questions: Questions, ) -> Result<SystemOneResponse, Error>
Blocking Client::system_one.
Examples found in repository?
examples/blocking.rs (lines 25-28)
11fn main() -> Result<(), Box<dyn std::error::Error>> {
12 let rt = tokio::runtime::Builder::new_multi_thread()
13 .enable_all()
14 .build()?;
15 let mock = rt.block_on(MockServer::start());
16 mock.on_system_one().respond(json!({
17 "urgent": noul(0.91),
18 }));
19
20 let client = ClientConfig::new()
21 .api_key("test")
22 .base_url(mock.url())
23 .build_blocking()?;
24
25 let response = client.system_one(
26 "Help! My payouts have been failing for 3 days.",
27 questions! { "urgent" => Question::noul("Does this convey urgency?") },
28 )?;
29 println!("urgent noul = {:?}", response.noul("urgent"));
30
31 drop(client);
32 drop(mock);
33 drop(rt);
34 Ok(())
35}Sourcepub fn system_one_with(
&self,
req: &SystemOneRequest,
opts: CallOptions,
) -> Result<SystemOneResponse, Error>
pub fn system_one_with( &self, req: &SystemOneRequest, opts: CallOptions, ) -> Result<SystemOneResponse, Error>
Blocking Client::system_one_with.
Sourcepub fn models(&self) -> BlockingModels<'_>
pub fn models(&self) -> BlockingModels<'_>
Access the Models resource.
Sourcepub fn default_model(&self) -> &str
pub fn default_model(&self) -> &str
Default model used when a request omits model.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for BlockingClient
impl !RefUnwindSafe for BlockingClient
impl !UnwindSafe for BlockingClient
impl Send for BlockingClient
impl Sync for BlockingClient
impl Unpin for BlockingClient
impl UnsafeUnpin for BlockingClient
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