2019-11-04 00:00:00 +00:00
|
|
|
// check-pass
|
2015-03-22 20:13:15 +00:00
|
|
|
// pretty-expanded FIXME #23616
|
|
|
|
|
2015-06-10 20:33:52 +00:00
|
|
|
use std::mem;
|
2013-08-13 03:18:47 +00:00
|
|
|
|
|
|
|
/// Returns the size of a type
|
2015-03-26 00:06:52 +00:00
|
|
|
pub fn size_of<T>() -> usize {
|
2013-09-02 13:30:00 +00:00
|
|
|
TypeInfo::size_of(None::<T>)
|
2013-08-13 03:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the size of the type that `val` points to
|
2015-03-26 00:06:52 +00:00
|
|
|
pub fn size_of_val<T>(val: &T) -> usize {
|
2013-08-13 03:18:47 +00:00
|
|
|
val.size_of_val()
|
|
|
|
}
|
|
|
|
|
2015-12-15 09:31:58 +00:00
|
|
|
pub trait TypeInfo: Sized {
|
2015-03-26 00:06:52 +00:00
|
|
|
fn size_of(_lame_type_hint: Option<Self>) -> usize;
|
|
|
|
fn size_of_val(&self) -> usize;
|
2013-08-13 03:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> TypeInfo for T {
|
|
|
|
/// The size of the type in bytes.
|
2015-03-26 00:06:52 +00:00
|
|
|
fn size_of(_lame_type_hint: Option<T>) -> usize {
|
2015-06-10 20:33:52 +00:00
|
|
|
mem::size_of::<T>()
|
2013-08-13 03:18:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the size of the type of `self` in bytes.
|
2015-03-26 00:06:52 +00:00
|
|
|
fn size_of_val(&self) -> usize {
|
2013-09-02 13:30:00 +00:00
|
|
|
TypeInfo::size_of(None::<T>)
|
2013-08-13 03:18:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn main() {}
|