Elektrine lite

← Feed

@Ambraven@social.mochi.academy

Post #2564768

2026-04-30 08:07 UTC

So I fed some solutions into compiler explorer: https://godbolt.org/z/fadsa9q8n For reference this is what I'm trying to emulate from C++: https://godbolt.org/z/hEEodGMWG I think the "bar" version is the closest match. Also it's worth pointing out that de C++ example only worst because the foo argument is const. #rust #rustlang #Cpp

Replies (2)

  • @manpacket@functional.cafe 2026-04-30 08:50

    @Ambraven@social.mochi.academy godbolt is great if you want to share the results or run it across a bunch of different compiler versions. If you simply what to see the generated asm for your rust project - there's cargo-show-asm.

    Open ##2564797

  • @michalfita@mastodon.social 2026-04-30 10:15

    @Ambraven@social.mochi.academy Your C++ code uses temporary default as reference; #Rust doesn't have them... unfortunately. The closest semantically would be IMHO: ``` fn foo(t: Option) { fn inner_foo(t: &T) { t.toto(); } inner_foo(t.unwrap_or(&T::default())); } ``` #Cpp

    Open ##2564798