Skip to content

Commit 2149b99

Browse files
authored
Merge pull request #7 from engali94/bug/std
#2 Use std feature instead no_std
2 parents f7f8cf0 + a418120 commit 2149b99

7 files changed

Lines changed: 34 additions & 17 deletions

File tree

.github/workflows/ci.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,21 @@ jobs:
4040
if: matrix.rust == 'stable'
4141
run: cargo clippy --all-targets -- -D warnings
4242

43+
- name: Run clippy (no_std)
44+
if: matrix.rust == 'stable'
45+
run: cargo clippy --all-targets --no-default-features -- -D warnings
46+
4347
- name: Build
4448
run: cargo build --verbose
4549

4650
- name: Run tests
4751
run: cargo test --verbose
4852

4953
- name: Run tests (no_std)
50-
run: cargo test --no-default-features --features no_std --verbose
54+
run: cargo test --no-default-features --verbose
55+
56+
- name: Check no_std compilation
57+
run: cargo check --no-default-features --verbose
5158

5259
- name: Run tests (nightly features)
5360
if: matrix.rust == 'nightly'

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ readme = "README.md"
1111
edition = "2021"
1212

1313
[features]
14-
default = []
15-
no_std = []
14+
default = ["std"]
15+
std = []
1616
nightly = []
1717

1818
[dev-dependencies]

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,12 @@ let reference: &str = unsafe { data.ptr.as_ref_unchecked() };
104104

105105
## Features
106106

107-
- **`no_std`**: Works in embedded environments
107+
- **`no_std`**: Works in embedded environments (disable default `std` feature)
108108
- **`nightly`**: Trait object support with nightly Rust
109109

110110
```toml
111111
[dependencies]
112-
movable-ref = { version = "0.1.0", features = ["no_std"] }
112+
movable-ref = { version = "0.1.0", default-features = false }
113113
```
114114
## Performance Benchmarks
115115

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub(crate) enum IntegerOffsetErrorImpl {
1414
Sub(usize, usize),
1515
}
1616

17-
#[cfg(not(feature = "no_std"))]
17+
#[cfg(feature = "std")]
1818
impl std::error::Error for IntegerOffsetError {}
1919

2020
mod fmt {

src/lib.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg_attr(feature = "no_std", no_std)]
1+
#![cfg_attr(not(feature = "std"), no_std)]
22
#![cfg_attr(feature = "nightly", feature(ptr_metadata))]
33
#![allow(clippy::needless_doctest_main)]
44
#![forbid(missing_docs)]
@@ -19,7 +19,17 @@ See the `SelfRef` type documentation for safety information.
1919
2020
### `no_std`
2121
22-
This crate is `no_std` compatible. Enable the `no_std` feature to use without the standard library.
22+
This crate is `no_std` compatible. Disable the `std` feature to use without the standard library.
23+
24+
```toml
25+
# For no_std environments (embedded systems, etc.)
26+
[dependencies]
27+
movable-ref = { version = "0.1.0", default-features = false }
28+
29+
# For std environments (default)
30+
[dependencies]
31+
movable-ref = "0.1.0"
32+
```
2333
2434
## Example
2535
@@ -116,7 +126,7 @@ be invalidated - which occurs when direct pointer modification is impossible
116126
and field offsets remain constant after initialization.
117127
*/
118128

119-
#[cfg(feature = "no_std")]
129+
#[cfg(not(feature = "std"))]
120130
extern crate core as std;
121131

122132
#[cfg(test)]

src/metadata/impls.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ use super::traits::PointerRecomposition;
22
use crate::offset::Ptr;
33
use std::ptr::NonNull;
44

5-
#[cfg(feature = "no_std")]
5+
#[cfg(not(feature = "std"))]
66
extern crate alloc;
7-
#[cfg(feature = "no_std")]
7+
#[cfg(not(feature = "std"))]
88
use alloc::{string::String, vec::Vec};
99

1010
unsafe impl<T: ?Sized> PointerRecomposition for &T {

src/tests.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ mod nightly {
168168

169169
assert_eq!(s.t().value, 42);
170170

171-
#[cfg(not(feature = "no_std"))]
171+
#[cfg(feature = "std")]
172172
{
173173
let debug_str = format!("{:?}", s.t_ref().as_ref());
174174
assert!(debug_str.contains("42"));
@@ -183,7 +183,7 @@ mod nightly {
183183

184184
assert_eq!(s.t().value, 42);
185185

186-
#[cfg(not(feature = "no_std"))]
186+
#[cfg(feature = "std")]
187187
{
188188
let debug_str = format!("{:?}", s.t_ref().as_ref());
189189
assert!(debug_str.contains("42"));
@@ -198,23 +198,23 @@ mod nightly {
198198

199199
assert_eq!(s.t().value, 42);
200200

201-
#[cfg(not(feature = "no_std"))]
201+
#[cfg(feature = "std")]
202202
{
203203
let debug_str = format!("{:?}", s.t_ref().as_ref());
204204
assert!(debug_str.contains("42"));
205205
}
206206
}
207207

208208
#[test]
209-
#[cfg(not(feature = "no_std"))]
209+
#[cfg(feature = "std")]
210210
fn check_trait_object_after_move_heap() {
211211
let s = SelfRefTest::new(TestStruct { value: 42 }, |x| unsafe {
212212
TraitObject::from_mut(x as &mut dyn std::fmt::Debug)
213213
});
214214

215215
assert_eq!(s.t().value, 42);
216216

217-
#[cfg(not(feature = "no_std"))]
217+
#[cfg(feature = "std")]
218218
{
219219
let debug_str = format!("{:?}", s.t_ref().as_ref());
220220
assert!(debug_str.contains("42"));
@@ -224,7 +224,7 @@ mod nightly {
224224

225225
assert_eq!(s.t().value, 42);
226226

227-
#[cfg(not(feature = "no_std"))]
227+
#[cfg(feature = "std")]
228228
{
229229
let debug_str = format!("{:?}", s.t_ref().as_ref());
230230
assert!(debug_str.contains("42"));

0 commit comments

Comments
 (0)