Simplification of @trusted
jfondren
julian.fondren at gmail.com
Fri Jun 25 12:21:56 UTC 2021
On Wednesday, 16 June 2021 at 11:38:54 UTC, RazvanN wrote:
> What do you think?
https://github.com/dlang/phobos/blob/master/std/array.d#L283
```d
auto temp = str.toUTF32;
/* Unsafe cast. Allowed because toUTF32 makes a new array
and copies all the elements.
*/
return () @trusted { return
cast(CopyTypeQualifiers!(ElementType!String, dchar)[]) temp; } ();
```
https://doc.rust-lang.org/src/core/ptr/non_null.rs.html#81-84
```rust
// SAFETY: mem::align_of() returns a non-zero usize which
is then casted
// to a *mut T. Therefore, `ptr` is not null and the
conditions for
// calling new_unchecked() are respected.
unsafe {
let ptr = mem::align_of::<T>() as *mut T;
NonNull::new_unchecked(ptr)
}
```
More information about the Digitalmars-d
mailing list