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
63
64
65
66
67
68
69
70
//! Defines errors which may be returned by [sharedlib](index.html).

use std::io;
use std::path::PathBuf;
use string::error::library_close as library_close_string;
use string::error::library_find_symbol as library_find_symbol_string;
use string::error::library_open as library_open_string;
use string::error::os_error as os_error_string;
use string::error::os_error_failure as os_error_failure_string;

error_chain! {
    types { }

    links { }

    foreign_links {
        io::Error, IoError;
    }

    errors {
        LibraryClose {
            description(library_close_string::description())
            display(
                "{}",
                library_close_string::display_1()
            )
        }

        LibraryFindSymbol(symbol: String) {
            description(library_find_symbol_string::description())
            display(
                "{}{}{}",
                library_find_symbol_string::display_1(),
                symbol,
                library_find_symbol_string::display_2()
            )
        }

        LibraryOpen(path_to_lib: PathBuf) {
            description(library_open_string::description())
            display(
                "{}{}{}",
                library_open_string::display_1(),
                path_to_lib.to_string_lossy(),
                library_open_string::display_2()
            )
        }

        OsError(cause: String, function_called: String) {
            description(os_error_string::description())
            display(
                "{}{}{}{}",
                os_error_string::display_1(),
                function_called,
                os_error_string::display_2(),
                cause
            )
        }

        OsErrorFailure(function_called: String) {
            description(os_error_failure_string::description())
            display(
                "{}{}{}",
                os_error_failure_string::display_1(),
                function_called,
                os_error_failure_string::display_2()
            )
        }
    }
}