diff --git a/Cargo.toml b/Cargo.toml index d11ca2e..2fbec6e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,6 +34,7 @@ alloc = ["managed/alloc"] std = ["alloc"] trace-pkt = ["alloc"] paranoid_unsafe = [] +core_error = [] # INTERNAL: enables the `__dead_code_marker!` macro. # used as part of the `scripts/test_dead_code_elim.sh` diff --git a/README.md b/README.md index a00d356..232787b 100644 --- a/README.md +++ b/README.md @@ -120,6 +120,8 @@ When using `gdbstub` in `#![no_std]` contexts, make sure to set `default-feature - Add a `TargetError::Io` variant to simplify `std::io::Error` handling from Target methods. - `paranoid_unsafe` - Please refer to the [`unsafe` in `gdbstub`](#unsafe-in-gdbstub) section below for more details. +- `core_error` + - Make `GdbStubError` implement [`core::error::Error`](https://doc.rust-lang.org/core/error/trait.Error.html) instead of `std::error::Error`. ## Examples diff --git a/src/lib.rs b/src/lib.rs index 2f4dd49..fa74449 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,6 +27,9 @@ //! - `paranoid_unsafe` //! - Please refer to the [`unsafe` in `gdbstub`](https://github.com/daniel5151/gdbstub#unsafe-in-gdbstub) //! section of the README.md for more details. +//! - `core_error` +//! - Make `GdbStubError` implement [`core::error::Error`](https://doc.rust-lang.org/core/error/trait.Error.html) +//! instead of `std::error::Error`. //! //! ## Getting Started //! diff --git a/src/stub/error.rs b/src/stub/error.rs index 8cdc18e..b05b872 100644 --- a/src/stub/error.rs +++ b/src/stub/error.rs @@ -1,9 +1,13 @@ use crate::protocol::PacketParseError; use crate::protocol::ResponseWriterError; use crate::util::managed_vec::CapacityError; +#[cfg(feature = "core_error")] +use core::error::Error as CoreError; use core::fmt::Debug; use core::fmt::Display; use core::fmt::{self}; +#[cfg(all(feature = "std", not(feature = "core_error")))] +use std::error::Error as CoreError; /// An error that may occur while interacting with a /// [`Connection`](crate::conn::Connection). @@ -145,8 +149,8 @@ where } } -#[cfg(feature = "std")] -impl std::error::Error for GdbStubError +#[cfg(any(feature = "std", feature = "core_error"))] +impl CoreError for GdbStubError where C: Debug + Display, T: Debug + Display,