webrtc
webrtc copied to clipboard
Newtype internal states
Currently all internal states are stored as an AtomicU8 which is not as descriptive as we can be. I think moving to a newtyped State<T> type would be more helpful in being explicit about the type that we are storing.
Below is an example of what could be used instead
struct State<T> where T: Into<u8> + From<u8> {
inner: std::sync::AtomicU8,
_: core::marker::PhantomData<T>,
}
impl <T> State<T> where T: Into<u8> + From<u8> {
fn new(state: T) -> Self {
inner: state,
_: core::marker::PhantomData,
}
fn load(&self) -> T {
self.inner.load(Ordering::SeqCst).into();
}
fn store(&mut self, state: T) {
self.inner.store(state.into(), Ordering::SeqCst);
}
}