execution_reservation_authority.bend

bendvy-ecs-core@0.1.0.3 · 24 lines · 6 definitions

1import Base
2
3type Granted is Data:
4  Granted{}
5
6type Grant is Data:
7  NoStructural{}
8  Structural{}
9type Context is Data:
10  Context{namespace:U32,id:U32,grant:Grant}
11type Permit is Data:
12  Authorized{namespace:U32,id:U32}
13  Unauthorized{}
14
15# The prepared framework boundary supplies Context from its actual owner and
16# closed command declaration. Gameplay bodies quantify an abstract Permit.
17def qualified(context:Context) -> Permit:
18  match context:
19    case Context{namespace,id,Structural{}}:Authorized{namespace,id}
20    case Context{_,_,NoStructural{}}:Unauthorized{}
21def admitted(permit:Permit,namespace:U32,identity:Maybe<&2,U32>) -> Bool:
22  match permit identity:
23    case Authorized{actual,id} Some{expected}:Bool.and(U32.is_eq(actual,namespace),U32.is_eq(id,expected))
24    case _ _:False{}