1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
use std::cell::Cell;
use std::mem::MaybeUninit;


/// A producer element that can be assigned to once
pub trait AssignElem<T> {
    /// Assign the value `input` to the element that self represents.
    fn assign_elem(self, input: T);
}

/// Assignable element, simply `*self = input`.
impl<'a, T> AssignElem<T> for &'a mut T {
    fn assign_elem(self, input: T) {
        *self = input;
    }
}

/// Assignable element, simply `self.set(input)`.
impl<'a, T> AssignElem<T> for &'a Cell<T> {
    fn assign_elem(self, input: T) {
        self.set(input);
    }
}

/// Assignable element, the item in the MaybeUninit is overwritten (prior value, if any, is not
/// read or dropped).
impl<'a, T> AssignElem<T> for &'a mut MaybeUninit<T> {
    fn assign_elem(self, input: T) {
        *self = MaybeUninit::new(input);
    }
}