Skip to content

Allow as in match statements #1009

Closed
Closed
@strega-nil

Description

@strega-nil

As in

let ptr = match mmap(...) {
    -1 as *mut c_void => panic!(),
    p => p,
}

This is very useful for FFI and #![no_std], I don't think it takes anything away, and it shouldn't be too difficult to add.

Possibilities right now include

let ptr = match mmap(...) as usize {
    -1 => panic!(),
    p => p as *mut c_void,
}

or

let ptr = match mmap(...) {
    p if p == -1 => panic!(),
    p => p,
}

Another possible idea, one that I doubt many people would like, is to allow *const and *mut pointers to be integrals. Then you could just do the C thing of

let ptr = match mmap(...) {
    -1 => panic!(), // -1 is a *mut c_void in this situation
    p => p,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-langRelevant to the language team, which will review and decide on the RFC.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions