I have a bytes::Bytes
(in this case its the body of a request in actix-web) and another function that expects a string slice argument: foo: &str
. What is the proper way to convert the bytes::Bytes
to &str
so that no copy is made? I've tried &body.into()
but I get:
the trait `std::convert::From<bytes::bytes::Bytes>` is not implemented for `str`
Here are the basic function signatures:
pub fn parse_body(data: &str) -> Option<&str> {
// Do stuff
// ....
Ok("xyz")
}
fn consume_data(req: HttpRequest<AppState>, body: bytes::Bytes) -> HttpResponse {
let foo = parse_body(&body);
// Do stuff
HttpResponse::Ok().into()
}