1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use std::ffi::{CString, NulError};
use std::{fmt, io};
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("Couldn't convert to a CString")]
CStringConversion(#[source] NulError),
#[error("Couldn't open the file")]
FileOpen(#[source] io::Error),
#[error("Couldn't read the file")]
FileRead(#[source] io::Error),
#[error("Path isn't valid Unicode")]
PathInvalidUnicode,
#[error("An error occurred in VSScript")]
VSScript(#[source] VSScriptError),
#[error("There's no such variable")]
NoSuchVariable,
#[error("Couldn't get the core")]
NoCore,
#[error("There's no output on the requested index")]
NoOutput,
#[error("Couldn't get the VapourSynth API")]
NoAPI,
}
impl From<NulError> for Error {
#[inline]
fn from(x: NulError) -> Self {
Error::CStringConversion(x)
}
}
impl From<VSScriptError> for Error {
#[inline]
fn from(x: VSScriptError) -> Self {
Error::VSScript(x)
}
}
pub(crate) type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Debug)]
pub struct VSScriptError(CString);
impl fmt::Display for VSScriptError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.0.to_string_lossy())
}
}
impl VSScriptError {
#[inline]
pub(crate) fn new(message: CString) -> Self {
VSScriptError(message)
}
}