BB_C

joined 1 year ago
[–] [email protected] 2 points 1 day ago* (last edited 1 day ago)

Not only that. We don't just "inject" raw strings with the syn/quote duality. Stringified or not, the token tree will be parse-checked into the expected syn type before being used in generated code.

So the distinction is both wrong and irrelevant. This is what I meant by wrong on multiple levels/layers 😉

[–] [email protected] 1 points 1 day ago (2 children)

In Rust, you provide a string — that is injected to be invoked internally. In C++, we’d just provide a callable.

This is because Rust’s attribute grammar can’t support a callable here.

I don't do C++ as a life choice, and thus not 100% sure what the author means here. But I have the feeling that he is wrong, on multiple levels even 😉

[–] [email protected] 3 points 3 days ago (1 children)

I just looked at the code, and it's actually a neat idea implementation wise, and I see now how it helped you.

But I'm still of the opinion that its a purpose mismatch.

[–] [email protected] 4 points 3 days ago (3 children)

Last week I basically duplicated the serialization code to provide better debug output…

Why was duplication needed, instead of implementing Debug using serialized output?

And why would one want to rename stuff...etc in Debug anyway? It's for debugging?

This looks like purpose mismatch to me.

[–] [email protected] 8 points 5 days ago

Also:

A short post on how variable names can leak out of macros

I don't think you understood the blog OP!

[–] [email protected] 1 points 1 week ago* (last edited 1 week ago) (3 children)

There is a general mechanism in Rust that allows language users to add their own sugar. It's called macros 😉

macro_rules! keep {
    (let $id:ident = $expr:expr => $($tt:tt)+) => {
        let $id = $expr;
        let $id = $id$($tt)+;
    }
}

fn main() {
    keep!{ let path = std::env::current_dir().unwrap() => .as_path() };
    println!("{path:?}");
}

You can remove let from the macro's fragment specifier and invocation.

[–] [email protected] -5 points 1 week ago

mastering_rust

Maybe wait until you're actually good at it.

[–] [email protected] 3 points 1 week ago

Rebinding with and without mut is a known and encouraged pattern in rust. Leaving things as mut longer than necessary is not.

[–] [email protected] 3 points 1 week ago

Bringing vimperator/pentadactyl back! That would be the dream.

Anyway, last time I tested it (~3 weeks ago), servo was not very usable still with the few websites I tried. Hopefully it gets, at least partway, there in a few months.

[–] [email protected] 20 points 1 week ago (1 children)

Neither.

  • make new() give you a fully valid and usable struct value.
  • or use a builder (you can call it something else like Partial/Incomplete/whatever) struct so you can't accidentally do anything without a fully initialized value.

Maybe you should also use substructs that hold some of the info.

view more: next ›