this post was submitted on 08 Feb 2024
0 points (NaN% liked)

Rust

5749 readers
12 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

!performance@programming.dev

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
top 11 comments
sorted by: hot top controversial new old
[–] anlumo@feddit.de 0 points 7 months ago (1 children)

Oh, inspect has finally arrived! That will help a ton with debug logging.

[–] lambda@programming.dev 0 points 7 months ago* (last edited 7 months ago) (1 children)

Do you mind explaining? Maybe with the context of another languages equivalent?

[–] anlumo@feddit.de 0 points 7 months ago
let bar: Result<T, E> = ...;
let foo = bar.inspect(|value| log::debug("{}", value));

is equivalent to

let bar: Result<T, E> = ...;
let foo = bar.map(|value| {
    log::debug("{}", value);
    value
});
[–] bwrsandman@lemmy.ca 0 points 7 months ago (2 children)

So rust finally gets reflection? In stable no less!

[–] snaggen@programming.dev 0 points 7 months ago (1 children)

Well, if the only thing you need from reflection is the name of a type, so then yes. But I wouldn't really call this reflection since it is very limited.

[–] Ephera@lemmy.ml 0 points 7 months ago (1 children)

Yeah, Rust can't have proper reflection, since there's no external runtime environment that keeps track of your state. Any such smartness either has to be compiled-in (which is how std::any and macros work) or you can implement something to keep track of this state at runtime, as if you were partially building a runtime environment.

[–] BatmanAoD@programming.dev 0 points 7 months ago (1 children)

Minor point of clarification: it can't have runtime reflection, but in principle it could have compile time reflection.

[–] anlumo@feddit.de 0 points 7 months ago (1 children)

No, the Rust Project recently made sure that Rust can't have compile-time reflection.

[–] bwrsandman@lemmy.ca 0 points 7 months ago (1 children)

Can you expand on this? I'd love to read more on the subject.

[–] anlumo@feddit.de 0 points 7 months ago

Here is a short summary. The compile-time reflection project was stopped, and now nobody wants to touch that subject any more due to fear of getting the wrath of the Rust project again (the person responsible for the whole thing is still part of the leadership).

[–] anlumo@feddit.de 0 points 7 months ago

Unfortunately, it's not guaranteed to be the same string all the time, so it's rather useless for anything but debugging and logging.