Skip to content

Commit 8a04fb9

Browse files
author
Stjepan Glavina
committed
Add extra methods to error types
1 parent 2d59985 commit 8a04fb9

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/lib.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,24 @@ pub enum PopError {
329329
Closed,
330330
}
331331

332+
impl PopError {
333+
/// Returns `true` if the queue is empty.
334+
pub fn is_empty(&self) -> bool {
335+
match self {
336+
PopError::Empty => true,
337+
PopError::Closed => false,
338+
}
339+
}
340+
341+
/// Returns `true` if the queue is empty and closed.
342+
pub fn is_closed(&self) -> bool {
343+
match self {
344+
PopError::Empty => false,
345+
PopError::Closed => true,
346+
}
347+
}
348+
}
349+
332350
impl error::Error for PopError {}
333351

334352
impl fmt::Debug for PopError {
@@ -359,6 +377,32 @@ pub enum PushError<T> {
359377
Closed(T),
360378
}
361379

380+
impl<T> PushError<T> {
381+
/// Unwraps the item that couldn't be pushed.
382+
pub fn into_inner(self) -> T {
383+
match self {
384+
PushError::Full(t) => t,
385+
PushError::Closed(t) => t,
386+
}
387+
}
388+
389+
/// Returns `true` if the queue is full.
390+
pub fn is_full(&self) -> bool {
391+
match self {
392+
PushError::Full(_) => true,
393+
PushError::Closed(_) => false,
394+
}
395+
}
396+
397+
/// Returns `true` if the queue is closed.
398+
pub fn is_closed(&self) -> bool {
399+
match self {
400+
PushError::Full(_) => false,
401+
PushError::Closed(_) => true,
402+
}
403+
}
404+
}
405+
362406
impl<T: fmt::Debug> error::Error for PushError<T> {}
363407

364408
impl<T: fmt::Debug> fmt::Debug for PushError<T> {

0 commit comments

Comments
 (0)