You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// A newtype wrapper around u32 that guarantees the number is even#[repr(transparent)]pubstructEvenU32(u32);implEvenU32{pubfntry_from_u32_ref(value:&u32) -> Result<&Self,()>{if*value % 2 == 0{Ok(safe_transmute(value))}else{Err(())}}}
To enforce the invariant of the wrapper type, safe_transmute should look at the visibility of the field. For example, the following code in a different module would not work:
// Should not compile, because the `u32` field is inaccessible from the outsidelet _:EvenU32 = safe_transmute(&100);
I'd like to write the following code:
To enforce the invariant of the wrapper type, safe_transmute should look at the visibility of the field. For example, the following code in a different module would not work:
CC @Manishearth
The text was updated successfully, but these errors were encountered: