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

feat: update embedded-nal to 0.9 #166

Merged
merged 7 commits into from
Jan 16, 2025
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ This document describes the changes to Minimq between releases.
## Changed
* The `Publication::finish()` API was removed in favor of a new `Publication::respond()` API for
constructing replies to previously received messages.
* [breaking] `embedded-nal` bumped. Now `core::net::SocketAddr` and related ip types are used.
MSRV becomes 1.77.0.

# [0.9.0] - 2024-04-29

Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ readme = "README.md"
categories = ["embedded", "no-std", "database", "encoding"]
keywords = ["mqtt", "embedded", "client"]
license = "MIT"
rust-version = "1.77.0"

[dependencies]
bit_field = "0.10.0"
Expand All @@ -23,7 +24,7 @@ embedded-time = "0.12"
varint-rs = {version = "2.2", default-features = false }
serde = { version = "1", features = ["derive"], default-features = false }
smlang = "0.6.0"
embedded-nal = "0.8"
embedded-nal = "0.9"

[features]
default = []
Expand All @@ -34,4 +35,4 @@ unsecure = []
log = "0.4"
env_logger = "0.10"
std-embedded-time = "0.1"
std-embedded-nal = { git = "https://gitlab.com/ryan-summers/std-embedded-nal", branch = "feature/0.8" }
std-embedded-nal = "0.4.0"
7 changes: 5 additions & 2 deletions src/broker.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use crate::{warn, MQTT_INSECURE_DEFAULT_PORT};
use core::convert::TryFrom;
use embedded_nal::{nb, AddrType, Dns, IpAddr, Ipv4Addr, SocketAddr};
use core::{
convert::TryFrom,
net::{IpAddr, Ipv4Addr, SocketAddr},
};
use embedded_nal::{nb, AddrType, Dns};

