[−][src]Module pui_core::scoped
This works on two different principles.
The first is that HRTB (higher rank type bounds) produces
fresh lifetimes on each call, and they can't be unified
against each other across multiple calls to Scoped::with
.
This allows Scoped::with
to prevent the following at
compile time:
Scoped::with(|a: Scoped<'_>| { Scoped::with(|b: Scoped<'_>| { assert_eq!(a, b); }) })
This means that all Scoped
types created with Scoped::with
are guaranteed to be unique! If you can't compare them, then
they can never compare equal.
The second principle is based off of
generativity
where macros are used to generate the boilerplate to create
unique lifetimes. You can read about the details in generativity
's
documentation.
This allows scope
to produce unique Scoped
s.
scope!(a); scope!(b); assert_eq!(a, b);
How to decide which to use
Scoped::with
generally produces better error messages, and tends
to be easier to reason about. So it should be the first choice.
However, if you are using some strange control flow or need early returns,
and it would be easier to embed a Scoped
directly in the current scope,
then you should use the scope
macro.
Structs
Scoped | A scoped |
ScopedToken |