Hello!
I am having trouble with a compile error when I specify a structure as an argument to the update function.
[ Error ]
$ cargo build
Compiling encrypted_notes_backend v0.1.0 (/Users/yukasaito/Desktop/git/icp/example_encrypted_notes/src/encrypted_notes_backend)
error[E0282]: type annotations needed for `(_, _)`
--> src/encrypted_notes_backend/src/lib.rs:113:1
|
113 | #[update(name = "updateNote")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in the attribute macro `update` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider giving this pattern a type, where the placeholders `_` are specified
|
113 | #[update(name = "updateNote")]: (_, _)
| ++++++++
For more information about this error, try `rustc --explain E0282`.
error: could not compile `encrypted_notes_backend` due to previous error
[ Code ]
#[derive(CandidType, Clone, Debug, Default)]
pub struct EncryptedNote {
pub id: u128,
pub encrypted_text: String,
}
thread_local! {
static NOTE_STORE: RefCell<BTreeMap<Principal, Vec<EncryptedNote>>> = RefCell::default();
static ID_STORE: RefCell<u128> = RefCell::new(0);
}
// ...
#[update(name = "updateNote")]
fn update_note(caller: Principal, update_note: EncryptedNote) {
NOTE_STORE.with(|note_ref| {
let mut writer = note_ref.borrow_mut();
let notes = writer.get_mut(&caller).expect("No user is registered.");
if let Some(current_note) = notes
.iter_mut()
.find(|current_note| current_note.id == update_note.id)
{
current_note.encrypted_text = update_note.encrypted_text;
}
})
}
When the content of the structure is directly specified as an argument, there is no problem, but when it is passed as a structure, the error occurs.
The code I am referring to is encrypted-notes-dapp - dfinity/examples (my code is much simpler than this).
If you know how to solve this problem, please let me know.
Thank you in advance.