Search
 
SCRIPT & CODE EXAMPLE
 

RUST

rust•armanriazi•unwrap

Calling .unwrap() on a Result is often considered poor style. When called on an error type, the program crashes without a helpful error message.
{
It would also be appropriate to call unwrap when you have some other logic that ensures the Result will have an Ok value, but the logic isn’t something the compiler understands. You’ll still have a Result value that you need to handle: whatever operation you’re calling still has the possibility of failing in general, even though it’s logically impossible in your particular situation. If you can ensure by manually inspecting the code that you’ll never have an Err variant, it’s perfectly acceptable to call unwrap. Here’s an example:


fn main() {
    use std::net::IpAddr;

    let home: IpAddr = "127.0.0.1".parse().unwrap();
}
}
Comment

PREVIOUS NEXT
Code Example
Rust :: armanriazi•rust•error•error[E0382]: borrow of moved value: `val` ... thread 
Rust :: rust create hashmap from delimited data in string 
Rust :: rust return the result with trait exit status 
Rust :: allow dead code 
Rust :: gentoo rust stdlib 
Rust :: armanriazi•rust•t•opt•? 
Rust :: Create and populate a 2d vector 
Rust :: how to get public addres from private key solana cli 
Rust :: Transpose matrix, pass-by-reference to function 
Rust :: Find unique element in array where all other elements occur 3 times, uses boolean logic 
Rust :: rust range step 
Lua :: luau how to make rainbow part 
Lua :: lua exponent 
Lua :: lua round number 
Lua :: roblox on touch script 
Lua :: lua float to int 
Lua :: roblox go thru all players 
Lua :: grepper lua 
Lua :: lua random number 
Lua :: lua commenting 
Lua :: how to kill humanoid with click detector roblox 
Lua :: copy table lua 
Lua :: LUKAO150 
Lua :: how to add a damage decimal in roblox studio 
Lua :: how to make kill block in roblox lua 
Matlab :: matlab negation 
Matlab :: how to set for with 2 increases in matlab 
Basic :: the terminal process failed to launch 
Elixir :: elixir string concatination 
Elixir :: create new project phoenix 
ADD CONTENT
Topic
Content
Source link
Name
2+7 =