userspace/
result.rs

1result!(
2    Ok;
3    "Human Ok";
4    usize;
5    [
6        [1; USERSPACE_DEFAULT_OK; Default; usize; "ZE"; "Entry to ze"],
7        [2; USERSPACE_TARGET_OK; Target; crate::target::Ok; "ZE"; "Entry to ze"],
8        [3; STDOUT; StdoutOk; usize; "ZE"; "Entry to ze"],
9    ];
10    Error;
11    "Human error";
12    usize;
13    [
14        [1; ERROR; Error; usize; "ZE"; "Entry to ze"],
15        [2; USERSPACE_TARGET_ERR; Target; crate::target::Error; "ZE"; "Entry to ze"],
16    ]
17);
18
19impl Ok {
20    pub fn from_no(no: usize) -> Self {
21        Ok::Default(no)
22    }
23}
24
25impl Error {
26    pub fn from_no(no: usize) -> Self {
27        Error::Error(no)
28    }
29}
30
31pub type Result = core::result::Result<Ok, Error>;
32
33pub fn handle_result(result: usize) -> Result {
34    if (result as isize) < 0 {
35        Err(Error::from_no(result))
36    } else {
37        Ok(Ok::from_no(result))
38    }
39}
40
41// // use result::ErrorTrait;
42
43// pub mod error {
44//     define_error!("ELF", []);
45// }
46
47// // define_error_nested! (
48// //     "ELF",
49// //     [
50// //         [0; Elf;     self::error;     ERR_ELF;     "Local error";   "ERR_ELF"],
51// //         // [1; DType;   crate::dtype;    ERR_DTYPE;   "Datatype erro"; "ERR_DTYPE"],
52// //         [2; Human;   human::result;   ERR_HUMAN;   "Human error";   "ERR_HUMAN"],
53// //         [3; Syscall; syscall::result; ERR_SYSCALL; "Syscall error"; "ERR_SYSCALL"]
54// //     ]
55// // );
56
57// pub mod macro_types {
58//     #[allow(non_camel_case_types)]
59//     pub type Mi8 = *const i8;
60//     pub type elf_error = super::error::Error;
61//     pub type dtype_error = crate::dtype::Error;
62// }
63
64// mod ok {
65//     enum_typed!(Ok; usize; "AT_TYPE"; crate::result::macro_types; [
66//         [0;    Null;            usize;  |p: Franco| { *p as usize };     AT_NULL;          "Null";          "End of vector"],
67//         [1;    Ignore;          usize;  |p: Franco| { *p as usize };     AT_IGNORE;        "Ignore";        "Entry should be ignored"],
68//     ]);
69// }
70
71// error_typed!("ELF Type"; crate::result::macro_types; [
72//    [0; Elf;     elf_error; p; { elf_error::from_ptr(p) };  { p.to_no() as Franco };                ERR_ELF; "ERR_ELF";   "ERR_ELF"],
73//    [1; DType; dtype_error; p; { dtype_error::from_ptr(p)}; { p as *const dtype_error as Franco}; ERR_DTYPE; "ERR_DTYPE"; "ERR_DTYPE"],
74// ]);
75
76// pub type Result = core::result::Result<ok::Ok, Error>;