diff --git a/CHANGELOG.md b/CHANGELOG.md index 491dade..0298dca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,16 +7,17 @@ * Internal alias `IntType` and `FloatType` used by the `Value` enum are now public * Error types for expecting each value type * Shortcut functions like `eval_int` to evaluate directly into a value type + * Type alias `TupleType` used to represent tuples was added ### Removed - * Removed integration tests from shipped crate + * Integration tests were removed from shipped crate ### Changed ### Fixed - * Wording of some documentation items + * Wording of some documentation items was changed to improve readability ### Deprecated diff --git a/src/error/mod.rs b/src/error/mod.rs index d214a90..7f4062e 100644 --- a/src/error/mod.rs +++ b/src/error/mod.rs @@ -7,6 +7,7 @@ use crate::value::Value; use token::PartialToken; +use value::TupleType; /// Errors used in this crate. #[derive(Debug, PartialEq)] @@ -88,7 +89,7 @@ pub enum Error { /// Only use this if there is no other error that describes the expected and provided types in more detail. TypeError { /// The expected types. - expected: Vec, + expected: TupleType, /// The actual value. actual: Value, }, @@ -166,7 +167,7 @@ impl Error { } /// Constructs `Error::TypeError{actual, expected}`. - pub fn type_error(actual: Value, expected: Vec) -> Self { + pub fn type_error(actual: Value, expected: TupleType) -> Self { Error::TypeError { actual, expected } } diff --git a/src/interface/mod.rs b/src/interface/mod.rs index 98e9c18..bfe12da 100644 --- a/src/interface/mod.rs +++ b/src/interface/mod.rs @@ -1,5 +1,6 @@ use token; use tree; +use value::TupleType; use Configuration; use EmptyConfiguration; use Error; @@ -120,7 +121,7 @@ pub fn eval_boolean(string: &str) -> Result { /// Evaluate the given expression string into a tuple. /// /// *See the [crate doc](index.html) for more examples and explanations of the expression format.* -pub fn eval_tuple(string: &str) -> Result, Error> { +pub fn eval_tuple(string: &str) -> Result { match eval(string) { Ok(Value::Tuple(tuple)) => Ok(tuple), Ok(value) => Err(Error::expected_tuple(value)), @@ -190,7 +191,7 @@ pub fn eval_boolean_with_configuration( pub fn eval_tuple_with_configuration( string: &str, configuration: &Configuration, -) -> Result, Error> { +) -> Result { match eval_with_configuration(string, configuration) { Ok(Value::Tuple(tuple)) => Ok(tuple), Ok(value) => Err(Error::expected_tuple(value)), diff --git a/src/value/mod.rs b/src/value/mod.rs index 5811fee..891b203 100644 --- a/src/value/mod.rs +++ b/src/value/mod.rs @@ -8,6 +8,9 @@ pub type IntType = i64; /// The type used to represent floats in `Value::Float`. pub type FloatType = f64; +/// The type used to represent tuples in `Value::Tuple`. +pub type TupleType = Vec; + /// The value type used by the parser. /// Values can be of different subtypes that are the variants of this enum. #[derive(Clone, Debug, PartialEq)] @@ -21,7 +24,7 @@ pub enum Value { /// A boolean value. Boolean(bool), /// A tuple value. - Tuple(Vec), + Tuple(TupleType), } impl Value { @@ -89,8 +92,8 @@ impl From for Value { } } -impl From> for Value { - fn from(tuple: Vec) -> Self { +impl From for Value { + fn from(tuple: TupleType) -> Self { Value::Tuple(tuple) } }