expression

Check request builder replayability

An in-memory body can be cloned in this example. Streaming bodies may not be cloneable. Replayability is only one part of retry safety; the operation must also permit repetition. External crate example; constructs requests or synthetic responses in memory; no request is sent. Expected stdout (not executed): true Common mistake: Equating a cloneable body with permission to repeat a mutation.

Formal Syntax & Structure

rust syntaxrust
RequestBuilder::try_clone() -> Option<RequestBuilder>

Working Example

Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() {    let c = reqwest::Client::builder().no_proxy().build().unwrap();    let b = c.put("https://example.com/books/1").body("draft");    let second = b.try_clone().unwrap().build().unwrap();    let first = b.build().unwrap();    println!("{}", first.body().unwrap().as_bytes() == second.body().unwrap().as_bytes());}
Rust Reference