Skip to content

Commit 8655a5a

Browse files
committed
Add std feature to allow implementing Error trait
1 parent 8c17287 commit 8655a5a

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,15 @@ More complex demos welcome!
118118

119119
# Features
120120

121+
- `full`<sup>&dagger;</sup>: do not compile Capstone C library in
122+
[diet mode](https://www.capstone-engine.org/diet.html)
123+
- `std`<sup>&dagger;</sup>: enable `std`-only features, such as the
124+
[`Error` trait](https://doc.rust-lang.org/std/error/trait.Error.html)
121125
- `use_bindgen`: run `bindgen` to generate Rust bindings to Capstone C library
122126
instead of using pre-generated bindings (not recommended).
123127

128+
<sup>&dagger;</sup>: enabled by default
129+
124130
# Reporting Issues
125131

126132
Please open a [Github issue](https://github.com/capstone-rust/capstone-rs/issues)

capstone-rs/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ name = "my_benchmark"
2828
harness = false
2929

3030
[features]
31-
default = ["full"]
31+
default = ["full", "std"]
32+
std = []
3233
# The 'full' feature, enabled by default, compiles Capstone normally. When disabled,
3334
# Capstone will be built in Diet mode (https://www.capstone-engine.org/diet.html).
3435
# This disables some features to reduce the size of the library

capstone-rs/src/error.rs

+4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ capstone_error_def!(
7272
=> UnsupportedX86Masm = CS_ERR_X86_MASM;
7373
);
7474

75+
// Required until https://github.com/rust-lang/rust/issues/103765 is resolved
76+
#[cfg(feature = "std")]
77+
impl std::error::Error for Error {}
78+
7579
pub type CsResult<T> = result::Result<T, Error>;
7680

7781
impl fmt::Display for Error {

capstone-rs/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#![doc = include_str!("../../README.md")]
2-
#![no_std]
2+
#![cfg_attr(not(feature = "std"), no_std)]
33

44
// The `vec` macro cannot be imported directly since it conflicts with the `vec` module
55
#[allow(unused_imports)]
66
#[macro_use]
77
extern crate alloc;
88

9-
#[cfg(test)]
9+
#[cfg(any(test, not(feature = "std")))]
1010
#[macro_use]
1111
extern crate std;
1212

13-
#[cfg(test)]
13+
#[cfg(any(test, not(feature = "std")))]
1414
#[global_allocator]
1515
static ALLOCATOR: std::alloc::System = std::alloc::System;
1616

0 commit comments

Comments
 (0)