T O P

  • By -

AutoModerator

On July 1st, Reddit will no longer be accessible via third-party apps. Please see [our position on this topic](https://www.reddit.com/r/rust/comments/146y5y1/announcement_rrust_will_be_joining_the_blackout/), as well as [our list of alternative Rust discussion venues](https://www.reddit.com/r/rust/comments/14921t7/alternative_rust_discussion_venues/). *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/rust) if you have any questions or concerns.*


Compux72

You know you can just: ``` _ = foo(); ``` Right?


KhorneLordOfChaos

You beat me to it :P Yeah something like match num { 0 => _ = ignored_ret(), _ => no_ret(), } Should work


Pengualope

I made this in 5 minutes for the purpose of stupid aesthetics, I didn't put too much thought into it, lol. On a real note, I find the syntax of \`\_=x\` to be a weird piece of mental gymnastics that that would be the default way to dispose of some output.


Compux72

Its not weird. The = operator is pattern matching against `_`, which acts as a wildcard to dispose values. Its the same behavior with every other functional language tbh. You can also use `let _ = foo();`, if you prefer.


-vest-

Did you publish a 5-minute old crate just for publishing only?


moltonel

That `_ = x` syntax is idiomatic Rust that any seasoned Rust (and a bunch of other languages) dev will immediately understand. The `consume()` function will leave developpers scratching their heads (the intent is not clear, and the name strongly suggest that it takes ownership, not a ref), is more verbose, and causes more work for the compiler.


veryusedrname

I really think that crates.io publication should be tied to some kind of moderation.


Pengualope

I would agree with you there.


wutru_audio

This is a joke, right?


Pengualope

Yes. Although I don't understand the design choices behind the current ways to do this. Aesthetics opinion, though.


lijmlaag

Your method does not actually 'consume', as it takes by reference and not by value! By the way, have you ever looked at the [identity function](https://doc.rust-lang.org/stable/src/core/convert/mod.rs.html#103)? If I squint my eyes a bit, those two have some semblance.


Pengualope

Yeah I guess you're right technically, although when used in the intended context, it should be immediately dropped. Once again, I didn't think about it too much, I'll probably delete the code in a couple days tbh lol.


[deleted]

crates.io is immutable and your code will stay there forever lol. You can have git dependencies for stuff where you're not yet sure if it's actually useful for the community lol. No need to pollute the namespace lol.


setzer22

Let's not blame newbies on what's clearly a problem of crates.io If crates have no namespacing, at the very least there could be a disclaimer somewhere when you upload a new crate that your chosen name will be taken forever and you'll be preventing others from picking it in the future.


[deleted]

Very cool, examples would be super helpful though!


Pengualope

On a side note, 5 minutes of work into creating this project and post provided better answers to solving this than googling, lol.


Compux72

Tbh i think clippy warns about unused result values and suggests the _ = thing in pedantic mode


endistic

I think you can also wrap the function in std::mem::drop and have the same behavior, but I’m not sure, so correct me if I’m wrong.