Skip to content

Usage of FnOnce in SinkMapExt::sink_map_err #2108

@twittner

Description

@twittner

SinkMapExt::sink_map_err accepts an FnOnce to map the error type at most once. A second error mapping will cause a panic because the mapping function has been consumed. As far as I can tell this dates back to futures-0.1 times when the Sink API documentation was quite explicit about possible panic conditions, e.g. "This method may panic in a few situations [...] - A previous call to start_send or poll_complete yielded an error." [1]

The current API documentation on the other hand is silent about panics, it only states that "In most cases, if the sink encounters an error, the sink will permanently be unable to receive items." [2] However using sink_map_err on any Sink type effectively prevents client code from calling any of its methods after an error has occurred if avoiding the panic from SinkMapErr is the goal.

Now, my question is ― should the Sink API documentation be updated to better express the panic conditions as it used to be the case, or should SinkMapExt::sink_map_err perhaps be changed to accept an FnMut instead?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-sinkArea: futures::sinkS-needs-decisionStatus: A decision on whether or not to do this is needed.docs

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions