大多数示例与超打交道时,Request<Body>
要么map(|chunk|{ //do something })
或and_then(|chunk|{ //do something })
然后返回物流,其作品,但现在我想尝试,并返回块或实际的项目流。见下文
pub fn to_struct(body: Body) -> Option<Person> {
let person = body.and_then(|chunk|{
let body = std::str::from_utf8(&chunk).unwrap();
let results: Person = serde_json::from_str(&body).unwrap();
Ok(results)
});
// match person or if let
// return Some or None
// Don't wan't to Body::wrap_stream(person) then return Response<Body>
}
streams do nothing unless polled
现在我想轮询以下流并返回结果。await
也许可以解决我相信的问题,但是我正在使用锈病马able。我希望,poll()
但是我会收到NotReady
。请告知。
您正在尝试同步使用hyper,从本质上说hyper并不是为此而设计的,并且需要一层抽象,您应该看一下这个问题
There is no documentation specifically to that effect. Since
you'd need to block the thread at a certain point in execution
until it is ready, you'd need the work of the event loop to occur
in another thread, and send the results over a channel that you
block on.
Alternatively, you can look at reqwest, which even with the hyper
upgrade (not quite released to crate.io, but super soon), it
still offers a synchronous API besides the new async API.
注意:reqwest
现已在crate.io上发布
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句