Rust `the trait bound `Response<()>: Copy` is not satisfied`

58 views Asked by At

Trying to add Response<BoxBody<bytes::Bytes, std::io::Error>> to a hashmap and take it out

Code:

pub async fn router(
    req: Request<hyper::body::Incoming>,
    remote_addr: SocketAddr
) -> hyper::Result<Response<BoxBody<Bytes, std::io::Error>>> {
    let selector = "<a key>";
    let mut funcs = HashMap::new();
    funcs.insert("<a key>", my_async_function(args).await);

    let result = funcs.get(&selector).copied().unwrap();
    Ok(result)
}

Compiler Output:

error[E0277]: the trait bound `Response<BoxBody<bytes::Bytes, std::io::Error>>: Copy` is not satisfied
    --> src\server.rs:22:39
     |
22   |     let result = funcs.get(&selector).copied().unwrap();
     |                                       ^^^^^^ the trait `Copy` is not implemented for `Response<BoxBody<bytes::Bytes, std::io::Error>>`
     |
note: required by a bound in `Option::<&T>::copied`
    --> C:\Users\XXX\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\core\src\option.rs:1863:12
     |
1861 |     pub const fn copied(self) -> Option<T>
     |                  ------ required by a bound in this associated function
1862 |     where
1863 |         T: Copy,
     |            ^^^^ required by this bound in `Option::<&T>::copied`

How to solve?

Tried to use *result instead of .copied but result in Cannot move error

0

There are 0 answers