pub trait TemplateValue: Clone + Send + Sync
{
fn to_template_string( &self ) -> String;
fn from_string( s: String ) -> Self;
fn is_empty( &self ) -> bool;
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(any(feature = "archive", feature = "template"), derive(serde::Deserialize))]
#[cfg_attr(any(feature = "archive", feature = "template"), serde(untagged))]
pub enum Value
{
Bool( bool ),
Number( i64 ),
List( Vec< String > ),
String( String ),
}
#[cfg(any(feature = "archive", feature = "template"))]
impl serde ::Serialize for Value
{
fn serialize< S >( &self, serializer: S ) -> Result< S ::Ok, S ::Error >
where
S: serde ::Serializer,
{
match self
{
Value ::String( s ) => serializer.serialize_str( s ),
Value ::Number( n ) => serializer.serialize_i64( *n ),
Value ::Bool( b ) => serializer.serialize_bool( *b ),
Value ::List( items ) => serializer.serialize_str( &items.join( ", " ) ),
}
}
}
impl TemplateValue for Value
{
fn to_template_string( &self ) -> String
{
match self
{
Value ::String( s ) => s.clone(),
Value ::Number( n ) => n.to_string(),
Value ::Bool( b ) => b.to_string(),
Value ::List( items ) => items.join( ", " ),
}
}
fn from_string( s: String ) -> Self
{
Value ::String( s )
}
fn is_empty( &self ) -> bool
{
match self
{
Value ::String( s ) => s.is_empty(),
Value ::Number( _ ) | Value ::Bool( _ ) => false,
Value ::List( items ) => items.is_empty(),
}
}
}