# Rust CDK v0.5.1 is out

**URL:** <https://forum.dfinity.org/t/rust-cdk-v0-5-1-is-out/13086>\
**Category:** Developers\
**Created:** [May 18, 2022, 8:40am UTC](https://forum.dfinity.org/t/rust-cdk-v0-5-1-is-out/13086 "2022-05-18T08:40:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![roman-kashitsyn](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/roman-kashitsyn/32/3802_2.png) [@roman-kashitsyn](https://forum.dfinity.org/u/roman-kashitsyn)\
**Post date:** [May 18, 2022, 8:40am UTC](https://forum.dfinity.org/t/rust-cdk-v0-5-1-is-out/13086/1 "2022-05-18T08:40:16Z")

</div>

I’m happy to announce that [Rust CDK 0.5.1](https://docs.rs/ic-cdk/0.5.1/ic_cdk/) is out.  
There are [a few great additions](https://github.com/dfinity/cdk-rs/blob/main/src/ic-cdk/CHANGELOG.md#051---2022-05-16) hiding behind the minor version bump:

1. The [long-standing issue with panicking after .await](https://mmapped.blog/posts/01-effective-rust-canisters.html#panic-await) is finally closed. The Rust CDK will correctly free resources if you trap across async boundaries. Huge thanks to @AdamS for elegantly implementing cleanups.
2. @christian exposed [`call_raw*`](https://docs.rs/ic-cdk/0.5.1/ic_cdk/api/call/fn.call_raw.html) and [`arg_data_raw`](https://docs.rs/ic-cdk/0.5.1/ic_cdk/api/call/fn.arg_data_raw.html) functions. This API allows you to call canisters that do not encode their arguments as Candid or forward calls without decoding the payload.
3. @hpeebles implemented [`BufferedStableReader`](https://docs.rs/ic-cdk/0.5.1/ic_cdk/api/stable/struct.BufferedStableReader.html) and [`BufferedStableWriter`](https://docs.rs/ic-cdk/0.5.1/ic_cdk/api/stable/struct.BufferedStableWriter.html) API for more efficient serialization (don’t forget to measure when you optimize!).
4. @roman-kashitsyn added [`notify*`](https://docs.rs/ic-cdk/0.5.1/ic_cdk/api/call/fn.notify_with_payment128.html) family of functions relying on the trick that @nomeata described in his [blog post](https://www.joachim-breitner.de/blog/789-Zero-downtime_upgrades_of_Internet_Computer_canisters#one-way-calls). If your canister uses _only_ `notify*` calls, it safe to upgrade the canister without stopping it first. The notify is a regular call setting a non-existing function as a callback. One practical implication of that implementation is that you get a refund if you attach cycles to the notification and the destination canister traps.

Enjoy building on the IC with the improved Rust CDK!

---

<div class="post-metadata">

**Author:** ![jzxchiang](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/jzxchiang/32/2592_2.png) [@jzxchiang](https://forum.dfinity.org/u/jzxchiang)\
**Post date:** [May 18, 2022, 10:26pm UTC](https://forum.dfinity.org/t/rust-cdk-v0-5-1-is-out/13086/2 "2022-05-18T22:26:24Z")

</div>

> 1. @roman-kashitsyn added [`notify*`](https://docs.rs/ic-cdk/0.5.1/ic_cdk/api/call/fn.notify_with_payment128.html) family of functions relying on the trick that @nomeata described in his [blog post](https://www.joachim-breitner.de/blog/789-Zero-downtime_upgrades_of_Internet_Computer_canisters#one-way-calls). If your canister uses _only_ `notify*` calls, it safe to upgrade the canister without stopping it first. The notify is a regular call setting a non-existing function as a callback. One practical implication of that implementation is that you get a refund if you attach cycles to the notification and the destination canister traps.

Very exciting! Do you happen to know if and when Motoko will support the same thing?

---

<div class="post-metadata">

**Author:** ![nomeata](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/nomeata/32/733_2.png) [@nomeata](https://forum.dfinity.org/u/nomeata)\
**Post date:** [May 19, 2022, 6:16am UTC](https://forum.dfinity.org/t/rust-cdk-v0-5-1-is-out/13086/3 "2022-05-19T06:16:29Z")

</div>

Since [0.6.17](https://github.com/dfinity/motoko/releases/tag/0.6.17), released last December. Sometimes Motoko isn’t last 🙂

---

<div class="post-metadata">

**Author:** ![GLdev](https://avatars.discourse-cdn.com/v4/letter/g/4bbf92/32.png) [@GLdev](https://forum.dfinity.org/u/GLdev)\
**Post date:** [May 19, 2022, 6:18am UTC](https://forum.dfinity.org/t/rust-cdk-v0-5-1-is-out/13086/4 "2022-05-19T06:18:11Z")

</div>

> [@roman-kashitsyn](#):
>
> @roman-kashitsyn added [`notify*`](https://docs.rs/ic-cdk/0.5.1/ic_cdk/api/call/fn.notify_with_payment128.html) family of functions relying on the trick that @nomeata described in his [blog post](https://www.joachim-breitner.de/blog/789-Zero-downtime_upgrades_of_Internet_Computer_canisters#one-way-calls). If your canister uses _only_ `notify*` calls, it safe to upgrade the canister without stopping it first. The notify is a regular call setting a non-existing function as a callback. One practical implication of that implementation is that you get a refund if you attach cycles to the notification and the destination canister traps.

Wooot! Nice work, very excited to try this.

---

<div class="post-metadata">

**Author:** ![levi](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/levi/32/22608_2.png) [@levi](https://forum.dfinity.org/u/levi)\
**Post date:** [May 27, 2022, 12:17am UTC](https://forum.dfinity.org/t/rust-cdk-v0-5-1-is-out/13086/6 "2022-05-27T00:17:39Z")

</div>

> [@roman-kashitsyn](#):
>
> The Rust CDK will correctly free resources if you trap across async boundaries. Huge thanks to @AdamS for elegantly implementing cleanups.

Hi @AdamS, can we hear about the elegance of these cleanups?  
How does it work and how is it used?

---

<div class="post-metadata">

**Author:** ![flyq](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/flyq/32/3637_2.png) [@flyq](https://forum.dfinity.org/u/flyq)\
**Post date:** [May 27, 2022, 12:48am UTC](https://forum.dfinity.org/t/rust-cdk-v0-5-1-is-out/13086/7 "2022-05-27T00:48:31Z")

</div>

In motoko, using ignore await canister\_a.method(xxx)

---

<div class="post-metadata">

**Author:** ![rckprtr](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/rckprtr/32/809_2.png) [@rckprtr](https://forum.dfinity.org/u/rckprtr)\
**Post date:** [May 27, 2022, 1:06am UTC](https://forum.dfinity.org/t/rust-cdk-v0-5-1-is-out/13086/8 "2022-05-27T01:06:09Z")

</div>

> 1. @hpeebles implemented [`BufferedStableReader`](https://docs.rs/ic-cdk/0.5.1/ic_cdk/api/stable/struct.BufferedStableReader.html) and [`BufferedStableWriter`](https://docs.rs/ic-cdk/0.5.1/ic_cdk/api/stable/struct.BufferedStableWriter.html) API for more efficient serialization (don’t forget to measure when you optimize!).

Curious what techniques you use to measure?

---

<div class="post-metadata">

**Author:** ![roman-kashitsyn](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/roman-kashitsyn/32/3802_2.png) [@roman-kashitsyn](https://forum.dfinity.org/u/roman-kashitsyn)\
**Post date:** [May 27, 2022, 9:00am UTC](https://forum.dfinity.org/t/rust-cdk-v0-5-1-is-out/13086/9 "2022-05-27T09:00:49Z")

</div>

You can find the implementation in these PRs:

- [feat: Add cleanup code in case of await trap by adamspofford-dfinity · Pull Request #232 · dfinity/cdk-rs · GitHub](https://github.com/dfinity/cdk-rs/pull/232)
- [chore(SDK-417): add an e2d test for async cleanup by roman-kashitsyn · Pull Request #250 · dfinity/cdk-rs · GitHub](https://github.com/dfinity/cdk-rs/pull/250)

---

<div class="post-metadata">

**Author:** ![claudio](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/claudio/32/322_2.png) [@claudio](https://forum.dfinity.org/u/claudio)\
**Post date:** [May 27, 2022, 11:01am UTC](https://forum.dfinity.org/t/rust-cdk-v0-5-1-is-out/13086/10 "2022-05-27T11:01:22Z")

</div>

> [@flyq](#):
>
> In motoko, using ignore await canister\_a.method(xxx)

Actually, I don’t think that’s correct. The shared function needs to be declared as a oneway function (returning `()`, not `async ()`) and just called without an await.

So, for this example:

Actor:

```auto
actor canister_a {
    // `()` return declares a Candid oneway function that can't be awaited. 
   public shared func method() : () { 
     ...
   };
}

```

Client:

```auto
   canister_a.method(); // no `await` possible (given return type of `()`, not `async ()`)

```

Ain’'t that right, @nomeata?

---

<div class="post-metadata">

**Author:** ![AdamS](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/adams/32/5248_2.png) [@AdamS](https://forum.dfinity.org/u/AdamS)\
**Post date:** [May 27, 2022, 3:08pm UTC](https://forum.dfinity.org/t/rust-cdk-v0-5-1-is-out/13086/11 "2022-05-27T15:08:56Z")

</div>

I think I would call it the exact opposite of elegant. It takes advantage of the fact that WASM is single-threaded to use global state. Essentially, it sets a global bool, executes the future, and then unsets it; the executor, when asked to execute a future, checks the global bool, and if it is set then it doesn’t actually execute the future but simply drops it.

The behavior is that all destructors are run in the case of an inter-canister trap, but execution does not continue. You can attach custom cleanup logic by placing it in a destructor via a crate like [`scope_guard`](https://docs.rs/scope-guard/latest/scope_guard/).

---

<div class="post-metadata">

**Author:** ![nomeata](https://sea1.discourse-cdn.com/flex023/user_avatar/forum.dfinity.org/nomeata/32/733_2.png) [@nomeata](https://forum.dfinity.org/u/nomeata)\
**Post date:** [May 27, 2022, 7:35pm UTC](https://forum.dfinity.org/t/rust-cdk-v0-5-1-is-out/13086/12 "2022-05-27T19:35:19Z")

</div>

> [@claudio](#):
>
> Ain’'t that right, @nomeata?

II tthhiinnkk ssoo, yyeess.
