summaryrefslogtreecommitdiff
path: root/src/eval/none.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-07-02 19:59:52 +0200
committerLaurenz <laurmaedje@gmail.com>2023-07-02 20:07:43 +0200
commitebfdb1dafa430786db10dad2ef7d5467c1bdbed1 (patch)
tree2bbc24ddb4124c4bb14dec0e536129d4de37b056 /src/eval/none.rs
parent3ab19185093d7709f824b95b979060ce125389d8 (diff)
Move everything into `crates/` directory
Diffstat (limited to 'src/eval/none.rs')
-rw-r--r--src/eval/none.rs74
1 files changed, 0 insertions, 74 deletions
diff --git a/src/eval/none.rs b/src/eval/none.rs
deleted file mode 100644
index ab7644a7..00000000
--- a/src/eval/none.rs
+++ /dev/null
@@ -1,74 +0,0 @@
-use std::fmt::{self, Debug, Formatter};
-
-use super::{cast, CastInfo, FromValue, IntoValue, Reflect, Value};
-use crate::diag::StrResult;
-
-/// A value that indicates the absence of any other value.
-#[derive(Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
-pub struct NoneValue;
-
-impl Reflect for NoneValue {
- fn describe() -> CastInfo {
- CastInfo::Type("none")
- }
-
- fn castable(value: &Value) -> bool {
- matches!(value, Value::None)
- }
-}
-
-impl IntoValue for NoneValue {
- fn into_value(self) -> Value {
- Value::None
- }
-}
-
-impl FromValue for NoneValue {
- fn from_value(value: Value) -> StrResult<Self> {
- match value {
- Value::None => Ok(Self),
- _ => Err(Self::error(&value)),
- }
- }
-}
-
-impl Debug for NoneValue {
- fn fmt(&self, f: &mut Formatter) -> fmt::Result {
- f.pad("none")
- }
-}
-
-cast! {
- (),
- self => Value::None,
- _: NoneValue => (),
-}
-
-impl<T: Reflect> Reflect for Option<T> {
- fn describe() -> CastInfo {
- T::describe() + NoneValue::describe()
- }
-
- fn castable(value: &Value) -> bool {
- NoneValue::castable(value) || T::castable(value)
- }
-}
-
-impl<T: IntoValue> IntoValue for Option<T> {
- fn into_value(self) -> Value {
- match self {
- Some(v) => v.into_value(),
- None => Value::None,
- }
- }
-}
-
-impl<T: FromValue> FromValue for Option<T> {
- fn from_value(value: Value) -> StrResult<Self> {
- match value {
- Value::None => Ok(None),
- v if T::castable(&v) => Ok(Some(T::from_value(v)?)),
- _ => Err(Self::error(&value)),
- }
- }
-}