Skip to content

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

Closed

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.

Activity

  1. iximeow commented on Apr 29, 2026

    @iximeow
    Member

    (done in #1130)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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