Skip to content

Commit 4dab854

Browse files
committed
rename use_.. features
this resolves the [C-FEATURE] finding from the API guidelines which states: > Do not include words in the name of a Cargo feature that convey zero > meaning, as in `use-abc` or `with-abc`. Name the feature `abc` > directly. note that this is a breaking change for existing consumers which must rename their usage of the feature. [C-FEATURE]: https://rust-lang.github.io/api-guidelines/naming.html#c-feature
1 parent abe2f20 commit 4dab854

File tree

6 files changed

+26
-25
lines changed

6 files changed

+26
-25
lines changed

.github/workflows/CI.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ jobs:
1414
fail-fast: false
1515
matrix:
1616
rust: [1.81.0, stable]
17-
features: ['use_alloc', 'use_alloc,defmt', 'use_heapless', 'use_heapless,defmt']
17+
features: ['alloc', 'alloc,defmt', 'heapless', 'heapless,defmt']
1818
exclude:
1919
- rust: 1.81.0
20-
features: 'use_alloc,defmt'
20+
features: 'alloc,defmt'
2121
- rust: 1.81.0
22-
features: 'use_heapless,defmt'
22+
features: 'heapless,defmt'
2323
runs-on: ubuntu-latest
2424
steps:
2525
- uses: actions/checkout@v4

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased] - ReleaseDate
99
### Changed
1010
* The MSRV has been updated to 1.81.0 due to `core::error::Error` being implemented
11+
* **BREAKING**: the features `use_alloc` and `use_heapless` have been renamed to `alloc` and `heapless` respectively.
1112

1213
## [0.2.0] - 2023-11-14
1314
### Added

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ serde = { version = "1.0", features = ["derive"], optional = true }
2020
[features]
2121
default = ["accelerometer_event", "button_event", "color_event", "gyro_event", "location_event", "magnetometer_event", "quaternion_event"]
2222

23-
use_heapless = ["dep:heapless"]
24-
use_alloc = []
23+
heapless = ["dep:heapless"]
24+
alloc = []
2525

2626
defmt = ["dep:defmt", "heapless?/defmt-03"]
2727

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Note that this work is not affiliated with Adafruit.
1111

1212
## Mandatory Features
1313
This crate is `no_std` and you can choose whether you want to use
14-
[`heapless::Vec`](https://docs.rs/heapless/0.8.0/heapless/struct.Vec.html) by selecting the feature `use_heapless` or
15-
[`alloc::vec::Vec`](https://doc.rust-lang.org/alloc/vec/struct.Vec.html) by selecting the feature `use_alloc`.
14+
[`heapless::Vec`](https://docs.rs/heapless/0.8.0/heapless/struct.Vec.html) by selecting the feature `heapless` or
15+
[`alloc::vec::Vec`](https://doc.rust-lang.org/alloc/vec/struct.Vec.html) by selecting the feature `alloc`.
1616
If you select neither or both you'll get a compile error.
1717

1818
## Optional Features

examples/stm32f4-event-printer/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmt = "0.3.6"
1717
defmt-rtt = "0.4"
1818

1919
# use `adafruit-bluefruit-protocol = "0.1"` in reality; path used here to ensure that the example always compiles against the latest master
20-
adafruit-bluefruit-protocol = { path = "../..", features = ["defmt", "use_heapless"] }
20+
adafruit-bluefruit-protocol = { path = "../..", features = ["defmt", "heapless"] }
2121

2222
[profile.release]
2323
codegen-units = 1

src/lib.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
)))]
3030
compile_error!("at least one event type must be selected in the features!");
3131

32-
#[cfg(not(any(feature = "use_alloc", feature = "use_heapless")))]
33-
compile_error!("you must choose either 'use_alloc' or 'use_heapless' as a feature!");
32+
#[cfg(not(any(feature = "alloc", feature = "heapless")))]
33+
compile_error!("you must choose either 'alloc' or 'heapless' as a feature!");
3434

