Closed rmja closed 1 year ago
Consider this example:
#[derive(Clone, AtatCmd)] #[at_cmd("+CPIN", NoResponse, timeout_ms = 5_000, termination = "\r")] pub struct EnterPin<'a> { #[at_arg(len = 4)] pub pin: &'a str, } #[cfg(test)] mod tests { use atat::AtatCmd; use super::*; #[test] fn can_enter_pin() { let cmd = EnterPin { pin: "1234" }; assert_eq!(b"AT+CPIN=\"1234\"\r", cmd.as_bytes()); } }
The test panics because the string allocation does not take into account the two ". If at_arg(len = 6) was specified instead the test would pass. From what I can see from e.g. https://github.com/BlackbirdHQ/ublox-cellular-rs/blob/961d7f570204ae53bd90d5f4dc174097056b4d06/ublox-cellular/src/command/device_lock/mod.rs#L29 the length specified by at_arg() should be the string length and not the quoted string length.
"
at_arg(len = 6)
at_arg()
Very nice catch! That does indeed seem like a bug!
A PR correcting this behavior, as well as the test you added here would be very welcomed ❤️
Consider this example:
The test panics because the string allocation does not take into account the two
"
. Ifat_arg(len = 6)
was specified instead the test would pass. From what I can see from e.g. https://github.com/BlackbirdHQ/ublox-cellular-rs/blob/961d7f570204ae53bd90d5f4dc174097056b4d06/ublox-cellular/src/command/device_lock/mod.rs#L29 the length specified byat_arg()
should be the string length and not the quoted string length.