fields-in-traits-rfc icon indicating copy to clipboard operation
fields-in-traits-rfc copied to clipboard

Allow constructing structs through associated fields

Open arielb1 opened this issue 7 years ago • 0 comments

This would be useful for rust-lang/rfcs#2102:

#[repr(C)]
pub union _Bindgen_somestruct_Field_0 {
    pad_binder: binder_uintptr_t,
    fd: u32
}

#[repr(C)]
pub union _Bindgen_somestruct_Field_target {
    handle: u32,
    ptr: binder_uintptr_t,
}

#[repr(C)]
pub struct somestruct {
    _Field_0: _Bindgen_somestruct_Field_0,
    target: _Bindgen_somestruct_Field_target
};

impl somestruct {
    unsafe pad_binder: self._Field_0.pad_binder;
    unsafe fd: self._Field_0.fd;
}

fn foo() {
    let somestruct = unsafe { somestruct {
        fd: 2,
        target
    }};
}

arielb1 avatar Aug 10 '17 12:08 arielb1