Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question: How to create hyper::Response from create image stream? #185

Open
chanble opened this issue Jan 7, 2022 · 2 comments
Open

question: How to create hyper::Response from create image stream? #185

chanble opened this issue Jan 7, 2022 · 2 comments

Comments

@chanble
Copy link

chanble commented Jan 7, 2022

I write like this:

let mut stream = docker_client.create_image(Some(CreateImageOptions{
    from_image: "hello-world",
    ..Default::default()
}), None, None);
HyperResponse::new(HyperBody::wrap_stream(stream))

error:

 the trait `From<CreateImageInfo>` is not implemented for `hyper::body::Bytes`
    |
    = help: the following implementations were found:
              <hyper::body::Bytes as From<&'static [u8]>>
              <hyper::body::Bytes as From<&'static str>>
              <hyper::body::Bytes as From<Box<[u8]>>>
              <hyper::body::Bytes as From<String>>
            and 5 others
    = note: required because of the requirements on the impl of `Into<hyper::body::Bytes>` for `CreateImageInfo`
note: required by a bound in `hyper::Body::wrap_stream`

@fussybeaver
Copy link
Owner

The create_image endpoint deserializes the docker payload into a stream of CreateImageInfo. If you wanted to recreate a new HyperResponse, you would need to serialize each instance back into bytes or text and create a new Hyper::Body out of that. Does that help ?

@chanble
Copy link
Author

chanble commented Jan 12, 2022

Thanks, It works like this.

let stream = docker_client.create_image(create_image_option, None, None);
let stream2 = stream.map(|create_result| match create_result {
    Ok(create_image_info) => {
        println!("create_image_info: {:?}", create_image_info);
        serde_json::to_string(&create_image_info).map_err(BollardError::from)
    }
    Err(err) => {
        println!("create_image_info err: {:?}", err);
        Err(err)
    }
});
HyperResponse::new(HyperBody::wrap_stream(stream2))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants