Skip to content

Commit

Permalink
Use ? instead of match
Browse files Browse the repository at this point in the history
Signed-off-by: Justus Fluegel <[email protected]>
  • Loading branch information
JustusFluegel committed Mar 5, 2024
1 parent 1f08009 commit f8b8b77
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/distributions/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,7 @@ impl<'a, T> Slice<'a, T> {
/// Create a new `Slice` instance which samples uniformly from the slice.
/// Returns `Err` if the slice is empty.
pub fn new(slice: &'a [T]) -> Result<Self, EmptySlice> {
let len = match NonZeroUsize::new(slice.len()) {
None => return Err(EmptySlice),
Some(len) => len,
};
let len = NonZeroUsize::new(slice.len()).ok_or(EmptySlice)?;

Ok(Self {
slice,
Expand Down

0 comments on commit f8b8b77

Please sign in to comment.