Struct dyer::Task[][src]

pub struct Task { /* fields omitted */ }
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, a Stream of byte chunks, or a value that has been deserialized.

Implementations

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();

creates a new TaskBuilder initialized with a POST method and URI

Examples
let task = Task::get("https://example.com/")
    .parser(parser_fn)
    .body(())
    .unwrap();

creates a new TaskBuilder initialized with a POST method and URI

Examples
let task = Task::post("https://example.com/")
    .parser(parser_fn)
    .body(());

creates a new TaskBuilder initialized with a PUT method and URI

Examples
let task = Task::put("https://example.com/")
    .parser(parser_fn)
    .body(());

creates a new TaskBuilder initialized with a CONNECT method and URI

Examples
let task = Task::connect("https://example.com/")
    .parser(parser_fn)
    .body(());

creates a new TaskBuilder initialized with a DELETE method and URI

Examples
let request = Task::delete("https://example.com/")
    .parser(parser_fn)
    .body(());

creates a new TaskBuilder initialized with a HEAD method and URI

Examples
let task = Task::head("https://example.com/")
    .parser(parser_fn)
    .body(());

creates a new TaskBuilder initialized with a OPTIONS method and URI

Examples
let task = Task::options("https://example.com/")
    .parser(parser_fn)
    .body(());

creates a new TaskBuilder initialized with a PATCH method and URI

Examples
let task = Task::patch("https://example.com/")
    .parser(parser_fn)
    .body(());

creates a new TaskBuilder initialized with a TRACE method and URI

Examples
let task = Task::trace("https://example.com/")
    .parser(parser_fn)
    .body(());

get shared reference to uri of Task

Examples
let task = Task::builder()
    .parser(parser_fn)
    .body(());
assert_eq!(*task.uri(), *"/");

get shared reference to method of Task

Examples
let task = Task::builder()
    .parser(parser_fn)
    .body(());
assert_eq!(task.method(), Method::GET);

get shared reference to headers of Task

Examples
let task = Task::builder()
    .parser(parser_fn)
    .body(());
assert!(task.headers().is_empty());

get headers of Task

Examples
let task = Task::builder()
    .parser(parser_fn)
    .body(());
assert_eq!(task.version(), Version::HTTP_11);

get shared reference to exts of Task

Examples
let task = Task::builder()
    .parser(parser_fn)
    .body(());
assert!(task.exts().is_empty());

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());

get shared reference to parser of Task

Examples
let task = Task::builder()
    .parser(parser_fn)
    .body(());
assert_eq!(*task.parser(), parser_fn);

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);

get the rank of Task

Examples
let task = Task::builder()
    .body(());
assert_eq!(task.rank(), 0);

get mutable reference to rank of Task

Examples
let task = Task::builder()
    .body(());
task.rank_mut() = 3;
assert_eq!(*task.rank_mut(), 3);

get shared reference to info of Task

Examples
let task = Task::builder()
    .parser(parser_fn)
    .body(());
assert_eq!(task.info().used, 0);

get shared reference to body of Task

Examples
let task = Task::builder()
    .parser(parser_fn)
    .body(());
assert!(task.body().is_empty());

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);

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);

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());

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);

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));

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));

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);

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);

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);

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]));

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());

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]);

Create new Task directly with body, inner data

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);

split Task into body, inner data

Examples
let task = Task::builder()
    .get("https://example.com")
    .parser(parser_fn)
    .body(vec![1,2,3]);
let (_inner, _body, _meta ) = task.into_parts();

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Deserialize this value from the given Serde deserializer. Read more

Performs the conversion.

Performs the conversion.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

Serialize this value into the given Serde serializer. Read more

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more