Skip to content

Commit aecc704

Browse files
committed
refactor: remove unwraps from node_table.rs
1 parent 6539cbf commit aecc704

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/node_table.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,21 +109,33 @@ impl<'a> NodeTable<'a> {
109109
}
110110

111111
/// Mutable access to node flags.
112+
///
113+
/// # Note
114+
///
115+
/// Internally, we rely on a conversion of u64 to usize.
116+
/// This conversion is fallible on some platforms.
117+
/// If the conversion fails, an empty slice is returned.
112118
pub fn flags_array_mut(&mut self) -> &mut [NodeFlags] {
113119
unsafe {
114120
std::slice::from_raw_parts_mut(
115121
self.table_.flags.cast::<NodeFlags>(),
116-
usize::try_from(self.table_.num_rows).unwrap(),
122+
usize::try_from(self.table_.num_rows).unwrap_or(0),
117123
)
118124
}
119125
}
120126

121127
/// Mutable access to node times.
128+
///
129+
/// # Note
130+
///
131+
/// Internally, we rely on a conversion of u64 to usize.
132+
/// This conversion is fallible on some platforms.
133+
/// If the conversion fails, an empty slice is returned.
122134
pub fn time_array_mut(&mut self) -> &mut [Time] {
123135
unsafe {
124136
std::slice::from_raw_parts_mut(
125137
self.table_.time.cast::<Time>(),
126-
usize::try_from(self.table_.num_rows).unwrap(),
138+
usize::try_from(self.table_.num_rows).unwrap_or(0),
127139
)
128140
}
129141
}

0 commit comments

Comments
 (0)