Skip to content

Commit

Permalink
feature to use core::error::Error instead of std::error::Error (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
ultimaweapon authored Oct 24, 2024
1 parent 6e72c26 commit f5354b6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//!
Expand Down
8 changes: 6 additions & 2 deletions src/stub/error.rs
Original file line number Diff line number Diff line change
@@ -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).
Expand Down Expand Up @@ -145,8 +149,8 @@ where
}
}

#[cfg(feature = "std")]
impl<T, C> std::error::Error for GdbStubError<T, C>
#[cfg(any(feature = "std", feature = "core_error"))]
impl<T, C> CoreError for GdbStubError<T, C>
where
C: Debug + Display,
T: Debug + Display,
Expand Down

0 comments on commit f5354b6

Please sign in to comment.