Introduce TupleType type alias for representing tuples
This commit is contained in:
parent
98ca788910
commit
e337520805
@ -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
|
||||
|
||||
|
@ -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<Value>,
|
||||
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<Value>) -> Self {
|
||||
pub fn type_error(actual: Value, expected: TupleType) -> Self {
|
||||
Error::TypeError { actual, expected }
|
||||
}
|
||||
|
||||
|
@ -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<bool, Error> {
|
||||
/// 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<Vec<Value>, Error> {
|
||||
pub fn eval_tuple(string: &str) -> Result<TupleType, Error> {
|
||||
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<Vec<Value>, Error> {
|
||||
) -> Result<TupleType, Error> {
|
||||
match eval_with_configuration(string, configuration) {
|
||||
Ok(Value::Tuple(tuple)) => Ok(tuple),
|
||||
Ok(value) => Err(Error::expected_tuple(value)),
|
||||
|
@ -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<Value>;
|
||||
|
||||
/// 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<Value>),
|
||||
Tuple(TupleType),
|
||||
}
|
||||
|
||||
impl Value {
|
||||
@ -89,8 +92,8 @@ impl From<bool> for Value {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Vec<Value>> for Value {
|
||||
fn from(tuple: Vec<Value>) -> Self {
|
||||
impl From<TupleType> for Value {
|
||||
fn from(tuple: TupleType) -> Self {
|
||||
Value::Tuple(tuple)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user