libhaystack/haystack/val/
marker.rs

1// Copyright (C) 2020 - 2022, J2 Innovations
2
3//! Haystack Marker
4
5use crate::haystack::val::Value;
6
7/// Haystack `Marker`
8///
9/// # Example
10/// Create `Marker` value
11/// ```
12/// use libhaystack::val::*;
13///
14/// let marker_value = Value::from(Marker);
15/// assert!(marker_value.is_marker());
16///
17/// assert_eq!(Marker::try_from(&marker_value), Ok(Marker));
18///```
19#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Copy, Clone, Debug)]
20pub struct Marker;
21
22/// Converts from Marker to a `Marker` `Value`
23impl From<Marker> for Value {
24    fn from(_: Marker) -> Self {
25        Value::Marker
26    }
27}
28
29/// Tries to convert from `Marker` `Value` to a `Marker`
30impl TryFrom<&Value> for Marker {
31    type Error = &'static str;
32    fn try_from(value: &Value) -> Result<Self, Self::Error> {
33        match value {
34            Value::Marker => Ok(Marker),
35            _ => Err("Value is not an `Marker`"),
36        }
37    }
38}