Struct xylem::id::IdArgs [−][src]
Expand description
Arguments for Id
.
Fields
new: bool
Whether to generate a new identifier.
If set to true
, expects the value to be a new identifier in the namespace.
If set to false
, expects the value to be an existing identifier in the namespace.
track: bool
Whether to track the identifier in the root scope.
The identifier will persist with respect to the unique identifier of the parent.
containing the identifiers of all ancestors (i.e. X::Scope
, X::Scope::Scope
, etc.).
This option is only valid when new
is true
,
and cannot be used if the type recurses.
import: Vec<TypeId>
Import identifiers whose scope is the object referenced by this identifier.
Example
use std::any::TypeId;
use xylem::{Id, Identifiable, Xylem};
#[derive(Xylem)]
struct Foo {
#[xylem(args(import = vec![TypeId::of::<Qux>()]))]
bar: Id<Schema, Bar>,
qux: Id<Schema, Qux>,
}
#[derive(Xylem)]
struct Bar {
#[xylem(args(new = true))]
id: Id<Schema, Bar>,
qux: Vec<Qux>,
}
impl Identifiable<Schema> for Bar {
type Scope = ();
fn id(&self) -> Id<Schema, Bar> { self.id }
}
#[derive(Xylem)]
struct Qux {
#[xylem(args(new = true, track = true))]
id: Id<Schema, Qux>,
}
impl Identifiable<Schema> for Qux {
type Scope = Bar;
fn id(&self) -> Id<Schema, Qux> { self.id }
}
Then Foo::qux
will be resolved using Foo::bar
as the scope.
This imported scope lasts for the rest of the scope of the object declaring this ID,
i.e. during the conversion of the fields in Foo
behind Foo::bar
.