3 ms·
> As far as I understand the libraries of Rust itself can't have everything written in "safe" code. You can't express everything in safe code but wrapping an u
by akiselev 10y ago
> As far as I understand the libraries of Rust itself can't have everything written in "safe" code.
You can't express everything in safe code but wrapping an unsafe API into a safe one is relatively easy with Rust's type system. For example, typemap [1] allows you to have a unsafe hash map of types with any key type to any value through a safe wrapper that uses associated types to enforce the data structure invariants at compile time. Given a bunch of types T, for example, you can have a single safe map containing all of the mappings of Event<T> to Vec<T>, Handlers<T> to HashMap<T, FnMut(T)>, and T to &T, etc, even though transmuting random bits of memory is the definition of unsafe.
[1] https://github.com/reem/rust-typemap https://github.com/reem/rust-typemap
- acqq 10y agoI've never disputed that. This duality (higher level allows safe abstraction of the low level) existed since the higher level languages exist.