Skip to content

Commit

Permalink
Fix/update a few Rust examples:
Browse files Browse the repository at this point in the history
* `counter`
* `hello`
* `performance_counters`
* `periodic_tasks`
* `pub-sub`
* `qrcode`
  • Loading branch information
berestovskyy committed Dec 5, 2023
1 parent fe2b3b2 commit 05619b1
Show file tree
Hide file tree
Showing 38 changed files with 2,703 additions and 10,554 deletions.
697 changes: 115 additions & 582 deletions rust/counter/Cargo.lock

Large diffs are not rendered by default.

12 changes: 5 additions & 7 deletions rust/counter/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
[package]
name = "counter"
version = "1.0.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
name = "counter"
version = "1.1.0"

[lib]
crate-type = ["cdylib"]

[dependencies]
candid = "0.7.14"
ic-cdk = "0.5.2"
ic-cdk-macros = "0.5.2"
candid = "0.10"
ic-cdk = "0.12"
ic-cdk-macros = "0.8"
8 changes: 4 additions & 4 deletions rust/counter/counter.did
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
service : {
"get": () -> (nat) query;
"set": (nat) -> ();
"inc": () -> ();
}
"get" : () -> (nat) query;
"set" : (nat) -> ();
"inc" : () -> ();
};
6 changes: 0 additions & 6 deletions rust/counter/dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,5 @@
"packtool": ""
}
},
"networks": {
"local": {
"bind": "127.0.0.1:8000",
"type": "ephemeral"
}
},
"version": 1
}
10 changes: 4 additions & 6 deletions rust/counter/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::cell::RefCell;
use candid::types::number::Nat;
use std::cell::RefCell;

thread_local! {
static COUNTER: RefCell<Nat> = RefCell::new(Nat::from(0));
static COUNTER: RefCell<Nat> = RefCell::new(Nat::from(0_u32));
}

/// Get the value of the counter.
Expand All @@ -21,11 +21,9 @@ fn set(n: Nat) {
/// Increment the value of the counter.
#[ic_cdk_macros::update]
fn inc() {
COUNTER.with(|counter| *counter.borrow_mut() += 1);
COUNTER.with(|counter| *counter.borrow_mut() += 1_u32);
}



#[cfg(test)]
mod tests {
use super::*;
Expand All @@ -49,4 +47,4 @@ mod tests {
assert_eq!(get(), Nat::from(i));
}
}
}
}
Loading

0 comments on commit 05619b1

Please sign in to comment.