Skip to content

refactor: remove unwraps from node_table.rs #346

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/node_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,33 @@ impl<'a> NodeTable<'a> {
}

/// Mutable access to node flags.
///
/// # Note
///
/// Internally, we rely on a conversion of u64 to usize.
/// This conversion is fallible on some platforms.
/// If the conversion fails, an empty slice is returned.
pub fn flags_array_mut(&mut self) -> &mut [NodeFlags] {
unsafe {
std::slice::from_raw_parts_mut(
self.table_.flags.cast::<NodeFlags>(),
usize::try_from(self.table_.num_rows).unwrap(),
usize::try_from(self.table_.num_rows).unwrap_or(0),
)
}
}

/// Mutable access to node times.
///
/// # Note
///
/// Internally, we rely on a conversion of u64 to usize.
/// This conversion is fallible on some platforms.
/// If the conversion fails, an empty slice is returned.
pub fn time_array_mut(&mut self) -> &mut [Time] {
unsafe {
std::slice::from_raw_parts_mut(
self.table_.time.cast::<Time>(),
usize::try_from(self.table_.num_rows).unwrap(),
usize::try_from(self.table_.num_rows).unwrap_or(0),
)
}
}
Expand Down