pub struct Task { /* private fields */ }
Expand description
An Task
consists of a head and a potentially optional body. The body component is
generic, enabling arbitrary types to represent the HTTP body. For example, the body could be
Vec
Implementations
sourceimpl Task
impl Task
sourcepub fn builder() -> TaskBuilder
pub fn builder() -> TaskBuilder
create an uninitalized Task instance
without set the parser as well
NOTE valid only in this crate when recycling failed response
Create an instance of TaskBuilder
that used to build a Task
Examples
let task = Task::builder()
.method("GET")
.uri("https://example.com/")
.header("accept", "*/*")
.parser(parser_fn)
.body(())
.unwrap();
sourceimpl Task
impl Task
sourcepub fn get<'a, S>(uri: S) -> TaskBuilder where
Uri: TryFrom<S>,
<Uri as TryFrom<S>>::Error: Into<Error>,
pub fn get<'a, S>(uri: S) -> TaskBuilder where
Uri: TryFrom<S>,
<Uri as TryFrom<S>>::Error: Into<Error>,
creates a new TaskBuilder
initialized with a POST method and URI
Examples
let task = Task::get("https://example.com/")
.parser(parser_fn)
.body(())
.unwrap();
sourcepub fn post<'a, S>(uri: S) -> TaskBuilder where
Uri: TryFrom<S>,
<Uri as TryFrom<S>>::Error: Into<Error>,
pub fn post<'a, S>(uri: S) -> TaskBuilder where
Uri: TryFrom<S>,
<Uri as TryFrom<S>>::Error: Into<Error>,
creates a new TaskBuilder
initialized with a POST method and URI
Examples
let task = Task::post("https://example.com/")
.parser(parser_fn)
.body(());
sourcepub fn put<'a, S>(uri: S) -> TaskBuilder where
Uri: TryFrom<S>,
<Uri as TryFrom<S>>::Error: Into<Error>,
pub fn put<'a, S>(uri: S) -> TaskBuilder where
Uri: TryFrom<S>,
<Uri as TryFrom<S>>::Error: Into<Error>,
creates a new TaskBuilder
initialized with a PUT method and URI
Examples
let task = Task::put("https://example.com/")
.parser(parser_fn)
.body(());
sourcepub fn connect<'a, S>(uri: S) -> TaskBuilder where
Uri: TryFrom<S>,
<Uri as TryFrom<S>>::Error: Into<Error>,
pub fn connect<'a, S>(uri: S) -> TaskBuilder where
Uri: TryFrom<S>,
<Uri as TryFrom<S>>::Error: Into<Error>,
creates a new TaskBuilder
initialized with a CONNECT method and URI
Examples
let task = Task::connect("https://example.com/")
.parser(parser_fn)
.body(());
sourcepub fn delete<'a, S>(uri: S) -> TaskBuilder where
Uri: TryFrom<S>,
<Uri as TryFrom<S>>::Error: Into<Error>,
pub fn delete<'a, S>(uri: S) -> TaskBuilder where
Uri: TryFrom<S>,
<Uri as TryFrom<S>>::Error: Into<Error>,
creates a new TaskBuilder
initialized with a DELETE method and URI
Examples
let request = Task::delete("https://example.com/")
.parser(parser_fn)
.body(());
sourcepub fn head<'a, S>(uri: S) -> TaskBuilder where
Uri: TryFrom<S>,
<Uri as TryFrom<S>>::Error: Into<Error>,
pub fn head<'a, S>(uri: S) -> TaskBuilder where
Uri: TryFrom<S>,
<Uri as TryFrom<S>>::Error: Into<Error>,
creates a new TaskBuilder
initialized with a HEAD method and URI
Examples
let task = Task::head("https://example.com/")
.parser(parser_fn)
.body(());
sourcepub fn options<'a, S>(uri: S) -> TaskBuilder where
Uri: TryFrom<S>,
<Uri as TryFrom<S>>::Error: Into<Error>,
pub fn options<'a, S>(uri: S) -> TaskBuilder where
Uri: TryFrom<S>,
<Uri as TryFrom<S>>::Error: Into<Error>,
creates a new TaskBuilder
initialized with a OPTIONS method and URI
Examples
let task = Task::options("https://example.com/")
.parser(parser_fn)
.body(());
sourcepub fn patch<S>(uri: S) -> TaskBuilder where
Uri: TryFrom<S>,
<Uri as TryFrom<S>>::Error: Into<Error>,
pub fn patch<S>(uri: S) -> TaskBuilder where
Uri: TryFrom<S>,
<Uri as TryFrom<S>>::Error: Into<Error>,
creates a new TaskBuilder
initialized with a PATCH method and URI
Examples
let task = Task::patch("https://example.com/")
.parser(parser_fn)
.body(());
sourcepub fn trace<'a, S>(uri: S) -> TaskBuilder where
Uri: TryFrom<S>,
<Uri as TryFrom<S>>::Error: Into<Error>,
pub fn trace<'a, S>(uri: S) -> TaskBuilder where
Uri: TryFrom<S>,
<Uri as TryFrom<S>>::Error: Into<Error>,
creates a new TaskBuilder
initialized with a TRACE method and URI
Examples
let task = Task::trace("https://example.com/")
.parser(parser_fn)
.body(());
sourcepub fn proxy_mut(&mut self) -> Option<&mut Proxy>
Available on crate feature proxy
only.
pub fn proxy_mut(&mut self) -> Option<&mut Proxy>
proxy
only.get mutable reference to proxy of Task
Examples
let mut task = Task::builder()
.proxy("http://127.0.0.1:1088")
.body(());
task.proxy_mut().unwrap().set_addr("http://127.0.0.1:1080");
assert!(task.proxy().unwrap().addr(), "http://127.0.0.1:1080");
sourceimpl Task
impl Task
sourcepub fn uri(&self) -> &Uri
pub fn uri(&self) -> &Uri
get shared reference to uri of Task
Examples
let task = Task::builder()
.parser(parser_fn)
.body(());
assert_eq!(*task.uri(), *"/");
sourcepub fn method(&self) -> &Method
pub fn method(&self) -> &Method
get shared reference to method of Task
Examples
let task = Task::builder()
.parser(parser_fn)
.body(());
assert_eq!(task.method(), Method::GET);
sourcepub fn headers(&self) -> &HeaderMap<HeaderValue>
pub fn headers(&self) -> &HeaderMap<HeaderValue>
get shared reference to headers of Task
Examples
let task = Task::builder()
.parser(parser_fn)
.body(());
assert!(task.headers().is_empty());
sourcepub fn version(&self) -> Version
pub fn version(&self) -> Version
get headers of Task
Examples
let task = Task::builder()
.parser(parser_fn)
.body(());
assert_eq!(task.version(), Version::HTTP_11);
sourcepub fn exts(&self) -> &Extensions
pub fn exts(&self) -> &Extensions
get shared reference to exts of Task
Examples
let task = Task::builder()
.parser(parser_fn)
.body(());
assert!(task.exts().is_empty());
sourcepub fn extensions(&self) -> &Extensions
pub fn extensions(&self) -> &Extensions
get shared reference to extensions of Task
Examples
struct S {}
let task = Task::builder()
.parser(parser_fn)
.body(());
assert!(task.extensions().get::<S>().is_none());
sourcepub fn parser<E>(&self) -> fn(_: Response) -> Parsed<E> where
E: Serialize + Clone,
pub fn parser<E>(&self) -> fn(_: Response) -> Parsed<E> where
E: Serialize + Clone,
get shared reference to parser of Task
Examples
let task = Task::builder()
.parser(parser_fn)
.body(());
assert_eq!(*task.parser(), parser_fn);
sourcepub fn err_parser<E>(&self) -> fn(_: Response) -> Parsed<E> where
E: Serialize + Clone,
pub fn err_parser<E>(&self) -> fn(_: Response) -> Parsed<E> where
E: Serialize + Clone,
get shared reference to err_parser of Task
Examples
let task = Task::builder()
.parser(parser_fn)
.err_parser(parser_fn)
.body(());
assert_eq!(*task.err_parser(), err_parser_fn);
sourcepub fn rank_mut(&mut self) -> &mut i16
pub fn rank_mut(&mut self) -> &mut i16
get mutable reference to rank of Task
Examples
let task = Task::builder()
.body(());
task.rank_mut() = 3;
assert_eq!(*task.rank_mut(), 3);
sourcepub fn info(&self) -> &Info
pub fn info(&self) -> &Info
get shared reference to info of Task
Examples
let task = Task::builder()
.parser(parser_fn)
.body(());
assert_eq!(task.info().used, 0);
sourcepub fn body(&self) -> &Body
pub fn body(&self) -> &Body
get shared reference to body of Task
Examples
let task = Task::builder()
.parser(parser_fn)
.body(());
assert!(task.body().is_empty());
sourcepub fn uri_mut(&mut self) -> &mut Uri
pub fn uri_mut(&mut self) -> &mut Uri
get mutable reference to uri of Task
Examples
let task = Task::builder()
.parser(parser_fn)
.body(());
let uri = "https://example.com".Into();
task.uri_mut() = uri;
assert_eq!(*task.uri(), uri);
sourcepub fn method_mut(&mut self) -> &mut Method
pub fn method_mut(&mut self) -> &mut Method
get mutable reference to method of Task
Examples
let task = Task::builder()
.parser(parser_fn)
.body(());
let method = Method::POST;
task.method_mut() = method;
assert_eq!(*task.method(), method);
sourcepub fn headers_mut(&mut self) -> &mut HeaderMap<HeaderValue>
pub fn headers_mut(&mut self) -> &mut HeaderMap<HeaderValue>
get mutable reference to headers of Task
Examples
let task = Task::builder()
.parser(parser_fn)
.body(());
task.headers_mut().insert(Method::ACCEPT, "*/*".into());
assert!(!task.headers().is_empty());
sourcepub fn version_mut(&mut self) -> &mut Version
pub fn version_mut(&mut self) -> &mut Version
get mutable reference to version of Task
Examples
let task = Task::builder()
.parser(parser_fn)
.body(());
let version = Version::HTTP_3;
task.version_mut() = version;
assert_eq!(task.version(), version);
sourcepub fn exts_mut(&mut self) -> &mut Extensions
pub fn exts_mut(&mut self) -> &mut Extensions
get mutable reference to exts of Task
Examples
struct S {}
let task = Task::builder()
.parser(parser_fn)
.body(());
let s = S {};
task.exts_mut().insert(s);
assert_eq!(task.exts().get::<S>(), Some(&s));
sourcepub fn extension_mut(&mut self) -> &mut Extensions
pub fn extension_mut(&mut self) -> &mut Extensions
get mutable reference to extensions of Task
Examples
struct S {}
let task = Task::builder()
.parser(parser_fn)
.body(());
let s = S {};
task.extensions_mut().insert(s);
assert_eq!(task.extensions().get::<S>(), Some(&s));
sourcepub fn parser_mut<E>(&mut self, parser: fn(_: Response) -> Parsed<E>) where
E: Serialize + Clone,
pub fn parser_mut<E>(&mut self, parser: fn(_: Response) -> Parsed<E>) where
E: Serialize + Clone,
get mutable reference to parser of Task
Examples
let task = Task::builder()
.parser(parser_fn)
.body(());
task.parser_mut() = new_parser_fn;
assert_eq!(*task.parser(), new_parser_fn);
sourcepub fn err_parser_mut<E>(&mut self, parser: fn(_: Response) -> Parsed<E>) where
E: Serialize + Clone,
pub fn err_parser_mut<E>(&mut self, parser: fn(_: Response) -> Parsed<E>) where
E: Serialize + Clone,
get mutable reference to err_parser of Task
Examples
let task = Task::builder()
.parser(parser_fn)
.body(());
task.err_parser_mut(new_parser_fn);
assert_eq!(*task.parser(), new_parser_fn);
sourcepub fn info_mut(&mut self) -> &mut Info
pub fn info_mut(&mut self) -> &mut Info
get mutable reference to info of Task
Examples
let task = Task::builder()
.parser(parser_fn)
.body(());
task.info_mut().unique = false;
assert_eq!(*task.info_ref().unique, false);
sourcepub fn body_mut(&mut self) -> &mut Body
pub fn body_mut(&mut self) -> &mut Body
get mutable reference to body of Task
Examples
let task = Task::builder()
.parser(parser_fn)
.body(Vec::new());
task.body_mut().extend(vec![1,2,3]);
assert_eq!(*task.body().get::<Vec<i32>>, Some(&vec![1,2,3]));
sourcepub fn into_body(self) -> Body
pub fn into_body(self) -> Body
Consume the task and obtain the body
Examples
let task = Task::builder()
.parser(parser_fn)
.body(Vec::new());
let body = task.into_body()
assert_eq!(body, vec::new());
sourcepub fn map<F>(self, f: F) -> Task where
F: FnOnce(Body) -> Body,
pub fn map<F>(self, f: F) -> Task where
F: FnOnce(Body) -> Body,
Convert the body of the Task
with function
Examples
let task = Task::builder()
.parser(parser_fn)
.body(vec![1,2,3]);
let new_task = task.map(|v| v + 1 );
assert_eq!(new_task.body, vec![2,3,4]);
sourcepub fn from_parts(
inner: InnerTask,
body: Body,
metat: MetaTask,
proxy: Option<Proxy>
) -> Self
pub fn from_parts(
inner: InnerTask,
body: Body,
metat: MetaTask,
proxy: Option<Proxy>
) -> Self
Create new Task
directly with body, inner data, proxy(require feature proxy
enabled)
Examples
let task = Task::builder()
.get("https://example.com")
.parser(parser_fn)
.body(vec![1,2,3]);
let ( mut inner, body, meta ) = task.into_parts();
inner.version = Version::HTTP_3;
let new_task = Task::from_parts(inner, body, meta);
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Task
impl<'de> Deserialize<'de> for Task
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Send for Task
Safety:
since *const () is a static function pointer(a usize that indicating hardware address)
which is Copy
so it owns the data, and no one else has it, the data can be safely transfered
to another thread
impl Sync for Task
Safety:
since *const () is a static function pointer(a usize that indicating hardware address)
which is Copy
so it owns the data, and no one else has it, the data can be safely transfered
to another thread
Auto Trait Implementations
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more