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
use super::Status;
use core::fmt::Debug;

/// Errors emitted from UEFI entry point must propagate erronerous UEFI statuses,
/// and may optionally propagate additional entry point-specific data.
#[derive(Debug)]
pub struct Error<Data: Debug = ()> {
    status: Status,
    data: Data,
}

impl<Data: Debug> Error<Data> {
    /// Create an `Error`.
    pub fn new(status: Status, data: Data) -> Self {
        Self { status, data }
    }

    /// Get error `Status`.
    pub fn status(&self) -> Status {
        self.status
    }

    /// Get error data.
    pub fn data(&self) -> &Data {
        &self.data
    }

    /// Split this error into its inner status and error data
    pub fn split(self) -> (Status, Data) {
        (self.status, self.data)
    }
}

// Errors without error data can be autogenerated from statuses

impl From<Status> for Error<()> {
    fn from(status: Status) -> Self {
        Self { status, data: () }
    }
}

// FIXME: This conversion will go away along with usage of the ucs2 crate

impl From<ucs2::Error> for Error<()> {
    fn from(other: ucs2::Error) -> Self {
        Status::from(other).into()
    }
}