Skip to content

Commit 3d26ef9

Browse files
committed
Replace unwrap() with alternatives to avoid panics
1 parent 627ad51 commit 3d26ef9

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

esp32-wroom-rp/src/protocol.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ impl NinaConcreteParam for NinaByteParam {
207207

208208
fn from_bytes(bytes: &[u8]) -> Self {
209209
let mut data_as_bytes: Vec<u8, 1> = Vec::new();
210-
data_as_bytes.extend_from_slice(bytes).ok().unwrap();
210+
data_as_bytes.extend_from_slice(bytes).unwrap_or_default();
211211
Self {
212212
length: data_as_bytes.len() as u8,
213213
data: data_as_bytes,
@@ -240,7 +240,7 @@ impl NinaConcreteParam for NinaWordParam {
240240

241241
fn from_bytes(bytes: &[u8]) -> Self {
242242
let mut data_as_bytes: Vec<u8, 2> = Vec::new();
243-
data_as_bytes.extend_from_slice(bytes).ok().unwrap();
243+
data_as_bytes.extend_from_slice(bytes).unwrap_or_default();
244244
Self {
245245
length: data_as_bytes.len() as u8,
246246
data: data_as_bytes,
@@ -273,7 +273,7 @@ impl NinaConcreteParam for NinaSmallArrayParam {
273273

274274
fn from_bytes(bytes: &[u8]) -> Self {
275275
let mut data_as_bytes: Vec<u8, MAX_NINA_PARAM_LENGTH> = Vec::new();
276-
data_as_bytes.extend_from_slice(bytes).ok().unwrap();
276+
data_as_bytes.extend_from_slice(bytes).unwrap_or_default();
277277
Self {
278278
length: data_as_bytes.len() as u8,
279279
data: data_as_bytes,
@@ -306,7 +306,7 @@ impl NinaConcreteParam for NinaLargeArrayParam {
306306

307307
fn from_bytes(bytes: &[u8]) -> Self {
308308
let mut data_as_bytes: Vec<u8, MAX_NINA_PARAM_LENGTH> = Vec::new();
309-
data_as_bytes.extend_from_slice(bytes).ok().unwrap();
309+
data_as_bytes.extend_from_slice(bytes).unwrap_or_default();
310310
Self {
311311
length: data_as_bytes.len() as u16,
312312
data: data_as_bytes,

esp32-wroom-rp/src/protocol/operation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl Operation<NinaAbstractParam> {
2626
// on the data bus.
2727
pub fn param(mut self, param: NinaAbstractParam) -> Self {
2828
// FIXME: Vec::push() will return T when it is full, handle this gracefully
29-
self.params.push(param).ok().unwrap();
29+
self.params.push(param).unwrap_or(());
3030
self
3131
}
3232
}

esp32-wroom-rp/src/tcp_client.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ where
198198
ip = self
199199
.protocol_handler
200200
.resolve(hostname.as_str())
201-
.ok()
202201
.unwrap_or_default();
203202
}
204203

0 commit comments

Comments
 (0)