Astra Kernel :verified:<p>✨ Underscore expressions in Rust</p><p>Underscore `_`, a reserved identifier - Anything passed to into it will be ignored(But careful, it is not dropped)</p><p>👉 Underscore doesnt copy,move or borrow the value</p><p>👉 In the following code, we create String instance 'x'.We pass it to the underscore which does nothing than ignoring whatever we give. It does not move the ownership.<br>Ownership still remains with 'x' 😱</p><p>let x = String::new("Kernel");<br>let _ = x; </p><p>👉 Then what is the use? </p><p>👉 It will be useful in situation, when you are not interested in a certain value and ignore it. </p><p>For example:<br>fn main(){<br> let x = (21, "Parker");<br> let (age, _) = x; //Ignore the name, only want age from the tuple.<br> println!("age: {}", age);<br>}</p><p>Resources:<br><a href="https://runrust.miraheze.org/wiki/Underscore" rel="nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="ellipsis">runrust.miraheze.org/wiki/Unde</span><span class="invisible">rscore</span></a></p><p>Underscore is not exactly "throw away" but rather it is exactly "don't bind to variable:<br><a href="https://news.ycombinator.com/item?id=22449960" rel="nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="ellipsis">news.ycombinator.com/item?id=2</span><span class="invisible">2449960</span></a><br><a href="https://www.reddit.com/r/rust/comments/96zxge/underscore_does_not_bind_codechain/" rel="nofollow noopener" target="_blank"><span class="invisible">https://www.</span><span class="ellipsis">reddit.com/r/rust/comments/96z</span><span class="invisible">xge/underscore_does_not_bind_codechain/</span></a></p><p><a href="https://infosec.exchange/tags/rustlang" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>rustlang</span></a> <a href="https://infosec.exchange/tags/rust" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>rust</span></a> <a href="https://infosec.exchange/tags/rustaceans" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>rustaceans</span></a> <a href="https://infosec.exchange/tags/RustChallenge" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>RustChallenge</span></a></p>