fix Queue::last
This commit is contained in:
parent
c0623ce64f
commit
88ed1ddafd
@ -24,6 +24,7 @@ impl<T: FromBytes + FromZeroes + AsBytes + Unaligned + Clone + Copy> Slabable fo
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: make this return the bare Queue to avoid additional allocations
|
||||
impl<T: FromBytes + FromZeroes + AsBytes + Unaligned + Clone + Copy> Queue<T> {
|
||||
pub fn new<R>(transaction: &mut TransactionHandle<R>) -> FilePointer<Queue<T>> {
|
||||
let (queue, data) = transaction.allocate();
|
||||
@ -276,7 +277,13 @@ impl<T: FromBytes + FromZeroes + AsBytes + Unaligned + Clone + Copy> FilePointer
|
||||
}
|
||||
|
||||
pub fn last(self, reader: &impl ReaderTrait) -> Option<T> {
|
||||
self.get(reader, self.length(reader) - 1)
|
||||
let length = self.length(reader);
|
||||
|
||||
if length == 0 {
|
||||
None
|
||||
} else {
|
||||
self.get(reader, length - 1)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn length(self, reader: &impl ReaderTrait) -> u64 {
|
||||
|
Loading…
Reference in New Issue
Block a user