memcpy() comparison: C, Rust, and D

Tobias Müller via Digitalmars-d digitalmars-d at puremagic.com
Wed Feb 1 22:23:15 PST 2017


Walter Bright <newshound2 at digitalmars.com> wrote:
> On 2/1/2017 9:28 AM, Michael Howell wrote:
>> unsafe fn copy_nonoverlapping_ref<T>(src: &T, dest: &mut T, len: usize) {
>> std::ptr::copy_nonoverlapping(src, dest, len)
>> }
>> 
>> Again, it doesn't guarantee no side effects, it may guarantee that src isn't
>> mutated, it does guarantee that they aren't stored away somewhere, and it
>> guarantees that src and dest don't overlap.
> 
> What part of the signature guarantees non-overlap?

Mutable references cannot overlap in Rust, at least in safe code.
The exact guarantees in unsafe code are not yet clear and currently being
fleshed out.
OTOH using unsafe code in Rust is quite rare.


More information about the Digitalmars-d mailing list