From cdcd24e7b66fd668e68b888280fb2d9e8e8d5758 Mon Sep 17 00:00:00 2001 From: Sebastian Schmidt Date: Tue, 19 Mar 2019 20:30:59 +0200 Subject: [PATCH] Document value type Implements #6 partially --- src/value/mod.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/value/mod.rs b/src/value/mod.rs index a312c66..b010b4d 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -5,16 +5,24 @@ mod display; pub type IntType = i64; pub type FloatType = f64; +/// The value type used by the parser. +/// Values can be of different subtypes that are the variants of this enum. #[derive(Clone, Debug, PartialEq)] pub enum Value { + /// A string value. String(String), + /// A float value. Float(FloatType), + /// An integer value. Int(IntType), + /// A boolean value. Boolean(bool), + /// A tuple value. Tuple(Vec), } impl Value { + /// Returns true if `self` is a `Value::Int`. pub fn is_int(&self) -> bool { match self { Value::Int(_) => true, @@ -22,6 +30,7 @@ impl Value { } } + /// Returns true if `self` is a `Value::Float`. pub fn is_float(&self) -> bool { match self { Value::Float(_) => true, @@ -29,6 +38,7 @@ impl Value { } } + /// Returns `self` as a `IntType`, or `Err` if `self` is not a `Value::Int`. pub fn as_int(&self) -> Result { match self { Value::Int(i) => Ok(*i), @@ -36,6 +46,7 @@ impl Value { } } + /// Returns `self` as a `FloatType`, or `Err` if `self` is not a `Value::Float` or `Value::Int`. pub fn as_float(&self) -> Result { match self { Value::Float(f) => Ok(*f),