Hacker News new | ask | show | jobs
by kobebrookskC3 103 days ago
how would you implement https://doc.rust-lang.org/stable/std/pin/macro.pin.html without macros? a macro is used to shadow the original variable so that you can't move it (safely) after you pin it
2 comments

Regular variable definition shadows. Macros expand to regular Rust code, they could always be replaced by the expanded body.
yes, but the code inside is unsafe. the pin macro is like a safe function.
I'm not sure what that has to do with anything. The macro isn't what makes it safe. The unsafe code being properly written is.
but without macros, how would you expose a safe interface?

  fn pin(x: T) -> Pin<&mut T> { ... }
would move the value
Your macroless variant of Rust would offer a safe builtin that does this. It doesn't need to be implemented with a macro.
Since macros just expand into code, how could you imagine that a macro is ever necessary?
the macro uses unsafe inside, so that's another instance of unsafe you'll need to check, whereas the pin macro is like a safe function
Excellent goalpost moving! Congratulations!
no, you just missed my point. expanding the implementation is not a safe abstraction. show me how you'd implement the functionality of the pin macro as a safe abstraction.
I didn't miss that you totally changed the subject and now you're attacking a strawman. See Steve Klabnick's response to your other comment where you did this. Of course macros are good for encapsulation and abstraction, but that's a different subject--and note that the discussion was about Zig vs. Rust, and Zig has no macros so there's unencapsulated unsafe code all over the place.

I won't respond further.

i was responding this claim

> It would be perfectly possible to design a variant of Rust that gets you to 80-90% of Rust's usability, with the same safety, without macros.

i then present an api that i think relies on macros to expose a safe api

> Of course macros are good for encapsulation and abstraction, but that's a different subject.

no it's not. exposing safe abstractions is pretty much rust's raison d'être

everything in zig is unsafe and needs to be checked like rust unsafe, so…