# Canvas unsafe code in the wild

**URL:** <https://internals.rust-lang.org/t/canvas-unsafe-code-in-the-wild/4990>\
**Category:** Unsafe Code Guidelines\
**Created:** [March 23, 2017, 1:58pm UTC](https://internals.rust-lang.org/t/canvas-unsafe-code-in-the-wild/4990 "2017-03-23T13:58:10Z")\
**Posts on this page:** 1\
**Showing post:** 34

<div class="post-metadata">

**Author:** ![briansmith](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/briansmith/32/1306_2.png) [@briansmith](https://internals.rust-lang.org/u/briansmith)\
**Post date:** [June 15, 2017, 8:18am UTC](https://internals.rust-lang.org/t/canvas-unsafe-code-in-the-wild/4990/34 "2017-06-15T08:18:48Z")

</div>

- In _ring_, we sometimes need to treat a &[u64] slice as a &[u32] slice and/or a &[u8] slice. We use `unsafe` to do this, but we would prefer it to be built into libcore or the language instead.

- For various reasons we benefit from converting a slice `&[u8]` to an array reference `&[u8; n]` after verifying that the slice has `n` elements, which requires us to use `unsafe`. This is another thing that we think should be built-in to the language and/or standard library instead.

We keep our hacks for things that should be built-in in one module:

> <https://github.com/briansmith/ring/blob/master/src/polyfill.rs>

---

_[View the full topic](https://internals.rust-lang.org/t/canvas-unsafe-code-in-the-wild/4990)._
