Struct anterofit::net::request::Request
[−]
[src]
#[must_use = "Request has not been sent yet"]pub struct Request<'a, T = ()> { /* fields omitted */ }
A request which is ready to be sent to the server.
Use exec()
or exec_here()
to send the request and receive the response.
Note
If an error occurred during initialization of the request, it will be immediately returned when the request is executed; no network or disk activity will occur.
Methods
impl<'a, T> Request<'a, T>
[src]
fn immediate(res: Result<T>) -> Request<'static, T>
Construct a Result
wrapping an immediate return of res
.
No network or disk activity will occur when this request is executed.
fn exec_here(self) -> Result<T>
Execute this request on the current thread, blocking until the result is available.
fn is_immediate(&self) -> bool
Returns true
if a result is immediately available (exec_here()
will not block).
impl<'a, T> Request<'a, T> where T: Send + 'static
[src]
fn exec(self) -> Call<T>
Execute this request on the adapter's executor, returning a type which can be polled for the result.
fn on_complete<F, R>(self, on_complete: F) -> Request<'a, R> where F: FnOnce(T) -> R + Send + 'static, R: Send + 'static
Add a callback to be executed with the request's return value when available, mapping
it to another value (or ()
if no return value).
on_complete
will always be executed on the adapter's executor because the return
value will not be available until the request is executed, whereas on_result()
's closure
may be executed immediately if an immediate result is available.
If a result is immediately available, on_complete
will be discarded.
Note
on_complete
should not be long-running in order to not block other requests waiting
on the executor.
Warning about Panics
Panics in on_complete
will cause the return value to be lost. There is no safety
issue and subsequent requests shouldn't be affected, but it may be harder to debug
without knowing which request caused the panic.
fn on_result<F, R>(self, on_result: F) -> Request<'a, R> where F: FnOnce(Result<T>) -> Result<R> + Send + 'static, R: Send + 'static
Add a callback to be executed with the request's result when available, mapping it to
another result (which can be ::Result<()>
).
If a result is immediately available, on_result
will be executed on the current thread
with the result, and the return value will be immediately available as well.
Note
on_result
should not be long-running in order to not block other requests waiting
on the executor, or block the current thread if the result is immediate.
Warning about Panics
Panics in on_result
will cause the return value to be lost. There is no safety
issue and subsequent requests shouldn't be affected, but it may be harder to debug
without knowing which request caused the panic.
If the result is immediately available, panics in on_result
will occur on the
current thread.