pub fn set_or_check<T>(maybe: &mut Option<T>, value: T)
where
    T: std::fmt::Debug + PartialEq
{
    let previous = maybe.replace(value);

    assert!(&previous == maybe, "Expected {:?} and {:?} to be equal", &maybe, &previous);
}

pub fn set_or_check<T>(maybe: &mut Option<T>, value: T)
where
    T: std::fmt::Debug + PartialEq
{
    let previous = maybe.replace(value);
    if previous.is_some() {
        assert!(&previous == maybe, "Expected {:?} and {:?} to be equal", &maybe, &previous);
    }
}

Handle setting the first value
Handle setting the first value

No need to check the value the first time it is replaced.
