Skip to content

Commit 9fe903b

Browse files
committed
AssetCanister: Allow state access by the lib consumer
1 parent 597d0a1 commit 9fe903b

File tree

1 file changed

+16
-2
lines changed
  • src/canisters/frontend/ic-certified-assets/src

1 file changed

+16
-2
lines changed

src/canisters/frontend/ic-certified-assets/src/lib.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ thread_local! {
3232
static STATE: RefCell<State> = RefCell::new(State::default());
3333
}
3434

35+
pub fn with_state<F, R>(f: F) -> R
36+
where
37+
F: FnOnce(&State) -> R,
38+
{
39+
STATE.with(|s| f(&s.borrow()))
40+
}
41+
42+
pub fn with_state_mut<F, R>(f: F) -> R
43+
where
44+
F: FnOnce(&mut State) -> R,
45+
{
46+
STATE.with(|s| f(&mut s.borrow_mut()))
47+
}
48+
3549
#[query]
3650
#[candid_method(query)]
3751
fn api_version() -> u16 {
@@ -387,11 +401,11 @@ fn can(permission: Permission) -> Result<(), String> {
387401
})
388402
}
389403

390-
fn can_commit() -> Result<(), String> {
404+
pub fn can_commit() -> Result<(), String> {
391405
can(Permission::Commit)
392406
}
393407

394-
fn can_prepare() -> Result<(), String> {
408+
pub fn can_prepare() -> Result<(), String> {
395409
can(Permission::Prepare)
396410
}
397411

0 commit comments

Comments
 (0)