[][src]Module pui::scoped

Use lifetimes to guarantee unique identifiers.

Two scoped identifiers will never have the same lifetime id, and so it checks at compile time that they are indeed different identifiers.

There are two main ways to create a scoped identifier, either you can use Scoped::with and pass it a callback that will be called with a new scoped identifier, or you can use pui::make_scoped to create a scoped identifier in the current scope.

fn pass() {
    Scoped::with(|foo| {
        let _foo_handle = foo.handle();
    })
}
fn pass() {
    pui::make_scoped!(foo);
    let _foo_handle = foo.handle();
}

Note: you cannot intermix different scoped identifiers declared in the same scope

fn fail() {
    pui::make_scoped!(foo);
    pui::make_scoped!(bar);
    assert_eq!(foo, bar);
}

Structs

Scoped

A scoped identifier

ScopedHandle

A handle to to a Scoped identifier