forked from FuelLabs/sway
-
Notifications
You must be signed in to change notification settings - Fork 0
/
intrinsics.sw
92 lines (89 loc) · 1.58 KB
/
intrinsics.sw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//! Exposes compiler intrinsics as stdlib wrapper functions.
library;
/// Returns whether a generic type `T` is a reference type or not.
///
/// # Returns
///
/// * [bool] - `true` if `T` is a reference type, `false` otherwise.
///
/// # Examples
///
/// ```sway
/// use std::intrinsics::is_reference_type;
///
/// fn foo() {
/// let a = 1;
/// assert(is_reference_type(a))
/// }
/// ```
pub fn is_reference_type<T>() -> bool {
__is_reference_type::<T>()
}
/// Returns the size of a generic type `T` in bytes.
///
/// # Returns
///
/// * [u64] - The size of `T` in bytes.
///
/// # Examples
///
/// ```sway
/// use std::intrinsics::size_of;
///
/// fn foo() {
/// assert(size_of::<u64>() == 8);
/// }
/// ```
///
/// ```sway
/// use std::intrinsics::size_of;
///
/// pub struct Foo {
/// a: u64,
/// b: u64,
/// }
///
/// fn foo() {
/// assert(size_of::<Foo>() == 16);
/// }
/// ```
pub fn size_of<T>() -> u64 {
__size_of::<T>()
}
/// Returns the size of the type of a value in bytes.
///
/// # Arguments
///
/// * `val` - The value to get the size of.
///
/// # Returns
///
/// * [u64] - The size of the type of `val` in bytes.
///
/// # Examples
///
/// ```sway
/// use std::intrinsics::size_of_val;
///
/// fn foo() {
/// let a = 1;
/// assert(size_of_val(a) == 8);
/// }
/// ```
///
/// ```sway
/// use std::intrinsics::size_of_val;
///
/// pub struct Foo {
/// a: u64,
/// b: u64,
/// }
///
/// fn foo() {
/// let a = Foo { a: 1, b: 2 };
/// assert(size_of_val(a) == 16);
/// }
/// ```
pub fn size_of_val<T>(val: T) -> u64 {
__size_of_val::<T>(val)
}