Skip to content

Commit

Permalink
Stop pretending that ContainerInit has any other use case besides Uns…
Browse files Browse the repository at this point in the history
…afeCell
  • Loading branch information
ivmarkov committed Jul 8, 2024
1 parent 2b096a2 commit e599c8a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion rs-matter/src/utils/blmutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use core::cell::UnsafeCell;

use embassy_sync::blocking_mutex::raw::{self, RawMutex};

use crate::utils::init::{init, ContainerInit, Init};
use crate::utils::init::{init, Init, UnsafeCellInit};

/// Blocking mutex (not async)
///
Expand Down
2 changes: 1 addition & 1 deletion rs-matter/src/utils/buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use embassy_futures::select::{select, Either};
use embassy_sync::blocking_mutex::raw::RawMutex;
use embassy_time::{Duration, Timer};

use super::init::{init, ContainerInit, Init};
use super::init::{init, Init, UnsafeCellInit};
use super::signal::Signal;

/// A trait for getting access to a `&mut T` buffer, potentially awaiting until a buffer becomes available.
Expand Down
2 changes: 1 addition & 1 deletion rs-matter/src/utils/ifmutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use core::ops::{Deref, DerefMut};

use embassy_sync::blocking_mutex::raw::RawMutex;

use super::init::{init, ContainerInit, Init};
use super::init::{init, Init, UnsafeCellInit};
use super::signal::Signal;

/// Error returned by [`Mutex::try_lock`]
Expand Down
10 changes: 4 additions & 6 deletions rs-matter/src/utils/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ use core::{cell::UnsafeCell, mem::MaybeUninit};
/// Re-export `pinned-init` because its API is very unstable currently (0.0.x)
pub use pinned_init::*;

/// A trait for retrofitting types wrapping a value with an initializer.
///
/// Types that can be retrofitted this way should be `repr(transparent)`.
pub trait ContainerInit<T> {
/// Create a new in-place initializer for the container
/// An extension trait for retrofitting `UnsafeCell` with an initializer.
pub trait UnsafeCellInit<T> {
/// Create a new in-place initializer for `UnsafeCell`
/// by using the given initializer for the value.
fn init<I: Init<T>>(value: I) -> impl Init<Self>;
}

impl<T> ContainerInit<T> for UnsafeCell<T> {
impl<T> UnsafeCellInit<T> for UnsafeCell<T> {
fn init<I: Init<T>>(value: I) -> impl Init<Self> {
unsafe {
init_from_closure::<_, Infallible>(move |slot: *mut Self| {
Expand Down
2 changes: 1 addition & 1 deletion rs-matter/src/utils/refcell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use core::mem;
use core::ops::{Deref, DerefMut};
use core::ptr::NonNull;

use super::init::{init, ContainerInit, Init};
use super::init::{init, Init, UnsafeCellInit};

/// A mutable memory location with dynamically checked borrow rules
///
Expand Down

0 comments on commit e599c8a

Please sign in to comment.