Skip to content

Commit

Permalink
Soft breaking changes developing into the 0.9 series
Browse files Browse the repository at this point in the history
Changes in this PR are technically breaking, but generally compatible in
the sense that they work unless there are either pre-existing unresolved
deprecation warnings, or a type that rarely needs explicit naming was
explicitly named.

Merges: #90
  • Loading branch information
chrysn committed Aug 20, 2024
2 parents 7fb661c + 9928b48 commit 850e8e8
Show file tree
Hide file tree
Showing 30 changed files with 226 additions and 753 deletions.
16 changes: 9 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "riot-wrappers"
version = "0.8.4"
version = "0.8.999" # really 0.9.0-alpha.1, but we also try hard to not break realistic 0.8 users who fixed all deprecation warnings and don't hold things wrong.
authors = ["Christian Amsüss <[email protected]>"]
edition = "2021"
rust-version = "1.75"
Expand Down Expand Up @@ -30,7 +30,7 @@ bare-metal = "1"

cstr = "^0.2.11"

heapless = "^0.7"
heapless = "^0.8"
rand_core_06 = { package = "rand_core", version = "^0.6" }

# For nimble UUID parsing and some debug implementations
Expand All @@ -40,18 +40,20 @@ coap-numbers = "^0.2.0"

embedded-graphics = "0.6"

coap-message-0-2 = { package = "coap-message", version = "^0.2.3" }
coap-message-0-3 = { package = "coap-message", version = "^0.3.0" }
coap-handler-0-1 = { package = "coap-handler", version = "^0.1.4" }
coap-handler-0-2 = { package = "coap-handler", version = "^0.2.0" }
embedded-nal = { version = "0.6.0", optional = true }
embedded-nal-tcpextensions = { version = "0.1", optional = true }
embedded-nal-async = { version = "0.6", optional = true }
embedded-nal-async-0-7 = { package = "embedded-nal-async", version = "0.7.1", optional = true }
embedded-io-async = { version = "0.6", optional = true }
pin-utils = "0.1"
pin-project = "1.0.11"

# as used in embedded-nal 0.6
no-std-net-0-5 = { package = "no-std-net", version = "0.5", optional = true }
# as used in embedded-nal-async
no-std-net-0-6 = { package = "no-std-net", version = "0.6", optional = true }

embedded-hal-async = { version = "1", optional = true }

critical-section = { version = "1.0", optional = true }
Expand Down Expand Up @@ -84,8 +86,8 @@ provide_critical_section_1_0 = ["critical-section/restore-state-u32"]
with_coap_message = []
with_coap_handler = []

with_embedded_nal = ["embedded-nal", "embedded-nal-tcpextensions"]
with_embedded_nal_async = [ "embedded-nal-async", "embedded-io-async", "embedded-nal-async-0-7" ]
with_embedded_nal = ["embedded-nal", "embedded-nal-tcpextensions", "no-std-net-0-5"]
with_embedded_nal_async = [ "embedded-io-async", "embedded-nal-async-0-7", "no-std-net-0-6" ]

with_embedded_hal_async = [ "embedded-hal-async" ]

Expand Down
6 changes: 3 additions & 3 deletions src/adc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::Never;
use core::convert::Infallible;

pub struct ADCLine(riot_sys::adc_t);

Expand Down Expand Up @@ -43,9 +43,9 @@ impl embedded_hal_0_2::adc::Channel<ADC> for ADCLine {
}

