Skip to content

Commit 6be96d3

Browse files
committed
refactor: remove some .unwrap() calls
1 parent d153709 commit 6be96d3

File tree

5 files changed

+21
-28
lines changed

5 files changed

+21
-28
lines changed

src/configure/auto_mozilla.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,15 @@ fn parse_server<B: BufRead>(
6767

6868
let typ = server_event
6969
.attributes()
70-
.find(|attr| {
71-
attr.as_ref()
72-
.map(|a| {
73-
String::from_utf8_lossy(a.key.as_ref())
74-
.trim()
75-
.to_lowercase()
76-
== "type"
77-
})
78-
.unwrap_or_default()
70+
.find_map(|attr| {
71+
attr.ok().filter(|a| {
72+
String::from_utf8_lossy(a.key.as_ref())
73+
.trim()
74+
.eq_ignore_ascii_case("type")
75+
})
7976
})
8077
.map(|typ| {
81-
typ.unwrap()
82-
.decode_and_unescape_value(reader.decoder())
78+
typ.decode_and_unescape_value(reader.decoder())
8379
.unwrap_or_default()
8480
.to_lowercase()
8581
})

src/context.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ pub struct InnerContext {
276276
/// The text of the last error logged and emitted as an event.
277277
/// If the ui wants to display an error after a failure,
278278
/// `last_error` should be used to avoid races with the event thread.
279-
pub(crate) last_error: std::sync::RwLock<String>,
279+
pub(crate) last_error: parking_lot::RwLock<String>,
280280

281281
/// If debug logging is enabled, this contains all necessary information
282282
///
@@ -446,7 +446,7 @@ impl Context {
446446
metadata: RwLock::new(None),
447447
creation_time: tools::Time::now(),
448448
last_full_folder_scan: Mutex::new(None),
449-
last_error: std::sync::RwLock::new("".to_string()),
449+
last_error: parking_lot::RwLock::new("".to_string()),
450450
debug_logging: std::sync::RwLock::new(None),
451451
push_subscriber,
452452
push_subscribed: AtomicBool::new(false),

src/location.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -244,18 +244,14 @@ impl Kml {
244244
self.tag = KmlTag::PlacemarkPoint;
245245
} else if tag == "coordinates" && self.tag == KmlTag::PlacemarkPoint {
246246
self.tag = KmlTag::PlacemarkPointCoordinates;
247-
if let Some(acc) = event.attributes().find(|attr| {
248-
attr.as_ref()
249-
.map(|a| {
250-
String::from_utf8_lossy(a.key.as_ref())
251-
.trim()
252-
.to_lowercase()
253-
== "accuracy"
254-
})
255-
.unwrap_or_default()
247+
if let Some(acc) = event.attributes().find_map(|attr| {
248+
attr.ok().filter(|a| {
249+
String::from_utf8_lossy(a.key.as_ref())
250+
.trim()
251+
.eq_ignore_ascii_case("accuracy")
252+
})
256253
}) {
257254
let v = acc
258-
.unwrap()
259255
.decode_and_unescape_value(reader.decoder())
260256
.unwrap_or_default();
261257

src/log.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ impl Context {
5050
/// Set last error string.
5151
/// Implemented as blocking as used from macros in different, not always async blocks.
5252
pub fn set_last_error(&self, error: &str) {
53-
let mut last_error = self.last_error.write().unwrap();
53+
let mut last_error = self.last_error.write();
5454
*last_error = error.to_string();
5555
}
5656

5757
/// Get last error string.
5858
pub fn get_last_error(&self) -> String {
59-
let last_error = &*self.last_error.read().unwrap();
59+
let last_error = &*self.last_error.read();
6060
last_error.clone()
6161
}
6262
}

src/mimeparser.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,10 +1667,11 @@ impl MimeMessage {
16671667
{
16681668
let mut to_list =
16691669
get_all_addresses_from_header(&report.headers, "x-failed-recipients");
1670-
let to = if to_list.len() == 1 {
1671-
Some(to_list.pop().unwrap())
1670+
let to = if to_list.len() != 1 {
1671+
// We do not know which recipient failed
1672+
None
16721673
} else {
1673-
None // We do not know which recipient failed
1674+
to_list.pop()
16741675
};
16751676

16761677
return Ok(Some(DeliveryReport {

0 commit comments

Comments
 (0)