|
1 |
| -// this crate can use `std` in tests only |
2 |
| -#![cfg_attr(not(test), no_std)] |
| 1 | +#![no_std] |
| 2 | + |
| 3 | +#![cfg_attr(feature = "unstable", feature(error_in_core))] |
| 4 | + |
3 | 5 | #![deny(missing_debug_implementations)]
|
4 | 6 | // --- BEGIN STYLE CHECKS ---
|
5 | 7 | // These checks are optional in CI for PRs, as discussed in
|
6 | 8 | // https://github.com/rust-osdev/multiboot2/pull/92
|
7 | 9 | #![deny(clippy::all)]
|
8 | 10 | #![deny(rustdoc::all)]
|
9 |
| -// Forcing this would be a little bit ridiculous, because it would require code examples for |
10 |
| -// each getter and each trivial trait implementation (like Debug). |
11 |
| -#![allow(rustdoc::missing_doc_code_examples)] |
12 | 11 | // --- END STYLE CHECKS ---
|
13 | 12 |
|
14 | 13 | //! Library that helps you to parse the multiboot information structure (mbi) from
|
|
40 | 39 | extern crate std;
|
41 | 40 |
|
42 | 41 | use core::fmt;
|
| 42 | +use derive_more::Display; |
43 | 43 |
|
44 | 44 | pub use boot_loader_name::BootLoaderNameTag;
|
45 | 45 | pub use command_line::CommandLineTag;
|
@@ -161,19 +161,25 @@ pub unsafe fn load_with_offset(
|
161 | 161 |
|
162 | 162 | /// Error type that describes errors while loading/parsing a multiboot2 information structure
|
163 | 163 | /// from a given address.
|
164 |
| -#[derive(Debug)] |
| 164 | +#[derive(Debug, Display)] |
165 | 165 | pub enum MbiLoadError {
|
166 | 166 | /// The address is invalid. Make sure that the address is 8-byte aligned,
|
167 | 167 | /// according to the spec.
|
| 168 | + #[display(fmt = "The address is invalid")] |
168 | 169 | IllegalAddress,
|
169 | 170 | /// The total size of the multiboot2 information structure must be a multiple of 8.
|
170 | 171 | /// (Not in spec, but it is implicitly the case, because the begin of MBI
|
171 | 172 | /// and all tags are 8-byte aligned and the end tag is exactly 8 byte long).
|
| 173 | + #[display(fmt = "The size of the MBI is unexpected")] |
172 | 174 | IllegalTotalSize(u32),
|
173 | 175 | /// End tag missing. Each multiboot2 header requires to have an end tag.
|
| 176 | + #[display(fmt = "There is no end tag")] |
174 | 177 | NoEndTag,
|
175 | 178 | }
|
176 | 179 |
|
| 180 | +#[cfg(feature = "unstable")] |
| 181 | +impl core::error::Error for MbiLoadError {} |
| 182 | + |
177 | 183 | /// A Multiboot 2 Boot Information struct.
|
178 | 184 | pub struct BootInformation {
|
179 | 185 | inner: *const BootInformationInner,
|
@@ -1435,4 +1441,13 @@ mod tests {
|
1435 | 1441 | core::mem::transmute::<[u8; 16], EFIMemoryMapTag>([0u8; 16]);
|
1436 | 1442 | }
|
1437 | 1443 | }
|
| 1444 | + |
| 1445 | + #[test] |
| 1446 | + #[cfg(feature = "unstable")] |
| 1447 | + /// This test succeeds if it compiles. |
| 1448 | + fn mbi_load_error_implements_error() { |
| 1449 | + fn consumer<E: core::error::Error>(_e: E) { |
| 1450 | + } |
| 1451 | + consumer(MbiLoadError::IllegalAddress) |
| 1452 | + } |
1438 | 1453 | }
|
0 commit comments