Skip to content

Commit d0d3fc8

Browse files
authored
Examples for the new Rust tutorial on inter-canister calls #1069
Examples for the new Rust tutorial on inter-canister calls
2 parents c00ae71 + bdff565 commit d0d3fc8

File tree

25 files changed

+1554
-769
lines changed

25 files changed

+1554
-769
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@
5959
/rust/hello/ @dfinity/sdk
6060
/rust/icp_transfer/ @dfinity/growth
6161
/rust/image-classification/ @dfinity/execution
62+
/rust/inter-canister-calls/ @dfinity/ic-message-routing-owners
6263
/rust/nft-wallet/ @dfinity/growth
6364
/rust/parallel_calls/ @dfinity/research
6465
/rust/performance_counters/ @dfinity/execution
6566
/rust/periodic_tasks/ @dfinity/execution
66-
/rust/pub-sub/ @dfinity/growth
6767
/rust/qrcode/ @dfinity/execution
6868
/rust/query_stats/ @dfinity/consensus
6969
/rust/send_http_get/ @dfinity/growth
Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,44 @@
1-
# Known failure: https://dfinity.atlassian.net/browse/EM-6
2-
name: rust-pub-sub
1+
name: rust-inter-canister-calls
32
on:
43
push:
54
branches:
65
- master
76
pull_request:
87
paths:
9-
- rust/pub-sub/**
8+
- rust/inter-canistert-calls/**
109
- .github/workflows/provision-darwin.sh
1110
- .github/workflows/provision-linux.sh
12-
- .github/workflows/rust-pub-sub-example.yml
11+
- .github/workflows/rust-inter-canister-calls-example.yml
1312
- .ic-commit
1413
concurrency:
1514
group: ${{ github.workflow }}-${{ github.ref }}
1615
cancel-in-progress: true
1716
jobs:
18-
rust-pub-sub-darwin:
17+
rust-inter-canister-calls-darwin:
1918
runs-on: macos-15
2019
steps:
2120
- uses: actions/checkout@v2
2221
with:
2322
submodules: recursive
2423
- name: Provision Darwin
2524
run: bash .github/workflows/provision-darwin.sh
26-
- name: Rust Pub-Sub Darwin
25+
- name: Rust Parallel-Calls Darwin
2726
run: |
28-
pushd rust/pub-sub
27+
pushd rust/inter-canister-calls
2928
dfx start --background
30-
make install
3129
make test
3230
popd
33-
rust-pub-sub-linux:
31+
rust-inter-canister-calls-linux:
3432
runs-on: ubuntu-20.04
3533
steps:
3634
- uses: actions/checkout@v2
3735
with:
3836
submodules: recursive
3937
- name: Provision Linux
4038
run: bash .github/workflows/provision-linux.sh
41-
- name: Rust Pub-Sub Linux
39+
- name: Rust Parallel-Calls Linux
4240
run: |
43-
pushd rust/pub-sub
41+
pushd rust/inter-canister-calls
4442
dfx start --background
45-
make install
4643
make test
4744
popd

rust/counter/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,15 @@ fn set(n: Nat) {
1818
COUNTER.with(|count| *count.borrow_mut() = n);
1919
}
2020

21+
#[ic_cdk_macros::update]
22+
fn get_and_set(n: Nat) -> Nat {
23+
COUNTER.with(|counter| {
24+
let old = counter.borrow().clone();
25+
*counter.borrow_mut() = n;
26+
old
27+
})
28+
}
29+
2130
/// Increment the value of the counter.
2231
#[ic_cdk_macros::update]
2332
fn inc() {
@@ -47,4 +56,12 @@ mod tests {
4756
assert_eq!(get(), Nat::from(i));
4857
}
4958
}
59+
60+
#[test]
61+
fn test_get_and_set() {
62+
let old = get_and_set(Nat::from(1 as u32));
63+
let new = get();
64+
assert_eq!(old, Nat::from(0 as u32));
65+
assert_eq!(new, Nat::from(1 as u32));
66+
}
5067
}

0 commit comments

Comments
 (0)