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
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
// Implement traits for typed offset structs.
macro_rules! impl_offset {
($type:ident, $type_int:expr, $name:expr) => {
impl TypedOffsetMethods for $type {
#[inline]
fn type_int() -> u8 {
$type_int
}
#[inline]
fn from_offset_unchecked(offset: Offset) -> Self {
$type(offset)
}
#[inline]
fn to_offset(&self) -> Offset {
self.0
}
}
impl Deref for $type {
type Target = Offset;
#[inline]
fn deref(&self) -> &Offset {
&self.0
}
}
impl Debug for $type {
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
if self.is_null() {
write!(f, "None")
} else {
if self.is_dirty() {
write!(f, "{}[{}]", $name, self.dirty_index())
} else {
// `Offset` will print "Disk[{}]".
self.0.fmt(f)
}
}
}
}
impl From<$type> for Offset {
#[inline]
fn from(x: $type) -> Offset {
x.0
}
}
impl From<$type> for u64 {
#[inline]
fn from(x: $type) -> u64 {
(x.0).0
}
}
impl From<$type> for usize {
#[inline]
fn from(x: $type) -> usize {
(x.0).0 as usize
}
}
};
}