util/error: refactor error handling

This commit is contained in:
meh
2015-05-24 18:51:34 +02:00
parent 2716893612
commit 5b80b10949
13 changed files with 205 additions and 101 deletions

View File

@ -30,7 +30,7 @@ impl Context {
unsafe {
match avcodec_open2(self.ptr, codec.ptr, ptr::null_mut()) {
0 => Ok(Opened(self)),
e => Err(Error::new(e))
e => Err(Error::from(e))
}
}
}
@ -39,7 +39,7 @@ impl Context {
unsafe {
match avcodec_open2(self.ptr, codec.ptr, &mut options.ptr) {
0 => Ok(Opened(self)),
e => Err(Error::new(e))
e => Err(Error::from(e))
}
}
}
@ -49,7 +49,7 @@ impl Context {
self.clone().open(codec).and_then(|c| c.decoder())
}
else {
Err(Error::from(AVERROR_DECODER_NOT_FOUND))
Err(Error::DecoderNotFound)
}
}
@ -58,7 +58,7 @@ impl Context {
self.clone().open(codec).and_then(|c| c.encoder())
}
else {
Err(Error::from(AVERROR_ENCODER_NOT_FOUND))
Err(Error::EncoderNotFound)
}
}
@ -169,7 +169,7 @@ impl Opened {
Ok(Decoder(self))
}
else {
Err(Error::from(AVERROR_INVALIDDATA))
Err(Error::InvalidData)
}
}
@ -184,7 +184,7 @@ impl Opened {
Ok(Encoder(self))
}
else {
Err(Error::from(AVERROR_INVALIDDATA))
Err(Error::InvalidData)
}
}
}