Skip to content

Add Bytes::try_unsplit() #287

Open
Open
@abonander

Description

@abonander

I see APIs have been proposed like this before but all I want is a method to try to unsplit a Bytes as I think that should be possible in many cases, and if it fails the user can choose to perform a copy:

 impl Bytes {
    /// If `self` and `other` are adjacent in the underlying buffer, widen `self` to encompass both slices.
    pub fn try_unsplit(&mut self, other: Bytes) -> Result<(),  Bytes> { ... }
}

if let Err(other) = bytes.try_unsplit(other) {
    bytes.extend_from_slice(&other);
}

I'd like it to take self by mutable reference as that's generally more versatile and matches the signature of BytesMut::unsplit().

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions