Implement Display and Error for IteratorError

This commit is contained in:
Sebastian Dröge 2017-12-16 17:48:38 +02:00
parent 7065d1d884
commit f7c971874d

View file

@ -21,6 +21,8 @@ use std::sync::Arc;
use std::ffi::CString; use std::ffi::CString;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::iter::Iterator as StdIterator; use std::iter::Iterator as StdIterator;
use std::fmt;
use std::error::Error;
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)] #[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub enum IteratorError { pub enum IteratorError {
@ -28,6 +30,24 @@ pub enum IteratorError {
Error, Error,
} }
impl fmt::Display for IteratorError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
IteratorError::Resync => write!(f, "Resync"),
IteratorError::Error => write!(f, "Error"),
}
}
}
impl Error for IteratorError {
fn description(&self) -> &str {
match *self {
IteratorError::Resync => "Resync",
IteratorError::Error => "Error",
}
}
}
// Implemented manually so that we can use generics for the item // Implemented manually so that we can use generics for the item
pub struct Iterator<T> { pub struct Iterator<T> {
iter: *mut ffi::GstIterator, iter: *mut ffi::GstIterator,