]>
Commit | Line | Data |
---|---|---|
60c5eb7d | 1 | // check-pass |
c34b1796 AL |
2 | // pretty-expanded FIXME #23616 |
3 | ||
62682a34 | 4 | use std::mem; |
1a4d82fc JJ |
5 | |
6 | /// Returns the size of a type | |
c34b1796 | 7 | pub fn size_of<T>() -> usize { |
1a4d82fc JJ |
8 | TypeInfo::size_of(None::<T>) |
9 | } | |
10 | ||
11 | /// Returns the size of the type that `val` points to | |
c34b1796 | 12 | pub fn size_of_val<T>(val: &T) -> usize { |
1a4d82fc JJ |
13 | val.size_of_val() |
14 | } | |
15 | ||
9cc50fc6 | 16 | pub trait TypeInfo: Sized { |
c34b1796 AL |
17 | fn size_of(_lame_type_hint: Option<Self>) -> usize; |
18 | fn size_of_val(&self) -> usize; | |
1a4d82fc JJ |
19 | } |
20 | ||
21 | impl<T> TypeInfo for T { | |
22 | /// The size of the type in bytes. | |
c34b1796 | 23 | fn size_of(_lame_type_hint: Option<T>) -> usize { |
62682a34 | 24 | mem::size_of::<T>() |
1a4d82fc JJ |
25 | } |
26 | ||
27 | /// Returns the size of the type of `self` in bytes. | |
c34b1796 | 28 | fn size_of_val(&self) -> usize { |
1a4d82fc JJ |
29 | TypeInfo::size_of(None::<T>) |
30 | } | |
31 | } | |
32 | ||
33 | pub fn main() {} |