Skip to content
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
refactor: remove unwraps from node_table.rs
  • Loading branch information
molpopgen committed Oct 28, 2022
commit aecc704f9c8992b8cee3e8776c9c999fa8936c3c
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