Hi! I’m quite stuck on this:
I need to store files from another canister and retrieve them as links (mostly images). So I’m trying to use the assets canister in rust. I found this crate: ic_certified_assets and I’m trying to use it. So I created my canister and this is the code inside the lib.rs file:
use ic_cdk::{init, post_upgrade, pre_upgrade};
use ic_cdk::storage::{stable_restore, stable_save};
use ic_certified_assets::StableState;
#[init]
fn init() {
ic_certified_assets::init();
}
#[pre_upgrade]
fn pre_upgrade() {
let state: StableState = ic_certified_assets::pre_upgrade();
stable_save((state,)).expect("failed to save stable state");
}
#[post_upgrade]
fn post_upgrade() {
let (stable_state,): (StableState,) = stable_restore()
.expect("failed to restore stable state");
ic_certified_assets::post_upgrade(stable_state);
}
It is similar to what I read from here.
The problem is that if I try to build it, I got this error:
error[E0277]: the trait bound
StableState: CandidType
is not satisfied
→ src/assets/src/lib.rs:13:18
|
13 | stable_save((state,)).expect(“failed to save stable state”);
| ----------- ^^^^^ the traitCandidType
is not implemented forStableState
| |
| required by a bound introduced by this call
|
= help: the following other types implement traitCandidType
:
bool
isize
i8
i16
i32
i64
i128
usize
and 113 others
= note: required for(StableState,)
to implementArgumentEncoder
note: required by a bound instable_save
→ /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ic-cdk-0.13.2/src/storage.rs:9:8
|
7 | pub fn stable_save(t: T) → Result<(), candid::Error>
| ----------- required by a bound in this function
8 | where
9 | T: candid::utils::ArgumentEncoder,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound instable_save
error[E0277]: the trait bound
StableState: CandidType
is not satisfied
→ src/assets/src/lib.rs:18:44
|
18 | let (stable_state,): (StableState,) = stable_restore()
| ^^^^^^^^^^^^^^ the traitCandidType
is not implemented forStableState
|
= help: the following other types implement traitCandidType
:
bool
isize
i8
i16
i32
i64
i128
usize
and 113 others
= note: required for(StableState,)
to implementfor<'de> ArgumentDecoder<'de>
note: required by a bound instable_restore
→ /Users/user/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ic-cdk-0.13.2/src/storage.rs:19:8
|
17 | pub fn stable_restore() → Result<T, String>
| -------------- required by a bound in this function
18 | where
19 | T: for<'de> candid::utils::ArgumentDecoder<'de>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound instable_restore
For more information about this error, try
rustc --explain E0277
.
error: could not compileassets
(lib) due to 2 previous errors
Do you have some idea to fix this? Or better ways to deploy an assets canister in rust?