adaptivegrain/vapoursynth/src/node/errors.rs
2019-05-30 11:06:53 +00:00

37 lines
846 B
Rust

use std::borrow::Cow;
use std::error::Error;
use std::ffi::CStr;
use std::fmt;
/// A container for a `get_frame` error.
#[derive(Debug)]
pub struct GetFrameError<'a>(Cow<'a, CStr>);
impl<'a> fmt::Display for GetFrameError<'a> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.0.to_string_lossy())
}
}
impl<'a> Error for GetFrameError<'a> {
#[inline]
fn description(&self) -> &str {
"VapourSynth error"
}
}
impl<'a> GetFrameError<'a> {
/// Creates a new `GetFrameError` with the given error message.
#[inline]
pub(crate) fn new(message: Cow<'a, CStr>) -> Self {
GetFrameError(message)
}
/// Consumes this error, returning its underlying error message.
#[inline]
pub fn into_inner(self) -> Cow<'a, CStr> {
self.0
}
}