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

Make atomic-waker and serde optional, update heapless #59

Merged
merged 2 commits into from
Nov 14, 2023
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.??.?] - ?
* Added the opt-out `asyncify` feature. Disabling this feature removes the `atomic-waker` dependencies and removes the `utils::asyncify` module.
* The `serde` dependency is now optional.
* Update to `heapless` 0.8

## [0.26.4] - 2023-11-12
* Updated changelog

Expand Down
13 changes: 7 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,27 @@ readme = "README.md"
rust-version = "1.71"

[features]
default = ["std", "use_serde", "use_strum", "use_numenum", "log"]
default = ["std", "use_serde", "use_strum", "use_numenum", "log", "asyncify"]

std = ["alloc", "embedded-io/std", "embedded-io-async?/std", "serde/std", "strum?/std", "num_enum?/std"]
alloc = ["embedded-io/alloc", "embedded-io-async?/alloc", "serde/alloc", "defmt?/alloc"]
nightly = ["embedded-io-async", "embedded-hal-async"]
experimental = []
use_serde = ["enumset/serde", "no-std-net/serde", "heapless/serde"]
use_serde = ["dep:serde", "enumset/serde", "no-std-net/serde", "heapless/serde"]
use_strum = ["strum", "strum_macros"]
use_numenum = ["num_enum"]
defmt = ["dep:defmt", "heapless/defmt", "heapless/defmt-impl", "embedded-io/defmt-03", "embedded-io-async?/defmt-03", "embedded-hal-async?/defmt-03"]
defmt = ["dep:defmt", "heapless/defmt-03", "embedded-io/defmt-03", "embedded-io-async?/defmt-03", "embedded-hal-async?/defmt-03"]
asyncify = ["dep:atomic-waker"]

[dependencies]
heapless = { version = "0.7" }
heapless = { version = "0.8" }
embedded-io = { version = "0.6", default-features = false }
embedded-io-async = { version = "0.6", default-features = false, optional = true }
embedded-hal-async = { version = "=1.0.0-rc.1", default-features = false, optional = true }
log = { version = "0.4", default-features = false, optional = true }
no-std-net = { version = "0.5", default-features = false }
serde = { version = "1", default-features = false, features = ["derive"] }
atomic-waker = { version = "1.1.1", default-features = false }
serde = { version = "1", default-features = false, features = ["derive"], optional = true }
atomic-waker = { version = "1.1.1", default-features = false, optional = true }
enumset = { version = "1", default-features = false }
strum = { version = "0.25", default-features = false, optional = true, features = ["derive"] }
strum_macros = { version = "0.25", optional = true }
Expand Down
4 changes: 3 additions & 1 deletion src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,16 @@ where
}

pub mod headers {
use core::convert::TryFrom;

pub type ContentLenParseBuf = heapless::String<20>;

pub fn content_type(ctype: &str) -> (&str, &str) {
("Content-Type", ctype)
}

pub fn content_len(len: u64, buf: &mut ContentLenParseBuf) -> (&str, &str) {
*buf = ContentLenParseBuf::from(len);
*buf = ContentLenParseBuf::try_from(len).unwrap();

("Content-Length", buf.as_str())
}
Expand Down
11 changes: 7 additions & 4 deletions src/http/server.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use core::fmt::{self, Debug, Display, Write as _};
use core::{
convert::TryInto,
fmt::{self, Debug, Display, Write as _},
};

use crate::io::{Error, Read, Write};

Expand Down Expand Up @@ -222,7 +225,7 @@ pub struct HandlerError(heapless::String<64>);

impl HandlerError {
pub fn new(message: &str) -> Self {
Self(message.into())
Self(message.try_into().unwrap())
}

pub fn message(&self) -> &str {
Expand All @@ -239,10 +242,10 @@ where
E: Debug,
{
fn from(e: E) -> Self {
let mut string: heapless::String<64> = "".into();
let mut string = heapless::String::<64>::new();

if write!(&mut string, "{e:?}").is_err() {
string = "(Error string too big)".into();
string = "(Error string too big)".try_into().unwrap();
}

Self(string)
Expand Down
1 change: 1 addition & 0 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "asyncify")]
pub mod asyncify;
pub mod http;
pub mod io;
Expand Down
11 changes: 6 additions & 5 deletions src/utils/http.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use core::str;
use core::{convert::TryFrom, str};

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
Expand Down Expand Up @@ -101,7 +101,7 @@ impl<'b, const N: usize> Headers<'b, N> {
content_len: u64,
buf: &'b mut heapless::String<20>,
) -> &mut Self {
*buf = heapless::String::<20>::from(content_len);
*buf = heapless::String::<20>::try_from(content_len).unwrap();

self.set("Content-Length", buf.as_str())
}
Expand Down Expand Up @@ -372,6 +372,7 @@ pub mod server {
}

pub mod session {
use core::convert::TryInto;
use core::fmt;
use core::time::Duration;

Expand Down Expand Up @@ -444,7 +445,7 @@ pub mod server {

for entry in &mut *data {
if entry.last_accessed + entry.timeout < current_time {
entry.id = "".into();
entry.id = heapless::String::new();
}
}
}
Expand Down Expand Up @@ -515,7 +516,7 @@ pub mod server {
{
Ok(f(&mut entry.data))
} else if let Some(entry) = data.iter_mut().find(|entry| entry.id == "") {
entry.id = session_id.into();
entry.id = session_id.try_into().unwrap();
entry.data = Default::default();
entry.timeout = self.default_session_timeout;
entry.last_accessed = current_time;
Expand All @@ -537,7 +538,7 @@ pub mod server {
.iter_mut()
.find(|entry| entry.id.as_str() == session_id)
{
entry.id = "".into();
entry.id = heapless::String::new();
true
} else {
false
Expand Down
9 changes: 5 additions & 4 deletions src/wifi.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use core::convert::TryInto;
use core::fmt::Debug;
use core::mem;

Expand Down Expand Up @@ -157,13 +158,13 @@ pub struct AccessPointConfiguration {
impl Default for AccessPointConfiguration {
fn default() -> Self {
Self {
ssid: "iot-device".into(),
ssid: "iot-device".try_into().unwrap(),
ssid_hidden: false,
channel: 1,
secondary_channel: None,
protocols: Protocol::P802D11B | Protocol::P802D11BG | Protocol::P802D11BGN,
auth_method: AuthMethod::None,
password: "".into(),
password: heapless::String::new(),
max_connections: 255,
}
}
Expand Down Expand Up @@ -195,10 +196,10 @@ impl Debug for ClientConfiguration {
impl Default for ClientConfiguration {
fn default() -> Self {
ClientConfiguration {
ssid: "".into(),
ssid: heapless::String::new(),
bssid: None,
auth_method: Default::default(),
password: "".into(),
password: heapless::String::new(),
channel: None,
}
}
Expand Down