nushell/crates/nu-protocol/src/ty.rs

51 lines
1.4 KiB
Rust
Raw Normal View History

2021-09-02 03:29:43 +02:00
use std::fmt::Display;
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum Type {
Int,
Float,
Range,
2021-09-02 03:29:43 +02:00
Bool,
String,
Block,
2021-09-07 00:02:24 +02:00
CellPath,
2021-09-02 03:29:43 +02:00
Duration,
FilePath,
Filesize,
List(Box<Type>),
Number,
Nothing,
Record(Vec<String>, Vec<Type>),
2021-09-08 20:54:27 +02:00
Table,
2021-09-04 08:52:28 +02:00
ValueStream,
2021-09-02 03:29:43 +02:00
Unknown,
2021-09-06 01:16:27 +02:00
Error,
2021-09-23 18:42:03 +02:00
Binary,
2021-09-02 03:29:43 +02:00
}
impl Display for Type {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Type::Block => write!(f, "block"),
Type::Bool => write!(f, "bool"),
2021-09-07 00:02:24 +02:00
Type::CellPath => write!(f, "cell path"),
2021-09-02 03:29:43 +02:00
Type::Duration => write!(f, "duration"),
Type::FilePath => write!(f, "filepath"),
Type::Filesize => write!(f, "filesize"),
Type::Float => write!(f, "float"),
Type::Int => write!(f, "int"),
Type::Range => write!(f, "range"),
Type::Record(cols, vals) => write!(f, "record<{}, {:?}>", cols.join(", "), vals),
2021-09-08 20:54:27 +02:00
Type::Table => write!(f, "table"),
2021-09-02 03:29:43 +02:00
Type::List(l) => write!(f, "list<{}>", l),
Type::Nothing => write!(f, "nothing"),
Type::Number => write!(f, "number"),
Type::String => write!(f, "string"),
2021-09-04 08:52:28 +02:00
Type::ValueStream => write!(f, "value stream"),
2021-09-02 03:29:43 +02:00
Type::Unknown => write!(f, "unknown"),
2021-09-06 01:16:27 +02:00
Type::Error => write!(f, "error"),
2021-09-23 18:42:03 +02:00
Type::Binary => write!(f, "binary"),
2021-09-02 03:29:43 +02:00
}
}
}