Skip to content

Commit

Permalink
Update heapless
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Nov 14, 2023
1 parent f6e3b8d commit f6f729f
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ experimental = []
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 }
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
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

0 comments on commit f6f729f

Please sign in to comment.