Skip to main content

PluginRegistrar

Struct PluginRegistrar 

Source
pub struct PluginRegistrar<'a> { /* private fields */ }

Implementations§

Source§

impl PluginRegistrar<'_>

Source

pub fn register_record_schema( &mut self, schema: DomainRecordSchema, ) -> Result<(), CanwuError>

Source

pub fn register_schema(&mut self, schema: TypeSchema) -> Result<(), CanwuError>

Source

pub fn register_event_audience( &mut self, event_type: impl Into<String>, audience: EventAudience, ) -> Result<(), CanwuError>

Declares the player-facing audience for one emitted plugin event type.

This policy is persisted in the plugin descriptor and is independent from the plugin system subscription graph. Event types without a declaration remain private to player-facing projections.

Source

pub fn register_system( &mut self, contract: SystemContract, handler: fn(&SimulationView<'_>, &SimEvent) -> Result<Vec<SystemDirective>, CanwuError>, ) -> Result<(), CanwuError>

Source

pub fn register_boundary_system( &mut self, contract: BoundarySystemContract, handler: fn(&SimulationView<'_>, &BoundaryContext) -> Result<BoundaryProposal, CanwuError>, ) -> Result<(), CanwuError>

Examples found in repository?
examples/phased_boundary.rs (line 104)
97    fn register(&self, registrar: &mut canwu_api::PluginRegistrar<'_>) -> Result<(), CanwuError> {
98        let mut contract = BoundarySystemContract::new(
99            "offer",
100            BoundaryPhase::ReservationAndAllocation,
101            SystemCadence::Daily,
102        );
103        contract.reservation_offers = vec![StateKey::new("logistics", "grain")];
104        registrar.register_boundary_system(contract, offer_grain)
105    }
106}
107
108struct DemandPlugin;
109
110impl SimulationPlugin for DemandPlugin {
111    fn name(&self) -> &'static str {
112        "example-demand"
113    }
114
115    fn version(&self) -> &'static str {
116        "1.0.0"
117    }
118
119    fn semantic_hash(&self) -> &'static str {
120        "331b865359d4ac4a14c9bf90da665b82b4aa65ee63c195e331d8f1fa181e7029"
121    }
122
123    fn register(&self, registrar: &mut canwu_api::PluginRegistrar<'_>) -> Result<(), CanwuError> {
124        let mut request = BoundarySystemContract::new(
125            "request",
126            BoundaryPhase::ReservationAndAllocation,
127            SystemCadence::Daily,
128        );
129        request.reservation_requests = vec![StateKey::new("logistics", "grain")];
130        registrar.register_boundary_system(request, request_grain)?;
131
132        let mut apply = BoundarySystemContract::new(
133            "apply",
134            BoundaryPhase::DomainDeltaProposal,
135            SystemCadence::Daily,
136        );
137        apply.writes = vec![StateKey::new("garrison", "grain")];
138        apply.emits = vec!["grain_allocated".to_owned()];
139        apply.reservation_reads = vec![ReservationRef::new(
140            "example-demand",
141            "request",
142            "daily-grain",
143        )];
144        apply.visibility = StateVisibility::SameBoundary;
145        registrar.register_boundary_system(apply, apply_grain)
146    }
Source

pub fn register_command( &mut self, descriptor: PluginActionDescriptor, handler: fn(&SimulationView<'_>, &CommandContext, &Value) -> Result<Vec<SystemDirective>, CanwuError>, ) -> Result<(), CanwuError>

Examples found in repository?
examples/plugin.rs (lines 57-84)
56    fn register(&self, registrar: &mut PluginRegistrar<'_>) -> Result<(), CanwuError> {
57        registrar.register_command(
58            PluginActionDescriptor {
59                name: "set_stance".to_owned(),
60                description: "Set an army stance through an issuer-aware command".to_owned(),
61                payload_schema: PayloadSchema::Object {
62                    properties: BTreeMap::from([
63                        (
64                            "army".to_owned(),
65                            PayloadProperty {
66                                value_type: PayloadValueType::Integer,
67                                required: true,
68                            },
69                        ),
70                        (
71                            "stance".to_owned(),
72                            PayloadProperty {
73                                value_type: PayloadValueType::String,
74                                required: true,
75                            },
76                        ),
77                    ]),
78                    allow_additional: false,
79                },
80                reads: vec![StateKey::core_armies()],
81                writes: vec![StateKey::new("military", "stance")],
82            },
83            set_stance,
84        )
85    }
Source

pub fn register_ingress( &mut self, descriptor: PluginIngressDescriptor, ) -> Result<(), CanwuError>

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for PluginRegistrar<'a>

§

impl<'a> Freeze for PluginRegistrar<'a>

§

impl<'a> RefUnwindSafe for PluginRegistrar<'a>

§

impl<'a> Send for PluginRegistrar<'a>

§

impl<'a> Sync for PluginRegistrar<'a>

§

impl<'a> Unpin for PluginRegistrar<'a>

§

impl<'a> UnsafeUnpin for PluginRegistrar<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.