diff options
author | Elichai Turkel <elichai.turkel@gmail.com> | 2019-04-01 21:50:02 +0300 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2019-04-03 08:32:10 -0400 |
commit | 0ebe290198ca852c27422fb3a82670f113f78727 (patch) | |
tree | 18a6fd1c2552d0b2e19ae690e18a6b7d86dbb9fb /doc/HACKING | |
parent | f0e39df5ce7b884ae6ff1c8579200886e298f44c (diff) | |
download | tor-0ebe290198ca852c27422fb3a82670f113f78727.tar.gz tor-0ebe290198ca852c27422fb3a82670f113f78727.zip |
Removed the use of expect from CodingStandardsRust
Diffstat (limited to 'doc/HACKING')
-rw-r--r-- | doc/HACKING/CodingStandardsRust.md | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/doc/HACKING/CodingStandardsRust.md b/doc/HACKING/CodingStandardsRust.md index fc562816db..b570e10dc7 100644 --- a/doc/HACKING/CodingStandardsRust.md +++ b/doc/HACKING/CodingStandardsRust.md @@ -256,7 +256,7 @@ Here are some additional bits of advice and rules: or 2) should fail (i.e. in a unittest). You SHOULD NOT use `unwrap()` anywhere in which it is possible to handle the - potential error with either `expect()` or the eel operator, `?`. + potential error with the eel operator, `?` or another non panicking way. For example, consider a function which parses a string into an integer: fn parse_port_number(config_string: &str) -> u16 { @@ -264,12 +264,12 @@ Here are some additional bits of advice and rules: } There are numerous ways this can fail, and the `unwrap()` will cause the - whole program to byte the dust! Instead, either you SHOULD use `expect()` + whole program to byte the dust! Instead, either you SHOULD use `ok()` (or another equivalent function which will return an `Option` or a `Result`) and change the return type to be compatible: fn parse_port_number(config_string: &str) -> Option<u16> { - u16::from_str_radix(config_string, 10).expect("Couldn't parse port into a u16") + u16::from_str_radix(config_string, 10).ok() } or you SHOULD use `or()` (or another similar method): |