rust-embedded / bare-metal

Abstractions common to microcontrollers
Apache License 2.0
114 stars 16 forks source link

Add inherent `impl` blocks for `Mutex<RefCell<T>>`? #43

Closed bradleyharden closed 2 years ago

bradleyharden commented 2 years ago

Based on Matrix discussions, I think I understand why the current Mutex API was chosen. However, using Mutex<RefCell<T>> is a bit more painful than I think it could be. Would it be possible to add an inherent block for Mutex<RefCell<T>>? It would basically combine .borrow(cs) with some of RefCell's methods, so that you don't end up with things like .borrow(cs).borrow_mut().

I can make a PR, but first I wanted to see if it would be a non-starter for some reason. It wouldn't be breaking, right?

adamgreig commented 2 years ago

Interesting idea! I don't think it would be breaking and it would be interesting to see what a proof of concept would look like. Certainly Mutex<RefCell> is a really common use-case so making it easier to use would be nice.