pub struct Context { /* private fields */ }
Expand description
A structure that holds information about the backend we’re about to query.
All its setters are const
, meaning it can be placed in a module, and
accessed from anywhere in the module.
§Example
use restest::{Context, Request};
const CONTEXT: Context = Context::new()
.with_port(80)
.with_host("http://localhost");
#[tokio::test]
async fn first_test() {
// Use CONTEXT.run(...) to run a request.
}
#[tokio::test]
async fn second_test() {
// Use CONTEXT.run(...) to run another request.
}
Implementations§
Source§impl Context
impl Context
Sourcepub const fn new() -> Context
pub const fn new() -> Context
Creates a new context with default values.
The default host is localhost.
The default port is port 80
.
Sourcepub const fn with_host(self, host: &'static str) -> Context
pub const fn with_host(self, host: &'static str) -> Context
Sets a host value.
The previously-set host is discarded.
Sourcepub const fn with_port(self, port: u16) -> Context
pub const fn with_port(self, port: u16) -> Context
Sets a port value.
The previously-set port is discarded.
Sourcepub async fn run<I>(&self, request: Request<I>) -> RequestResultwhere
I: Serialize,
pub async fn run<I>(&self, request: Request<I>) -> RequestResultwhere
I: Serialize,
Runs a request.
This function performs I/O, therefore it is marked as async
.
Auto Trait Implementations§
impl Freeze for Context
impl RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnwindSafe for Context
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