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
use std::error::Error;
type CefResult<T> = Result<String, T>;
pub trait ToCef<T: Error> {
fn to_cef(&self) -> CefResult<T>;
}
#[cfg(test)]
mod test {
use super::*;
use std::fmt::{Display, Formatter, Result as FmtResult};
#[derive(Debug)]
enum CefTestError {
ExampleCase,
}
impl Error for CefTestError {}
impl Display for CefTestError {
fn fmt(&self, f: &mut Formatter) -> FmtResult {
write!(f, "CefTestError: {}", self)
}
}
struct Example {}
impl ToCef<CefTestError> for Example {
fn to_cef(&self) -> CefResult<CefTestError> {
Err(CefTestError::ExampleCase)
}
}
#[test]
fn test_impl() {
let example = Example {};
let result = example.to_cef();
assert!(result.is_err())
}
}