Skip to content

Commit 3a7dbc9

Browse files
Remove panic by overflow possibility
Co-authored-by: Collyn O'Kane <47607823+okaneco@users.noreply.github.com>
1 parent 2f9f7d2 commit 3a7dbc9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

palette/src/gradient/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ pub trait ArrayLike : Index<usize>{
2828
}
2929
/// Returns a pointer to the last element of the collection, or None if it is empty.
3030
fn last(&self) -> Option<&Self::Output> {
31-
self.get(self.len() - 1)
31+
if !self.is_empty() {
32+
self.get(self.len() - 1)
33+
} else {
34+
None
35+
}
3236
}
3337
/// Returns true if the collection contains no elements.
3438
fn is_empty(&self) -> bool {

0 commit comments

Comments
 (0)