-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve type system implementation and represent values as union not …
…string
- Loading branch information
1 parent
1d573a9
commit 53dd7a4
Showing
15 changed files
with
236 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ pub mod object; | |
pub mod statement; | ||
pub mod transformation; | ||
pub mod types; | ||
pub mod value; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
use std::collections::HashMap; | ||
|
||
use crate::value::Value; | ||
|
||
#[derive(Clone)] | ||
pub struct GQLObject { | ||
pub attributes: HashMap<String, String>, | ||
pub attributes: HashMap<String, Value>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
use crate::types::DataType; | ||
|
||
#[derive(PartialEq, Clone)] | ||
pub enum Value { | ||
Number(i64), | ||
Text(String), | ||
Boolean(bool), | ||
Date(i64), | ||
Null, | ||
} | ||
|
||
impl Value { | ||
pub fn data_type(&self) -> DataType { | ||
return match self { | ||
Value::Number(_) => DataType::Number, | ||
Value::Text(_) => DataType::Text, | ||
Value::Boolean(_) => DataType::Boolean, | ||
Value::Date(_) => DataType::Date, | ||
Value::Null => DataType::Null, | ||
}; | ||
} | ||
|
||
pub fn literal(&self) -> String { | ||
return match self { | ||
Value::Number(i) => i.to_string(), | ||
Value::Text(s) => s.to_string(), | ||
Value::Boolean(b) => b.to_string(), | ||
Value::Date(d) => d.to_string(), | ||
Value::Null => "Null".to_string(), | ||
}; | ||
} | ||
|
||
pub fn as_number(&self) -> i64 { | ||
if let Value::Number(n) = self { | ||
return *n; | ||
} | ||
return 0; | ||
} | ||
|
||
pub fn as_text(&self) -> String { | ||
if let Value::Text(s) = self { | ||
return s.to_string(); | ||
} | ||
return "".to_owned(); | ||
} | ||
|
||
pub fn as_bool(&self) -> bool { | ||
if let Value::Boolean(b) = self { | ||
return *b; | ||
} | ||
return false; | ||
} | ||
|
||
pub fn as_date(&self) -> i64 { | ||
if let Value::Date(d) = self { | ||
return *d; | ||
} | ||
return 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.