diff --git a/.gitignore b/.gitignore index 427cd63b..07cf1c95 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,3 @@ Cargo.lock # These are backup files generated by rustfmt **/*.rs.bk -/cozo_parser/target/ diff --git a/Cargo.toml b/Cargo.toml index f9a88b11..ca484323 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,14 @@ -[workspace] -members = ["cozo_parser"] \ No newline at end of file +[package] +name = "cozo" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +pest = "2.0" +pest_derive = "2.0" +ordered-float = "2.10.0" +uuid = "0.8" +chrono = "0.4" +rocksdb = "0.18.0" \ No newline at end of file diff --git a/cozo_parser/Cargo.toml b/cozo_parser/Cargo.toml deleted file mode 100644 index 8286208e..00000000 --- a/cozo_parser/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "cozo_parser" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -pest = "2.0" -pest_derive = "2.0" -ordered-float = "2.10.0" -uuid = "0.8" -chrono = "0.4" \ No newline at end of file diff --git a/cozo_parser/src/cozo.pest b/src/cozo.pest similarity index 100% rename from cozo_parser/src/cozo.pest rename to src/cozo.pest diff --git a/cozo_parser/src/lib.rs b/src/lib.rs similarity index 85% rename from cozo_parser/src/lib.rs rename to src/lib.rs index 62d22e68..6982b077 100644 --- a/cozo_parser/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,24 @@ pub struct CozoParser; mod tests { use super::*; + #[test] + fn db() { + use rocksdb::{DB, Options}; +// NB: db is automatically closed at end of lifetime + let path = "_path_for_rocksdb_storage"; + { + let db = DB::open_default(path).unwrap(); + db.put("真二", "你好👋").unwrap(); + match db.get_pinned("真二") { + Ok(Some(value)) => println!("retrieved value {}", std::str::from_utf8(&value).unwrap()), + Ok(None) => println!("value not found"), + Err(e) => println!("operational problem encountered: {}", e), + } + db.delete(b"my key").unwrap(); + } + let _ = DB::destroy(&Options::default(), path); + } + #[test] fn identifiers() { assert_eq!(CozoParser::parse(Rule::normal_ident, "x").unwrap().as_str(), "x"); diff --git a/cozo_parser/src/value.rs b/src/value.rs similarity index 89% rename from cozo_parser/src/value.rs rename to src/value.rs index 6eba67b3..5c3cbc38 100644 --- a/cozo_parser/src/value.rs +++ b/src/value.rs @@ -104,7 +104,7 @@ impl<'a> ByteArrayParser<'a> { u if u == ValueTag::UInt as u64 => Some(ValueTag::UInt), u if u == ValueTag::List as u64 => Some(ValueTag::List), u if u == ValueTag::Dict as u64 => Some(ValueTag::Dict), - // u if u == ValueTag::Uuid as u64 => Some(ValueTag::Uuid), + u if u == ValueTag::Uuid as u64 => Some(ValueTag::Uuid), _ => { None } @@ -188,42 +188,18 @@ impl<'a> ByteArrayParser<'a> { } pub fn parse_value(&mut self) -> Option> { match self.parse_value_tag()? { - ValueTag::Null => { - Some(Value::Null) - } - ValueTag::BoolTrue => { - Some(Value::Bool(true)) - } - ValueTag::BoolFalse => { - Some(Value::Bool(false)) - } - ValueTag::FwdEdge => { - Some(Value::EdgeDir(EdgeDir::FwdEdge)) - } - ValueTag::BwdEdge => { - Some(Value::EdgeDir(EdgeDir::BwdEdge)) - } - ValueTag::Int => { - Some(Value::Int(self.parse_zigzag()?)) - } - ValueTag::Float => { - Some(Value::Float(self.parse_float()?)) - } - ValueTag::String => { - Some(Value::RefString(self.parse_string()?)) - } - ValueTag::UInt => { - Some(Value::UInt(self.parse_varint()?)) - } - ValueTag::List => { - Some(Value::List(Box::new(self.parse_list()?))) - } - ValueTag::Dict => { - Some(Value::Dict(Box::new(self.parse_dict()?))) - } - ValueTag::Uuid => { - Some(Value::Uuid(self.parse_uuid()?)) - } + ValueTag::Null => { Some(Value::Null) } + ValueTag::BoolTrue => { Some(Value::Bool(true)) } + ValueTag::BoolFalse => { Some(Value::Bool(false)) } + ValueTag::FwdEdge => { Some(Value::EdgeDir(EdgeDir::FwdEdge)) } + ValueTag::BwdEdge => { Some(Value::EdgeDir(EdgeDir::BwdEdge)) } + ValueTag::Int => { Some(Value::Int(self.parse_zigzag()?)) } + ValueTag::Float => { Some(Value::Float(self.parse_float()?)) } + ValueTag::String => { Some(Value::RefString(self.parse_string()?)) } + ValueTag::UInt => { Some(Value::UInt(self.parse_varint()?)) } + ValueTag::List => { Some(Value::List(Box::new(self.parse_list()?))) } + ValueTag::Dict => { Some(Value::Dict(Box::new(self.parse_dict()?))) } + ValueTag::Uuid => { Some(Value::Uuid(self.parse_uuid()?)) } } } pub fn compare_value(&mut self, other: &mut Self) -> Ordering { @@ -548,19 +524,18 @@ mod tests { assert_eq!(i, i2); } - // - // #[test] - // fn size() { - // println!("{:?}", std::mem::size_of::()); - // println!("{:?}", std::mem::size_of::()); - // println!("{:?}", std::mem::size_of::()); - // println!("{:?}", std::mem::size_of::, Value>>()); - // println!("{:?}", std::mem::size_of::>()); - // println!("{:?}", std::mem::size_of::>()); - // println!("{:?}", std::mem::size_of::>>()); - // println!("{:?}", std::mem::size_of::>>()); - // println!("{:?}", std::mem::size_of::()); - // println!("{:?}", std::mem::size_of::<&str>()); - // } + #[test] + fn size() { + println!("{:?}", std::mem::size_of::()); + println!("{:?}", std::mem::size_of::()); + println!("{:?}", std::mem::size_of::()); + println!("{:?}", std::mem::size_of::, Value>>()); + println!("{:?}", std::mem::size_of::>()); + println!("{:?}", std::mem::size_of::>()); + println!("{:?}", std::mem::size_of::>>()); + println!("{:?}", std::mem::size_of::>>()); + println!("{:?}", std::mem::size_of::()); + println!("{:?}", std::mem::size_of::<&str>()); + } }