Skip to main content

datex_core/values/value_container/ops/
neg.rs

1use crate::values::value_container::{ValueContainer, error::ValueError};
2use core::{ops::Neg, result::Result};
3
4impl Neg for ValueContainer {
5    type Output = Result<ValueContainer, ValueError>;
6
7    fn neg(self) -> Self::Output {
8        match self {
9            ValueContainer::Local(value) => (-value).map(ValueContainer::Local),
10            ValueContainer::Shared(reference) => reference
11                .with_collapsed_value_mut(|value| {
12                    (-value.clone()).map(ValueContainer::Local)
13                }),
14        }
15    }
16}