[][src]Macro pui_core::scalar_allocator

macro_rules! scalar_allocator {
    (
        $(#[$meta:meta])*
        $v:vis struct $name:ident;
    ) => { ... };
    (
        $(#[$meta:meta])*
        $v:vis thread_local struct $name:ident;
    ) => { ... };
    (
        $(#[$meta:meta])*
        $v:vis struct $name:ident($scalar:ty);
    ) => { ... };
    (
        $(#[$meta:meta])*
        $v:vis thread_local struct $name:ident($scalar:ty);
    ) => { ... };
}

Construct a new ScalarAllocator

For example:

pui_core::scalar_allocator! {
    /// Your scalar allocator
    struct Foo;
}

pui_core::scalar_allocator! {
    #[derive(Debug)]
    pub struct Bar(u8);
}

let foo = Foo;
let bar = Bar;

Foo: ScalarAllocator, and because it is guaratneed to produce one scalar, it also implements Pool with a Flag. Bar: ScalarAllocator, as you can see it also has a paramter: u8. You can use any type that implements Scalar in it's place. This type defines what sort the inner type of Dynamic and DynamicToken.

For example you could use u64:

pui_core::scalar_allocator! {
    #[derive(Debug)]
    pub struct Bar(u64);
}

You can also prefix struct with thread_local to get a ScalarAllocator that is only produces unique scalars on within a given thread

For example:

pui_core::scalar_allocator! {
    thread_local struct Foo;
}

pui_core::scalar_allocator! {
    thread_local struct Bar(u8);
}

let foo = Foo;
let bar = Bar;