impl embedded_hal_0_2::adc::OneShot<ADC, i32, ADCLine> for ADC {
type Error = Never;
type Error = Infallible;

fn read(&mut self, pin: &mut ADCLine) -> nb::Result<i32, Never> {
fn read(&mut self, pin: &mut ADCLine) -> nb::Result<i32, Infallible> {
// Sorry, blocking still
Ok(unsafe { riot_sys::adc_sample(pin.0, self.resolution) })
}
Expand Down
4 changes: 0 additions & 4 deletions src/coap_handler/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
//! This module provides a wrappers around a coap_handler::Handler in different versions, all of
//! which can be registered at a RIOT GcoapHandler.

pub mod v0_1;
pub mod v0_2;

#[deprecated(note = "Use through the v0_1 module.")]
pub use v0_1::*;
115 changes: 0 additions & 115 deletions src/coap_handler/v0_1.rs

This file was deleted.

4 changes: 2 additions & 2 deletions src/coap_handler/v0_2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ impl<H> crate::gcoap::Handler for GcoapHandler<H>
where
H: Handler,
{
fn handle(&mut self, pkt: &mut PacketBuffer) -> isize {
let request_data = self.0.extract_request_data(pkt);
fn handle(&mut self, pkt: PacketBuffer) -> isize {
let request_data = self.0.extract_request_data(&pkt);
let mut lengthwrapped = ResponseMessage::new(pkt);
match request_data {
Ok(r) => {
Expand Down
85 changes: 0 additions & 85 deletions src/coap_message/impl_0_2.rs

This file was deleted.

8 changes: 4 additions & 4 deletions src/coap_message/impl_0_3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ impl<'a> MessageOption for super::MessageOption<'a> {
}
}

impl WithSortedOptions for super::PacketBuffer {
impl<'b> WithSortedOptions for super::PacketBuffer<'b> {
// valid because gcoap just reads options from the message where they are stored in sequence
}

impl ReadableMessage for super::PacketBuffer {
impl<'b> ReadableMessage for super::PacketBuffer<'b> {
type Code = u8;
type OptionsIter<'a> = super::OptionsIterator<'a>;
type MessageOption<'a> = super::MessageOption<'a>;
type OptionsIter<'a> = super::OptionsIterator<'a, 'b> where Self: 'a;
type MessageOption<'a> = super::MessageOption<'a> where Self: 'a;

fn code(&self) -> Self::Code {
self.get_code_raw()
Expand Down
13 changes: 6 additions & 7 deletions src/coap_message/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! This module implements [coap_message::ReadableMessage] for, and a wrapper that provides
//! [coap_message::WritableMessage] around RIOT's coap_pkt_t.

mod impl_0_2;
mod impl_0_3;

use crate::gcoap::{PacketBuffer, PacketBufferOptIter};
Expand All @@ -11,8 +10,8 @@ pub struct MessageOption<'a> {
value: &'a [u8],
}

pub struct OptionsIterator<'a>(PacketBufferOptIter<'a>);
impl<'a> Iterator for OptionsIterator<'a> {
pub struct OptionsIterator<'a, 'b>(PacketBufferOptIter<'a, 'b>);
impl<'a, 'b> Iterator for OptionsIterator<'a, 'b> {
type Item = MessageOption<'a>;

fn next(&mut self) -> Option<Self::Item> {
Expand All @@ -24,15 +23,15 @@ impl<'a> Iterator for OptionsIterator<'a> {
}
}

pub struct ResponseMessage<'a> {
pub struct ResponseMessage<'b> {
/// Note that this is a slightly weird version of PacketBuffer, where opt_finish is never
/// called, and .payload() perpetually reports the payload marker as part of the payload.
message: &'a mut PacketBuffer,
message: PacketBuffer<'b>,
payload_written: Option<usize>,
}

impl<'a> ResponseMessage<'a> {
pub fn new(buf: &'a mut PacketBuffer) -> Self {
impl<'b> ResponseMessage<'b> {
pub fn new(mut buf: PacketBuffer<'b>) -> Self {
// Can't really err; FIXME ensure that such a check won't affect ROM too much
buf.resp_init(5 << 5).unwrap();

Expand Down
6 changes: 1 addition & 5 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ pub trait NegativeErrorExt {
/// manually implemented newtype around isize that'd be used to represent the Result.
#[derive(Debug, PartialEq, Eq)]
pub struct NumericError {
#[deprecated(note = "Use the .number() method")]
pub number: isize,
number: isize,
}

impl NumericError {
Expand Down Expand Up @@ -56,13 +55,11 @@ impl NumericError {
name > 0,
"Error names are expected to be positive for conversion into negative error numbers."
);
#[allow(deprecated)] // it's deprecated *pub*
NumericError { number: -name }
}

/// Numeric value of the error
pub const fn number(&self) -> isize {
#[allow(deprecated)] // it's deprecated *pub*
self.number
}

Expand Down Expand Up @@ -94,7 +91,6 @@ where
if self >= Self::zero() {
Ok(self)
} else {
#[allow(deprecated)] // it's deprecated *pub*
Err(NumericError {
number: self.try_into().unwrap_or(-(riot_sys::EOVERFLOW as isize)),
})
Expand Down
Loading

0 comments on commit 850e8e8

Please sign in to comment.