diff options
| author | Brian Anderson <banderson@mozilla.com> | 2014-05-06 23:33:08 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2014-05-07 14:12:43 -0700 |
| commit | 3a11509e00e5ed27e69522dc456c5b82c29404ef (patch) | |
| tree | 15d689716762a4bcd8e75b2c54a6697bf5c4fabd | |
| parent | a993703f93cdfa210f9e790de6683e86e0204a1a (diff) | |
| download | rust-3a11509e00e5ed27e69522dc456c5b82c29404ef.tar.gz rust-3a11509e00e5ed27e69522dc456c5b82c29404ef.zip | |
std: Reorder definitions in cast
Prioritize `transmute` and `forget`.
| -rw-r--r-- | src/libcore/cast.rs | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/src/libcore/cast.rs b/src/libcore/cast.rs index 25b6fd1b2cf..e0edeb53c6e 100644 --- a/src/libcore/cast.rs +++ b/src/libcore/cast.rs @@ -14,25 +14,6 @@ use mem; use intrinsics; use ptr::copy_nonoverlapping_memory; -/// Casts the value at `src` to U. The two types must have the same length. -#[inline] -pub unsafe fn transmute_copy<T, U>(src: &T) -> U { - let mut dest: U = mem::uninit(); - let dest_ptr: *mut u8 = transmute(&mut dest); - let src_ptr: *u8 = transmute(src); - copy_nonoverlapping_memory(dest_ptr, src_ptr, mem::size_of::<U>()); - dest -} - -/** - * Move a thing into the void - * - * The forget function will take ownership of the provided value but neglect - * to run any required cleanup or memory-management operations on it. - */ -#[inline] -pub unsafe fn forget<T>(thing: T) { intrinsics::forget(thing); } - /** * Transform a value of one type into a value of another type. * Both types must have the same size and alignment. @@ -51,6 +32,25 @@ pub unsafe fn transmute<L, G>(thing: L) -> G { intrinsics::transmute(thing) } +/** + * Move a thing into the void + * + * The forget function will take ownership of the provided value but neglect + * to run any required cleanup or memory-management operations on it. + */ +#[inline] +pub unsafe fn forget<T>(thing: T) { intrinsics::forget(thing); } + +/// Casts the value at `src` to U. The two types must have the same length. +#[inline] +pub unsafe fn transmute_copy<T, U>(src: &T) -> U { + let mut dest: U = mem::uninit(); + let dest_ptr: *mut u8 = transmute(&mut dest); + let src_ptr: *u8 = transmute(src); + copy_nonoverlapping_memory(dest_ptr, src_ptr, mem::size_of::<U>()); + dest +} + /// Coerce an immutable reference to be mutable. #[inline] #[deprecated="casting &T to &mut T is undefined behaviour: use Cell<T>, RefCell<T> or Unsafe<T>"] |
