如何获取闭包数据

use std::io::{self, Write};
use std::sync::{Arc, Mutex};
use hyper::{Chunk, Client, Error, Uri};
use hyper::rt::{self, Future, Stream};

pub fn run() {

    let fut = do_request().map(move |body|{
        println!("{}", body);
    }).map_err(|err|{
        println!("{:?}", err);
    });

    rt::run(fut);
//    println!("{:?}", body);

    println!("lalala");
    println!("lalala");
    println!("lalala");
    println!("lalala")
}

fn do_request() -> impl Future<Item=String, Error=hyper::error::Error> {
    let client = Client::new();
    client
        .get(Uri::from_static("http://httpbin.org/ip"))
        .and_then(|res| {
            println!("status: {}", res.status());
            res.into_body().concat2()
        })
        .and_then(|body| {
            let s = ::std::str::from_utf8(&body).expect("httpbin sends utf-8 JSON");
            Ok(s.to_string())
        })
        .map_err(|err| {
            err
        })
}

想在外面获取闭包里面的body数据,请问该如何做?

文章来源:

Author:Rust.cc
link:https://rust.cc/article?id=0f6111e3-b057-49e9-80a9-187c28f39498