Skip to content

I/O traits should be object safe #3833

@tcharding

Description

@tcharding

The std::io traits we mimic are object safe so it seems ours should be also.

I would expect this to build but it does not because of our take() implementation.

#[test]
fn object_safety() {
    // Sanity check, these are all object safe.
    struct StdlibTraits {
        p: Box<dyn std::io::Read>,
        q: Box<dyn std::io::Write>,
        r: Box<dyn std::io::BufRead>,
    }
    // If this builds then our three traits are object safe also.
    struct OurTraits {
        p: Box<dyn Read>,
        q: Box<dyn Write>,
        r: Box<dyn BufRead>,

    }
}

Clue: We may need a where clause.

    /// Constructs a new adapter which will read at most `limit` bytes.
    #[inline]
    fn take(&mut self, limit: u64) -> Take<Self>
    where
        Self: Sized,
    {
        Take { reader: self, remaining: limit }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    1.0Issues and PRs required or helping to stabilize the APIC-ioPRs modifying the io crate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions