Skip to content

Commit 5451d4f

Browse files
ttsugriyanonrig
authored andcommitted
Simplify from ada_url_components.
It's more concise and idiomatic to use `then_some`.
1 parent a2cd9cf commit 5451d4f

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

src/lib.rs

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -98,26 +98,10 @@ pub struct UrlComponents {
9898

9999
impl From<&ffi::ada_url_components> for UrlComponents {
100100
fn from(value: &ffi::ada_url_components) -> Self {
101-
let port = if value.port == u32::MAX {
102-
None
103-
} else {
104-
Some(value.port)
105-
};
106-
let pathname_start = if value.pathname_start == u32::MAX {
107-
None
108-
} else {
109-
Some(value.pathname_start)
110-
};
111-
let search_start = if value.search_start == u32::MAX {
112-
None
113-
} else {
114-
Some(value.search_start)
115-
};
116-
let hash_start = if value.hash_start == u32::MAX {
117-
None
118-
} else {
119-
Some(value.hash_start)
120-
};
101+
let port = (value.port != u32::MAX).then_some(value.port);
102+
let pathname_start = (value.pathname_start != u32::MAX).then_some(value.pathname_start);
103+
let search_start = (value.search_start != u32::MAX).then_some(value.search_start);
104+
let hash_start = (value.hash_start != u32::MAX).then_some(value.hash_start);
121105
Self {
122106
protocol_end: value.protocol_end,
123107
username_end: value.username_end,

0 commit comments

Comments
 (0)