Skip to content

Chain::read/write should require T: FromBytes/IntoBytes #1126

@FelixMcFelix

Description

@FelixMcFelix

The current trait bounds here are too lax, allowing the compiler to accept code such as:

fn ctl_test(
    chain: &mut Chain,
    mem: &MemCtx,
) -> Result<(), ()> {
    let mut a = false;
    if !chain.read(&mut a, &mem) {
        return Err(());
    }
    Ok(())
}

I think every use of this API is using well-formed types (so isn't liable to hit UB on an invalid value), but we can rely on the typesystem to keep us right.

The underlying call to MemCtx::read already requires FromBytes, while MemCtx::write requires only Copy. It should probably also require IntoBytes for symmetry.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions