Skip to content

Mut syntax for record fields #2133

@jamorton

Description

@jamorton

Just a random comment, not sure if anything can be done about this.

I think the mutability syntax for records is a bit unreadable.

type cpu_state = {
    regs: [mut u16],
    mut pc: u16,
    mut sp: u16,
    mut o: u16,
    mem: [mut u16],
    mut cycles: uint,
    mut stop: bool
};
fn new_cpu_state() -> cpu_state {
    {
        regs: vec::to_mut(vec::from_elem(8u, 0u16)),
        mut pc: 0u16,
        mut sp: 0u16,
        mut o: 0u16,
        mem: vec::to_mut(vec::from_elem(0x10000u, 0u16)),
        mut cycles: 0u,
        mut stop: false
    }
}

Because the mut comes before the field name, it's quite hard to figure out what the actual fields are called. IMO, name should be on the left and the information associated with it on the right, that seems like a universal thing for structs, dictionaries, etc.

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