method DynHandle.setAs
set on behalf of p (a service acting for a user; the policy is evaluated for p).
Example:
dynamic Limits {
rps: u32 = 100
}
policy Limits {
allow set if caller.hasRole("Admin")
}
fn main() io {
let l = Limits.get()
let admin = Principal.User("ann", ["Admin"], Map.new(), false, none)
let guest = Principal.User("bob", [], Map.new(), false, none)
print("{l.rps.setAs(&admin, 200) is DynError}")
print("{l.rps.setAs(&guest, 300) is DynError}")
print("{l.rps.get()}")
}Output
false true 200
pub(api) fn setAs(p: &Principal, v: T, layer: DynScope = .Global) -> () | DynError where T: SerializableSince. 1.0.0-beta
Parameters
Returns
()
Errors
DynError where T: Serializable- `DynError` when the policy of the config refuses `p`.
Effects
none declared (pure unless the body says otherwise)
Defined in: std/core/dynconf.oxl:574