Skip to content

Problems with SendError #587

Open
Open
@cetra3

Description

@cetra3

There is currently no way to create a SendError which means you have to resort to workarounds as per #401.

I've been trying to use this to stream out a hyper body from a file in a performant fashion.

I've had to adjust the SendError struct to have a public member:

pub struct SendError<T>(pub T);

With that example snippet works:

//file is a FsReadStream from futures-fs
let file = self.fspool.read(path)
    .map(|bytes| {
        Ok(hyper::Chunk::from(bytes))
    })
    .map_err(|err| {
        SendError(Err(hyper::Error::Io(err)))
    });

let (tx, body) = hyper::Body::pair();

//ctx.handle() is a tokio remote handle
ctx.handle().spawn(tx.send_all(file).map(|_| ())
    .map_err(|_| ()));

Response::build().body(body)

If it's not a public field, you need to use the workaround mentioned:

let file = self.fspool.read(path)
    .map(|bytes| {
        Ok(hyper::Chunk::from(bytes))
    })
    .map_err(|err| {
        unimplemented!()
    });

I'm not sure this is the right approach, but I think being able to construct SendErrors would be a good workaround. Is there a reason why it's private? If not I will raise a PR.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions