Permalink
Browse files
Add an evil ObjectClass::cast() helper
- Loading branch information...
Showing
with
9 additions
and
0 deletions.
-
+9
−0
hdf5-rs/src/class.rs
|
|
@@ -1,4 +1,6 @@ |
|
|
|
use std::fmt; |
|
|
|
use std::mem; |
|
|
|
use std::ptr; |
|
|
|
|
|
|
|
use crate::internal_prelude::*; |
|
|
|
|
|
|
@@ -48,6 +50,13 @@ pub trait ObjectClass: Sized { |
|
|
|
&mut *(self as *mut Self as *mut T) |
|
|
|
} |
|
|
|
|
|
|
|
unsafe fn cast<T: ObjectClass>(self) -> T { |
|
|
|
// This method requires you to be 18 years or older to use it |
|
|
|
let obj = ptr::read(&self as *const _ as *const _); |
|
|
|
mem::forget(self); |
|
|
|
obj |
|
|
|
} |
|
|
|
|
|
|
|
fn debug_fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
|
|
|
// TODO: this can moved out if/when specialization lands in stable |
|
|
|
h5lock!({ |
|
|
|
0 comments on commit
9103597