Skip to content

Commit

Permalink
update heapless (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarfu authored Nov 9, 2023
1 parent 27c1264 commit e73a15c
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 40 deletions.
4 changes: 2 additions & 2 deletions atat/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ embedded-io-async = { version = "0.6.0", optional = true }
futures = { version = "0.3", default-features = false, optional = true }
embassy-sync = "0.4.0"
embassy-time = "0.1"
heapless = { version = "^0.7", features = ["serde"] }
heapless = { version = "^0.8", features = ["serde"] }
serde_at = { path = "../serde_at", version = "^0.20.0", optional = true }
atat_derive = { path = "../atat_derive", version = "^0.20.0", optional = true }
serde_bytes = { version = "0.11.5", default-features = false, optional = true }
Expand All @@ -41,7 +41,7 @@ tokio = { version = "1", features = ["macros", "rt"] }

[features]
default = ["derive", "bytes"]
defmt = ["dep:defmt", "embedded-io-async/defmt-03"]
defmt = ["dep:defmt", "embedded-io-async/defmt-03", "heapless/defmt-03"]
derive = ["atat_derive", "serde_at"]
bytes = ["heapless-bytes", "serde_bytes"]
custom-error-messages = []
Expand Down
4 changes: 2 additions & 2 deletions atat/src/blocking/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,15 +413,15 @@ mod test {
Ok(TestResponseString {
socket: 22,
length: 16,
data: String::<64>::from("0123456789012345")
data: String::<64>::try_from("0123456789012345").unwrap()
}),
client.send(&cmd0),
);
assert_eq!(
Ok(TestResponseStringMixed {
socket: 22,
length: 16,
data: String::<64>::from("0123456789012345")
data: String::<64>::try_from("0123456789012345").unwrap()
}),
client.send(&cmd1),
);
Expand Down
23 changes: 14 additions & 9 deletions atat/src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ mod tests {
assert_eq!(
LengthTester {
x: 8,
y: String::from("SomeString"),
y: String::try_from("SomeString").unwrap(),
z: 2,
w: "whatup",
a: SimpleEnum::A,
Expand All @@ -230,7 +230,7 @@ mod tests {
assert_eq!(SimpleEnumU32::try_from(1), Ok(SimpleEnumU32::B));
assert_eq!(
to_string::<_, 1>(&MixedEnum::UnitVariant, "CMD", SerializeOptions::default()).unwrap(),
String::<1>::from("0")
String::<1>::try_from("0").unwrap()
);
assert_eq!(
to_string::<_, 10>(
Expand All @@ -239,16 +239,21 @@ mod tests {
SerializeOptions::default()
)
.unwrap(),
String::<10>::from("1,15")
String::<10>::try_from("1,15").unwrap()
);
assert_eq!(
to_string::<_, 50>(
&MixedEnum::AdvancedTuple(25, String::from("testing"), -54, SimpleEnumU32::A),
&MixedEnum::AdvancedTuple(
25,
String::try_from("testing").unwrap(),
-54,
SimpleEnumU32::A
),
"CMD",
SerializeOptions::default()
)
.unwrap(),
String::<50>::from("2,25,\"testing\",-54,0")
String::<50>::try_from("2,25,\"testing\",-54,0").unwrap()
);
assert_eq!(
to_string::<_, 10>(
Expand All @@ -257,22 +262,22 @@ mod tests {
SerializeOptions::default()
)
.unwrap(),
String::<10>::from("3,35")
String::<10>::try_from("3,35").unwrap()
);

assert_eq!(
to_string::<_, 50>(
&MixedEnum::AdvancedStruct {
a: 77,
b: String::from("whaat"),
b: String::try_from("whaat").unwrap(),
c: 88,
d: SimpleEnum::B
},
"CMD",
SerializeOptions::default()
)
.unwrap(),
String::<50>::from("4,77,\"whaat\",88,1")
String::<50>::try_from("4,77,\"whaat\",88,1").unwrap()
);

assert_eq!(Ok(MixedEnum::UnitVariant), from_str::<MixedEnum<'_>>("0"));
Expand All @@ -283,7 +288,7 @@ mod tests {
assert_eq!(
Ok(MixedEnum::AdvancedTuple(
251,
String::from("deser"),
String::try_from("deser").unwrap(),
-43,
SimpleEnumU32::C
)),
Expand Down
2 changes: 1 addition & 1 deletion atat/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
//! fn parse(&self, resp: Result<&[u8], InternalError>) -> Result<Self::Response, Error> {
//! // Parse resp into `GreetingText`
//! Ok(GreetingText {
//! text: String::from(core::str::from_utf8(resp.unwrap()).unwrap()),
//! text: String::try_from(core::str::from_utf8(resp.unwrap()).unwrap()).unwrap(),
//! })
//! }
//! }
Expand Down
20 changes: 10 additions & 10 deletions atat/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl<const L: usize> AtatCmd<L> for String<L> {
fn parse(&self, resp: Result<&[u8], InternalError>) -> Result<Self::Response, Error> {
let utf8_string =
core::str::from_utf8(resp.map_err(Error::from)?).map_err(|_| Error::Parse)?;
Ok(String::from(utf8_string))
String::try_from(utf8_string).map_err(|_| Error::Parse)

Check warning on line 104 in atat/src/traits.rs

View workflow job for this annotation

GitHub Actions / clippy

matching over `()` is more explicit

warning: matching over `()` is more explicit --> atat/src/traits.rs:104:48 | 104 | String::try_from(utf8_string).map_err(|_| Error::Parse) | ^ help: use `()` instead of `_`: `()` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#ignored_unit_patterns
}
}

Expand Down Expand Up @@ -200,9 +200,9 @@ mod test {
let mut v = Vec::<_, 3>::from_slice(&[
PDPContextDefinition {
cid: 2,
pdp_type: String::from("IP"),
apn: String::from("em"),
pdp_addr: String::from("100.92.188.66"),
pdp_type: String::try_from("IP").unwrap(),
apn: String::try_from("em").unwrap(),
pdp_addr: String::try_from("100.92.188.66").unwrap(),
d_comp: 0,
h_comp: 0,
ipv4_addr_alloc: Some(0),
Expand All @@ -212,9 +212,9 @@ mod test {
},
PDPContextDefinition {
cid: 1,
pdp_type: String::from("IP"),
apn: String::from("STATREAL"),
pdp_addr: String::from("0.0.0.0"),
pdp_type: String::try_from("IP").unwrap(),
apn: String::try_from("STATREAL").unwrap(),
pdp_addr: String::try_from("0.0.0.0").unwrap(),
d_comp: 0,
h_comp: 0,
ipv4_addr_alloc: None,
Expand All @@ -224,9 +224,9 @@ mod test {
},
PDPContextDefinition {
cid: 3,
pdp_type: String::from("IP"),
apn: String::from("tim.ibox.it"),
pdp_addr: String::from("0.0.0.0"),
pdp_type: String::try_from("IP").unwrap(),
apn: String::try_from("tim.ibox.it").unwrap(),
pdp_addr: String::try_from("0.0.0.0").unwrap(),
d_comp: 0,
h_comp: 0,
ipv4_addr_alloc: None,
Expand Down
2 changes: 1 addition & 1 deletion serde_at/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ name = "serde_at"
version = "0.20.0"

[dependencies]
heapless = { version = "^0.7", features = ["serde"] }
heapless = { version = "^0.8", features = ["serde"] }
serde = { version = "^1", default-features = false }

[dependencies.num-traits]
Expand Down
2 changes: 1 addition & 1 deletion serde_at/src/de/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ mod tests {
assert_eq!(
crate::from_str("+CCID: \"89883030000005421166\""),
Ok(StringTest {
string: String::from("89883030000005421166")
string: String::try_from("89883030000005421166").unwrap()
})
);
}
Expand Down
27 changes: 13 additions & 14 deletions serde_at/src/ser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,7 @@ where
T: ser::Serialize + ?Sized,
{
let vec: Vec<u8, N> = to_vec(value, cmd, options)?;
Ok(String::from(unsafe {
core::str::from_utf8_unchecked(&vec)
}))
Ok(unsafe { String::from_utf8_unchecked(vec) })
}

/// Serializes the given data structure as a byte vector
Expand Down Expand Up @@ -569,14 +567,14 @@ mod tests {
)
.unwrap();

assert_eq!(s, String::<32>::from("4,15"));
assert_eq!(s, String::<32>::try_from("4,15").unwrap());
}

#[test]
fn newtype_struct() {
let s: String<32> = to_string(&Handle(15), "", SerializeOptions::default()).unwrap();

assert_eq!(s, String::<32>::from("15"));
assert_eq!(s, String::<32>::try_from("15").unwrap());
}

#[test]
Expand All @@ -590,7 +588,7 @@ mod tests {

let s: String<32> = to_string(&value, "+CMD", SerializeOptions::default()).unwrap();

assert_eq!(s, String::<32>::from("AT+CMD\r\n"));
assert_eq!(s, String::<32>::try_from("AT+CMD\r\n").unwrap());
}

#[test]
Expand All @@ -604,7 +602,7 @@ mod tests {

let s: String<32> = to_string(&value, "+CMD", SerializeOptions::default()).unwrap();

assert_eq!(s, String::<32>::from("AT+CMD=\"value\"\r\n"));
assert_eq!(s, String::<32>::try_from("AT+CMD=\"value\"\r\n").unwrap());
}

#[test]
Expand All @@ -618,7 +616,7 @@ mod tests {
s: Bytes::new(&slice[..]),
};
let s: String<32> = to_string(&b, "+CMD", SerializeOptions::default()).unwrap();
assert_eq!(s, String::<32>::from("AT+CMD=Some bytes\r\n"));
assert_eq!(s, String::<32>::try_from("AT+CMD=Some bytes\r\n").unwrap());
}

#[test]
Expand All @@ -639,7 +637,7 @@ mod tests {

let s: String<32> = to_string(&value, "+CMD", SerializeOptions::default()).unwrap();

assert_eq!(s, String::<32>::from("AT+CMD=\"value\"\r\n"));
assert_eq!(s, String::<32>::try_from("AT+CMD=\"value\"\r\n").unwrap());
}

#[test]
Expand Down Expand Up @@ -729,9 +727,9 @@ mod tests {
let s: String<600> = to_string(&params, "+CMD", options).unwrap();
assert_eq!(
s,
String::<600>::from(
String::<600>::try_from(
"AT+CMD=0x0000FF00,000055AA,0x000000ff,0000aa55,0x0:0:0:0:F:F:0:0,00-00-55-AA,0x0:0:0:0:0:0:f:f,00-00-00-00-aa-55-00-ff\r\n"
)
).unwrap()
);

let params = WithHexStr {
Expand Down Expand Up @@ -807,9 +805,10 @@ mod tests {
let s: String<600> = to_string(&params, "+CMD", options).unwrap();
assert_eq!(
s,
String::<600>::from(
String::<600>::try_from(
"AT+CMD=0xFF00,55AA,0xff,aa55,0xF:F:0:0,55-AA,0xf:f,aa-55-00-ff\r\n"
)
.unwrap()
);
}

Expand Down Expand Up @@ -913,9 +912,9 @@ mod tests {
let s: String<600> = to_string(&params, "+CMD", options).unwrap();
assert_eq!(
s,
String::<600>::from(
String::<600>::try_from(
"AT+CMD=ff00aa55ff00aa55,0xFF00AA55FF00AA55,0xff00aa55ff00aa55,FF00AA55FF00AA55,ff00aa55ff00aa55,0xFF-00-AA-55-FF-00-AA-55,0xf:f:0:0:a:a:5:5:f:f:0:0:a:a:5:5,FF_00_AA_55_FF_00_AA_55,f#f#0#0#a#a#5#5#f#f#0#0#a#a#5#5\r\n"
)
).unwrap()
);
}
}

0 comments on commit e73a15c

Please sign in to comment.