userspace/
result.rs

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