35-
#[cfg(all(feature = "use_alloc", feature = "use_heapless"))]
36-
compile_error!("you must choose either 'use_alloc' or 'use_heapless' as a feature but not both!");
35+
#[cfg(all(feature = "alloc", feature = "heapless"))]
36+
compile_error!("you must choose either 'alloc' or 'heapless' as a feature but not both!");
3737

3838
#[cfg(feature = "accelerometer_event")]
3939
pub mod accelerometer_event;
@@ -59,12 +59,12 @@ use color_event::ColorEvent;
5959
use core::cmp::min;
6060
#[cfg(feature = "gyro_event")]
6161
use gyro_event::GyroEvent;
62-
#[cfg(feature = "use_heapless")]
62+
#[cfg(feature = "heapless")]
6363
use heapless::Vec;
6464

65-
#[cfg(feature = "use_alloc")]
65+
#[cfg(feature = "alloc")]
6666
extern crate alloc;
67-
#[cfg(feature = "use_alloc")]
67+
#[cfg(feature = "alloc")]
6868
use alloc::vec::Vec;
6969
use core::error::Error;
7070
use core::fmt::{Display, Formatter};
@@ -207,17 +207,17 @@ impl TryFrom<u8> for ControllerDataPackageType {
207207
}
208208
}
209209

210-
#[cfg(feature = "use_heapless")]
210+
#[cfg(feature = "heapless")]
211211
type ParseResult<const MAX_RESULTS: usize> =
212212
Vec<Result<ControllerEvent, ProtocolParseError>, MAX_RESULTS>;
213213

214-
#[cfg(feature = "use_alloc")]
214+
#[cfg(feature = "alloc")]
215215
type ParseResult<const MAX_RESULTS: usize> = Vec<Result<ControllerEvent, ProtocolParseError>>;
216-
#[cfg(feature = "use_alloc")]
216+
#[cfg(feature = "alloc")]
217217
const MAX_RESULTS: usize = 0;
218218

219219
/// Parse the input string for commands. Unexpected content will be ignored if it's not formatted like a command!
220-
pub fn parse<#[cfg(feature = "use_heapless")] const MAX_RESULTS: usize>(
220+
pub fn parse<#[cfg(feature = "heapless")] const MAX_RESULTS: usize>(
221221
input: &[u8],
222222
) -> ParseResult<MAX_RESULTS> {
223223
/// Simple state machine for the parser, represents whether the parser is seeking a start or has found it.
@@ -239,11 +239,11 @@ pub fn parse<#[cfg(feature = "use_heapless")] const MAX_RESULTS: usize>(
239239
}
240240
ParserState::ParseCommand => {
241241
let data_package = extract_and_parse_command(&input[(pos - 1)..]);
242-
#[cfg(feature = "use_alloc")]
242+
#[cfg(feature = "alloc")]
243243
result.push(data_package);
244-
#[cfg(feature = "use_heapless")]
244+
#[cfg(feature = "heapless")]
245245
result.push(data_package).ok();
246-
#[cfg(feature = "use_heapless")]
246+
#[cfg(feature = "heapless")]
247247
if result.len() == MAX_RESULTS {
248248
return result;
249249
}
@@ -399,9 +399,9 @@ mod tests {
399399
#[test]
400400
fn test_parse() {
401401
let input = b"\x00!B11:!B10;\x00\x00!\x00\x00\x00\x00!B138";
402-
#[cfg(feature = "use_heapless")]
402+
#[cfg(feature = "heapless")]
403403
let result = parse::<4>(input);
404-
#[cfg(feature = "use_alloc")]
404+
#[cfg(feature = "alloc")]
405405
let result = parse(input);
406406

407407
assert_eq!(result.len(), 4);
@@ -413,7 +413,7 @@ mod tests {
413413
e,
414414
&ProtocolParseError::ButtonParseError(ButtonParseError::UnknownButtonState(b'3'))
415415
);
416-
#[cfg(feature = "use_alloc")]
416+
#[cfg(feature = "alloc")]
417417
{
418418
use alloc::string::ToString;
419419
use core::error::Error;

0 commit comments

Comments
 (0)