aboutsummaryrefslogtreecommitdiff
path: root/development/libs/barrel/src/types/defaults.rs
diff options
context:
space:
mode:
authorMx Kookie <kookie@spacekookie.de>2020-10-31 20:17:22 +0100
committerMx Kookie <kookie@spacekookie.de>2020-12-21 05:19:21 +0100
commita9f4dd41c11bc4255823ebad7ceabf033cf32ecf (patch)
treed91064e96e60f444076c9ffc122a47afe3b22a72 /development/libs/barrel/src/types/defaults.rs
parent534807c7a3a3b96d219ec0ce9bb0b3029aa1bdd9 (diff)
Add 'development/libs/barrel/' from commit 'f3b8ab47d3a3ad8d43dc2b89a5eec1c4e87b033d'
git-subtree-dir: development/libs/barrel git-subtree-mainline: 518551bfa6ef7d6508b425afa4bfb3ddbd418141 git-subtree-split: f3b8ab47d3a3ad8d43dc2b89a5eec1c4e87b033d
Diffstat (limited to 'development/libs/barrel/src/types/defaults.rs')
-rw-r--r--development/libs/barrel/src/types/defaults.rs89
1 files changed, 89 insertions, 0 deletions
diff --git a/development/libs/barrel/src/types/defaults.rs b/development/libs/barrel/src/types/defaults.rs
new file mode 100644
index 000000000000..ba3d75cb5ba1
--- /dev/null
+++ b/development/libs/barrel/src/types/defaults.rs
@@ -0,0 +1,89 @@
+use std::fmt::{self, Display, Formatter};
+use std::time::SystemTime;
+
+use super::Type;
+
+#[derive(PartialEq, Debug, Clone)]
+pub enum WrappedDefault<'outer> {
+ /// Any text information
+ AnyText(&'outer str),
+ /// Simple integer
+ Integer(i64),
+ /// Floating point number
+ Float(f32),
+ /// Like Float but `~ ~ d o u b l e p r e c i s i o n ~ ~`
+ Double(f64),
+ /// A unique identifier type
+ UUID(String), // TODO: Change to UUID type
+ /// True or False
+ Boolean(bool),
+ /// Date And Time
+ Date(SystemTime),
+ /// <inconceivable jibberish>
+ Binary(&'outer [u8]),
+ /// Foreign key to other table
+ Foreign(Box<Type>),
+ // I have no idea what you are – but I *like* it
+ Custom(&'static str),
+ /// Any of the above, but **many** of them
+ Array(Vec<Type>),
+}
+
+impl<'outer> Display for WrappedDefault<'outer> {
+ fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+ use self::WrappedDefault::*;
+ write!(
+ f,
+ "{}",
+ &match *self {
+ AnyText(ref val) => format!("{}", val),
+ Integer(ref val) => format!("{}", val),
+ Float(ref val) => format!("{}", val),
+ Double(ref val) => format!("{}", val),
+ UUID(ref val) => format!("{}", val),
+ Boolean(ref val) => format!("{}", val),
+ Date(ref val) => format!("{:?}", val),
+ Binary(ref val) => format!("{:?}", val),
+ Foreign(ref val) => format!("{:?}", val),
+ Custom(ref val) => format!("{}", val),
+ Array(ref val) => format!("{:?}", val),
+ }
+ )
+ }
+}
+
+impl From<&'static str> for WrappedDefault<'static> {
+ fn from(s: &'static str) -> Self {
+ WrappedDefault::AnyText(s)
+ }
+}
+
+impl From<i64> for WrappedDefault<'static> {
+ fn from(s: i64) -> Self {
+ WrappedDefault::Integer(s)
+ }
+}
+
+impl From<f32> for WrappedDefault<'static> {
+ fn from(s: f32) -> Self {
+ WrappedDefault::Float(s)
+ }
+}
+
+impl From<f64> for WrappedDefault<'static> {
+ fn from(s: f64) -> Self {
+ WrappedDefault::Double(s)
+ }
+}
+
+impl From<bool> for WrappedDefault<'static> {
+ fn from(s: bool) -> Self {
+ WrappedDefault::Boolean(s)
+ }
+}
+
+impl From<SystemTime> for WrappedDefault<'static> {
+ fn from(s: SystemTime) -> Self {
+ WrappedDefault::Date(s)
+ }
+}