1 use std::convert::TryFrom;
2 
3 use ffi::*;
4 use libc::c_int;
5 
6 #[derive(Eq, PartialEq, Clone, Copy, Debug)]
7 pub enum Level {
8     Quiet,
9     Panic,
10     Fatal,
11     Error,
12     Warning,
13     Info,
14     Verbose,
15     Debug,
16     Trace,
17 }
18 
19 pub struct LevelError;
20 
21 impl TryFrom<c_int> for Level {
22     type Error = &'static str;
23 
try_from(value: c_int) -> Result<Self, &'static str>24     fn try_from(value: c_int) -> Result<Self, &'static str> {
25         match value {
26             AV_LOG_QUIET => Ok(Level::Quiet),
27             AV_LOG_PANIC => Ok(Level::Panic),
28             AV_LOG_FATAL => Ok(Level::Fatal),
29             AV_LOG_ERROR => Ok(Level::Error),
30             AV_LOG_WARNING => Ok(Level::Warning),
31             AV_LOG_INFO => Ok(Level::Info),
32             AV_LOG_VERBOSE => Ok(Level::Verbose),
33             AV_LOG_DEBUG => Ok(Level::Debug),
34             AV_LOG_TRACE => Ok(Level::Trace),
35             _ => Err("illegal log level"),
36         }
37     }
38 }
39 
40 impl From<Level> for c_int {
from(value: Level) -> c_int41     fn from(value: Level) -> c_int {
42         match value {
43             Level::Quiet => AV_LOG_QUIET,
44             Level::Panic => AV_LOG_PANIC,
45             Level::Fatal => AV_LOG_FATAL,
46             Level::Error => AV_LOG_ERROR,
47             Level::Warning => AV_LOG_WARNING,
48             Level::Info => AV_LOG_INFO,
49             Level::Verbose => AV_LOG_VERBOSE,
50             Level::Debug => AV_LOG_DEBUG,
51             Level::Trace => AV_LOG_TRACE,
52         }
53     }
54 }
55