Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename feature embedded_hal to embedded-hal-02 #47

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/quickstart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ jobs:
- run: cargo test
- run: cargo test --no-default-features
- run: cargo test --no-default-features --features=alloc
- run: cargo test --no-default-features --features=embedded_hal
- run: cargo test --no-default-features --features=embedded_hal,alloc
- run: cargo test --no-default-features --features=embedded_hal,alloc,std
- run: cargo test --no-default-features --features=embedded_hal,alloc,std,serde
- run: cargo test --no-default-features --features=embedded-hal-02
- run: cargo test --no-default-features --features=embedded-hal-02,alloc
- run: cargo test --no-default-features --features=embedded-hal-02,alloc,std
- run: cargo test --no-default-features --features=embedded-hal-02,alloc,std,serde

build_examples:
name: Build Examples
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Decoder improvements (#43)
- **BREAKING:** Renamed `*Reader` types to `*ByteSource` (e.g. `IoReader` to `IoByteSource`) (#45)
- Refactored `ByteSourceErr` trait (#46)
- **BREAKING:** Renamed feature `embedded_hal` to `embedded-hal-02` (#47)


## [0.4.0] - 2024-06-04
Expand Down
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ edition = "2021"
default = ["std"]
std = ["alloc"]
alloc = []
embedded_hal = ["nb", "embedded-hal"]
embedded-hal-02 = ["nb", "dep:embedded-hal-02"]
serde = ["dep:serde"]

[dependencies]
crc = "3.0.0"
embedded-hal = { version = "0.2.7", optional = true }
nb = { version = "1.1.0", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
crc = "3"
embedded-hal-02 = { version = "0.2", package = "embedded-hal", optional = true }
nb = { version = "1", optional = true }
serde = { version = "1", features = ["derive"], optional = true }

[dev-dependencies]
insta = { version = "1.21.0", features = ["yaml", "glob"] }
Expand Down
26 changes: 13 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! # Feature flags
//! - **`std`** (default) — Remove this feature to make the library `no_std` compatible.
//! - **`alloc`** (default) — Implementations using allocations (`alloc::Vec` et al.).
//! - **`embedded_hal`** — Allows using pins implementing `embedded_hal::serial::Read` in [`SmlReader`](SmlReader::from_eh_reader).
//! - **`embedded-hal-02`** — Allows using pins implementing `embedded_hal::serial::Read` in [`SmlReader`](SmlReader::from_eh_reader).
//! - **`nb`** - Enables non-blocking APIs using the `nb` crate.
//! - **`serde`** - Implements `Serialize` and `Deserialize` on most error types.
//!
Expand Down Expand Up @@ -279,7 +279,7 @@ impl DummySmlReader {

/// Build an `SmlReader` from a type implementing `embedded_hal::serial::Read<u8>`.
///
/// *This function is available only if sml-rs is built with the `"embedded-hal"` feature.*
/// *This function is available only if sml-rs is built with the `"embedded-hal-02"` feature.*
///
/// # Examples
///
Expand All @@ -288,18 +288,18 @@ impl DummySmlReader {
/// // usually provided by hardware abstraction layers (HALs) for specific chips
/// // let pin = ...;
/// # struct Pin;
/// # impl embedded_hal::serial::Read<u8> for Pin {
/// # impl embedded_hal_02::serial::Read<u8> for Pin {
/// # type Error = ();
/// # fn read(&mut self) -> nb::Result<u8, Self::Error> { Ok(123) }
/// # }
/// # let pin = Pin;
///
/// let reader = SmlReader::from_eh_reader(pin);
/// ```
#[cfg(feature = "embedded_hal")]
#[cfg(feature = "embedded-hal-02")]
pub fn from_eh_reader<R, E>(reader: R) -> SmlReader<util::EhByteSource<R, E>, DefaultBuffer>
where
R: embedded_hal::serial::Read<u8, Error = E>,
R: embedded_hal_02::serial::Read<u8, Error = E>,
{
SmlReader {
decoder: DecoderReader::new(util::EhByteSource::new(reader)),
Expand Down Expand Up @@ -429,7 +429,7 @@ where
///
/// Using `nb::Result` allows this method to be awaited using the `nb::block!` macro.
///
/// *This function is available only if sml-rs is built with the `"nb"` or `"embedded_hal"` features.*
/// *This function is available only if sml-rs is built with the `"nb"` or `"embedded-hal-02"` features.*
#[cfg(feature = "nb")]
pub fn read_nb<'i, T>(&'i mut self) -> nb::Result<T, T::Error>
where
Expand Down Expand Up @@ -463,7 +463,7 @@ where
///
/// Using `nb::Result` allows this method to be awaited using the `nb::block!` macro.
///
/// *This function is available only if sml-rs is built with the `"nb"` or `"embedded_hal"` features.*
/// *This function is available only if sml-rs is built with the `"nb"` or `"embedded-hal-02"` features.*
#[cfg(feature = "nb")]
pub fn next_nb<'i, T>(&'i mut self) -> nb::Result<Option<T>, T::Error>
where
Expand Down Expand Up @@ -518,7 +518,7 @@ impl<Buf: Buffer> SmlReaderBuilder<Buf> {

/// Build an `SmlReader` from a type implementing `embedded_hal::serial::Read<u8>`.
///
/// *This function is available only if sml-rs is built with the `"embedded-hal"` feature.*
/// *This function is available only if sml-rs is built with the `"embedded-hal-02"` feature.*
///
/// # Examples
///
Expand All @@ -527,16 +527,16 @@ impl<Buf: Buffer> SmlReaderBuilder<Buf> {
/// // usually provided by hardware abstraction layers (HALs) for specific chips
/// // let pin = ...;
/// # struct Pin;
/// # impl embedded_hal::serial::Read<u8> for Pin {
/// # impl embedded_hal_02::serial::Read<u8> for Pin {
/// # type Error = ();
/// # fn read(&mut self) -> nb::Result<u8, Self::Error> { Ok(123) }
/// # }
/// # let pin = Pin;
///
/// let reader = SmlReader::with_static_buffer::<1024>().from_eh_reader(pin);
/// ```
#[cfg(feature = "embedded_hal")]
pub fn from_eh_reader<R: embedded_hal::serial::Read<u8, Error = E>, E>(
#[cfg(feature = "embedded-hal-02")]
pub fn from_eh_reader<R: embedded_hal_02::serial::Read<u8, Error = E>, E>(
self,
reader: R,
) -> SmlReader<util::EhByteSource<R, E>, Buf> {
Expand Down Expand Up @@ -697,11 +697,11 @@ fn test_smlreader_construction() {
}

#[test]
#[cfg(feature = "embedded_hal")]
#[cfg(feature = "embedded-hal-02")]
fn test_smlreader_eh_construction() {
// dummy struct implementing `Read`
struct Pin;
impl embedded_hal::serial::Read<u8> for Pin {
impl embedded_hal_02::serial::Read<u8> for Pin {
type Error = i16;

fn read(&mut self) -> nb::Result<u8, Self::Error> {
Expand Down
4 changes: 2 additions & 2 deletions src/transport/decoder_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ where
///
/// Using `nb::Result` allows this method to be awaited using the `nb::block!` macro.
///
/// *This function is available only if sml-rs is built with the `"nb"` or `"embedded_hal"` features.*
/// *This function is available only if sml-rs is built with the `"nb"` or `"embedded-hal-02"` features.*
#[cfg(feature = "nb")]
pub fn read_nb(&mut self) -> nb::Result<&[u8], ReadDecodedError<R::ReadError>> {
self.read().map_err(|e| match e {
Expand All @@ -130,7 +130,7 @@ where
///
/// Using `nb::Result` allows this method to be awaited using the `nb::block!` macro.
///
/// *This function is available only if sml-rs is built with the `"nb"` or `"embedded_hal"` features.*
/// *This function is available only if sml-rs is built with the `"nb"` or `"embedded-hal-02"` features.*
#[cfg(feature = "nb")]
pub fn next_nb(&mut self) -> nb::Result<Option<&[u8]>, ReadDecodedError<R::ReadError>> {
match self.read_nb() {
Expand Down
23 changes: 13 additions & 10 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,28 +245,28 @@ impl ByteSourceErr for std::io::Error {
impl private::Sealed for std::io::Error {}

/// Wraps types that implement `embedded_hal::serial::Read<...>` and implements `ByteSource`
#[cfg(feature = "embedded_hal")]
#[cfg(feature = "embedded-hal-02")]
pub struct EhByteSource<R, E>
where
R: embedded_hal::serial::Read<u8, Error = E>,
R: embedded_hal_02::serial::Read<u8, Error = E>,
{
inner: R,
}

#[cfg(feature = "embedded_hal")]
#[cfg(feature = "embedded-hal-02")]
impl<R, E> EhByteSource<R, E>
where
R: embedded_hal::serial::Read<u8, Error = E>,
R: embedded_hal_02::serial::Read<u8, Error = E>,
{
pub(crate) fn new(reader: R) -> Self {
EhByteSource { inner: reader }
}
}

#[cfg(feature = "embedded_hal")]
#[cfg(feature = "embedded-hal-02")]
impl<R, E> ByteSource for EhByteSource<R, E>
where
R: embedded_hal::serial::Read<u8, Error = E>,
R: embedded_hal_02::serial::Read<u8, Error = E>,
{
type ReadError = nb::Error<E>;

Expand All @@ -275,10 +275,13 @@ where
}
}

#[cfg(feature = "embedded_hal")]
impl<R, E> private::Sealed for EhByteSource<R, E> where R: embedded_hal::serial::Read<u8, Error = E> {}
#[cfg(feature = "embedded-hal-02")]
impl<R, E> private::Sealed for EhByteSource<R, E> where
R: embedded_hal_02::serial::Read<u8, Error = E>
{
}

#[cfg(feature = "embedded_hal")]
#[cfg(feature = "embedded-hal-02")]
impl<E> ByteSourceErr for nb::Error<E> {
fn kind(&self) -> ErrKind {
match self {
Expand All @@ -288,7 +291,7 @@ impl<E> ByteSourceErr for nb::Error<E> {
}
}

#[cfg(feature = "embedded_hal")]
#[cfg(feature = "embedded-hal-02")]
impl<E> private::Sealed for nb::Error<E> {}

/// Error type indicating that the end of the input has been reached
Expand Down