Skip to content

Commit 8173b66

Browse files
author
Felix Obenhuber
committed
anng: replace unwrap with expect in Url::from_nng write! calls
1 parent 96788c9 commit 8173b66

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

anng/src/pipes.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -182,29 +182,29 @@ impl Url {
182182
let sa_addr = u32::from_be(addr.sa_addr);
183183
let sa_port = u16::from_be(addr.sa_port);
184184
let ip = Ipv4Addr::from_bits(sa_addr);
185-
// unwrap: fmt::Write for String is infallible
186-
write!(url, "{scheme}://{ip}:{sa_port}").unwrap();
185+
write!(url, "{scheme}://{ip}:{sa_port}")
186+
.expect("fmt::Write for String is infallible");
187187
}
188188
x if x == nng_sys::nng_sockaddr_family::NNG_AF_INET6 as u32 => {
189189
// SAFETY: we've checked the family
190190
let addr = unsafe { &addr.s_in6 };
191191
let sa_port = u16::from_be(addr.sa_port);
192192
let ip = Ipv6Addr::from_bits(u128::from_be_bytes(addr.sa_addr));
193193
let scope_id = addr.sa_scope;
194-
// unwrap: fmt::Write for String is infallible
195194
if scope_id != 0 {
196-
write!(url, "{scheme}://[{ip}%{scope_id}]:{sa_port}").unwrap();
195+
write!(url, "{scheme}://[{ip}%{scope_id}]:{sa_port}")
197196
} else {
198-
write!(url, "{scheme}://[{ip}]:{sa_port}").unwrap();
197+
write!(url, "{scheme}://[{ip}]:{sa_port}")
199198
}
199+
.expect("fmt::Write for String is infallible");
200200
}
201201
x if x == nng_sys::nng_sockaddr_family::NNG_AF_IPC as u32 => {
202202
// SAFETY: we've checked the family
203203
let addr = unsafe { &addr.s_ipc };
204204
// SAFETY: sa_path is guaranteed to be a C-style string
205205
let path = unsafe { CStr::from_ptr(addr.sa_path.as_ptr()) };
206-
// unwrap: fmt::Write for String is infallible
207-
write!(url, "{scheme}://{}", path.to_string_lossy()).unwrap();
206+
write!(url, "{scheme}://{}", path.to_string_lossy())
207+
.expect("fmt::Write for String is infallible");
208208
}
209209
x if x == nng_sys::nng_sockaddr_family::NNG_AF_ABSTRACT as u32 => {
210210
// SAFETY: we've checked the family
@@ -214,13 +214,12 @@ impl Url {
214214
// - ASCII graphic characters (0x21-0x7E) are written literally
215215
// - All other bytes (including space 0x20, null 0x00, and high bytes) are
216216
// percent-encoded as %xx
217-
// unwrap: fmt::Write for String is infallible
218-
write!(url, "{scheme}://").unwrap();
217+
write!(url, "{scheme}://").expect("fmt::Write for String is infallible");
219218
for &b in name {
220219
if b.is_ascii_graphic() {
221220
url.push(b as char);
222221
} else {
223-
write!(url, "%{b:02x}").unwrap();
222+
write!(url, "%{b:02x}").expect("fmt::Write for String is infallible");
224223
}
225224
}
226225
}
@@ -229,8 +228,8 @@ impl Url {
229228
let addr = unsafe { &addr.s_inproc };
230229
// SAFETY: sa_name is guaranteed to be a C-style string
231230
let name = unsafe { CStr::from_ptr(addr.sa_name.as_ptr()) };
232-
// unwrap: fmt::Write for String is infallible
233-
write!(url, "{scheme}://{}", name.to_string_lossy()).unwrap();
231+
write!(url, "{scheme}://{}", name.to_string_lossy())
232+
.expect("fmt::Write for String is infallible");
234233
}
235234
_ => {
236235
unimplemented!("support for address family {s_family} has not yet been added")

0 commit comments

Comments
 (0)