/// A type that allows us to (eventually) determine the broker address.
pub trait Broker {
Expand Down
11 changes: 6 additions & 5 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,12 @@ impl<'a, Broker: crate::Broker> ConfigBuilder<'a, Broker> {
mod tests {
use super::*;
use crate::broker::IpBroker;
use core::net::IpAddr;

#[test]
pub fn basic_config() {
let mut buffer = [0; 30];
let localhost: embedded_nal::IpAddr = "127.0.0.1".parse().unwrap();
let localhost: IpAddr = "127.0.0.1".parse().unwrap();
let builder: ConfigBuilder<IpBroker> = ConfigBuilder::new(localhost.into(), &mut buffer);

let config = builder.build();
Expand All @@ -269,7 +270,7 @@ mod tests {
#[test]
pub fn without_session_state() {
let mut buffer = [0; 30];
let localhost: embedded_nal::IpAddr = "127.0.0.1".parse().unwrap();
let localhost: IpAddr = "127.0.0.1".parse().unwrap();
let builder: ConfigBuilder<IpBroker> = ConfigBuilder::new(localhost.into(), &mut buffer)
.session_state(BufferConfig::Exactly(0));

Expand All @@ -282,7 +283,7 @@ mod tests {
#[test]
pub fn with_exact_sizes() {
let mut buffer = [0; 30];
let localhost: embedded_nal::IpAddr = "127.0.0.1".parse().unwrap();
let localhost: IpAddr = "127.0.0.1".parse().unwrap();
let builder: ConfigBuilder<IpBroker> = ConfigBuilder::new(localhost.into(), &mut buffer)
.session_state(BufferConfig::Exactly(8))
.rx_buffer(BufferConfig::Exactly(4))
Expand All @@ -297,7 +298,7 @@ mod tests {
#[test]
pub fn with_max() {
let mut buffer = [0; 30];
let localhost: embedded_nal::IpAddr = "127.0.0.1".parse().unwrap();
let localhost: IpAddr = "127.0.0.1".parse().unwrap();
let builder: ConfigBuilder<IpBroker> = ConfigBuilder::new(localhost.into(), &mut buffer)
.session_state(BufferConfig::Maximum(8));

Expand All @@ -310,7 +311,7 @@ mod tests {
#[test]
pub fn with_min() {
let mut buffer = [0; 30];
let localhost: embedded_nal::IpAddr = "127.0.0.1".parse().unwrap();
let localhost: IpAddr = "127.0.0.1".parse().unwrap();
let builder: ConfigBuilder<IpBroker> = ConfigBuilder::new(localhost.into(), &mut buffer)
.session_state(BufferConfig::Minimum(20));

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
//! // or QoS::ExactlyOnce has not been completed (PUBCOMP).
//! // Connect to a broker at localhost - Use a client ID of "test".
//! let mut buffer = [0; 256];
//! let localhost: embedded_nal::IpAddr = "127.0.0.1".parse().unwrap();
//! let localhost: std::net::IpAddr = "127.0.0.1".parse().unwrap();
//! let mut mqtt: Minimq<'_, _, _, minimq::broker::IpBroker> = Minimq::new(
//! std_embedded_nal::Stack::default(),
//! std_embedded_time::StandardClock::default(),
Expand Down
3 changes: 2 additions & 1 deletion src/network_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
//! stack to be used to transmit buffers that may be stored internally in other structs without
//! violating Rust's borrow rules.
use crate::{message_types::ControlPacket, packets::Pub};
use embedded_nal::{nb, SocketAddr, TcpClientStack, TcpError};
use core::net::SocketAddr;
use embedded_nal::{nb, TcpClientStack, TcpError};
use serde::Serialize;

use crate::{Error, ProtocolError};
Expand Down
2 changes: 1 addition & 1 deletion tests/at_least_once_subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use minimq::{
Minimq, Publication, QoS,
};

use embedded_nal::{self, IpAddr, Ipv4Addr};
use core::net::{IpAddr, Ipv4Addr};
use std_embedded_time::StandardClock;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/deferred_payload.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use minimq::{DeferredPublication, Minimq, QoS};

use embedded_nal::{self, IpAddr, Ipv4Addr};
use core::net::{IpAddr, Ipv4Addr};
use std_embedded_time::StandardClock;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/exactly_once_subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use minimq::{
Minimq, Publication, QoS,
};

use embedded_nal::{self, IpAddr, Ipv4Addr};
use core::net::{IpAddr, Ipv4Addr};
use std_embedded_time::StandardClock;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/exactly_once_transmission.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use minimq::{Minimq, Publication, QoS};

use embedded_nal::{self, IpAddr, Ipv4Addr};
use core::net::{IpAddr, Ipv4Addr};
use std_embedded_time::StandardClock;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_test.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use minimq::{types::Utf8String, Minimq, Property, Publication, QoS, Will};

use embedded_nal::{self, IpAddr, Ipv4Addr};
use core::net::{IpAddr, Ipv4Addr};
use std_embedded_time::StandardClock;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/poll_result.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use minimq::{Minimq, Publication, QoS};

use embedded_nal::{self, IpAddr, Ipv4Addr};
use core::net::{IpAddr, Ipv4Addr};
use std_embedded_time::StandardClock;

#[test]
Expand Down
2 changes: 1 addition & 1 deletion tests/reconnection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use minimq::{
Minimq, Publication, QoS,
};

use embedded_nal::{self, IpAddr, Ipv4Addr};
use core::net::{IpAddr, Ipv4Addr};
use std_embedded_time::StandardClock;

mod stack;
Expand Down
8 changes: 4 additions & 4 deletions tests/stack/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use embedded_nal::{nb, TcpClientStack};
use std::cell::RefCell;
use std::io::{Error, ErrorKind, Read, Write};
use std::net::{SocketAddr, TcpStream};
use std::net::{IpAddr, SocketAddr, TcpStream};

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct TcpHandle {
Expand Down Expand Up @@ -76,8 +76,8 @@ impl TcpSocket {
Self { stream: None }
}

fn connect(&mut self, remote: embedded_nal::SocketAddr) -> Result<(), Error> {
let embedded_nal::IpAddr::V4(addr) = remote.ip() else {
fn connect(&mut self, remote: SocketAddr) -> Result<(), Error> {
let IpAddr::V4(addr) = remote.ip() else {
return Err(Error::new(ErrorKind::Other, "Only IPv4 supported"));
};
let remote = SocketAddr::new(addr.octets().into(), remote.port());
Expand Down Expand Up @@ -109,7 +109,7 @@ impl<'a> TcpClientStack for MitmStack<'a> {
fn connect(
&mut self,
socket: &mut Self::TcpSocket,
remote: embedded_nal::SocketAddr,
remote: SocketAddr,
) -> nb::Result<(), Self::Error> {
let index = self
.sockets
Expand Down
Loading