Skip to content

Dynamic dispatch through traits requires a managed pointer #8804

@zeux

Description

@zeux

I'm trying to write a function that reads 4 bytes from the reader using Reader trait and dynamic dispatch. This code:

fn readbytes(reader: &std::io::Reader) -> ~[u8] { reader.read_bytes(4) }

results in this error:

<anon>:5:59: 5:81 error: failed to find an implementation of trait std::io::Reader for &std::io::Reader<no-bounds>

The error message is confusing; nevertheless, replacing borrowed pointer with a managed one makes the code compile:

fn readbytes(reader: @std::io::Reader) -> ~[u8] { reader.read_bytes(4) }

However, requiring a managed pointer for dynamic dispatch seems excessive. Is this a bug?

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