From 2451e711eafb11343548d8b38e7122aa5cd02876 Mon Sep 17 00:00:00 2001 From: Greg Burd Date: Sun, 19 Nov 2023 22:30:09 +0000 Subject: [PATCH] WIP --- edn/src/lib.rs | 10 +++++----- edn/src/namespaceable_name.rs | 2 +- edn/src/query.rs | 4 ++-- edn/src/types.rs | 4 ++-- edn/src/utils.rs | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/edn/src/lib.rs b/edn/src/lib.rs index dfa846ac..ab15b602 100644 --- a/edn/src/lib.rs +++ b/edn/src/lib.rs @@ -128,7 +128,7 @@ peg::parser!(pub grammar parse() for str { // result = r#""foo\\bar""# // For the typical case, string_normal_chars will match multiple, leading to a single-element vec. pub rule raw_text() -> String = "\"" t:((string_special_char() / string_normal_chars())*) "\"" - { t.join(&"") } + { t.join("") } pub rule text() -> SpannedValue = v:raw_text() { SpannedValue::Text(v) } @@ -153,16 +153,16 @@ peg::parser!(pub grammar parse() for str { "#instmicros" whitespace()+ d:$( digit()+ ) { let micros = d.parse::().unwrap(); let seconds: i64 = micros / 1_000_000; - let nanos: u32 = ((micros % 1_000_000).abs() as u32) * 1000; - Utc.timestamp(seconds, nanos) + let nanos: u32 = ((micros % 1_000_000).unsigned_abs() as u32) * 1000; + Utc.timestamp_opt(seconds, nanos).unwrap() } rule inst_millis() -> DateTime = "#instmillis" whitespace()+ d:$( digit()+ ) { let millis = d.parse::().unwrap(); let seconds: i64 = millis / 1000; - let nanos: u32 = ((millis % 1000).abs() as u32) * 1_000_000; - Utc.timestamp(seconds, nanos) + let nanos: u32 = ((millis % 1000).unsigned_abs() as u32) * 1_000_000; + Utc.timestamp_opt(seconds, nanos).unwrap() } rule inst() -> SpannedValue = t:(inst_millis() / inst_micros() / inst_string()) diff --git a/edn/src/namespaceable_name.rs b/edn/src/namespaceable_name.rs index 722aff46..fb372ba1 100644 --- a/edn/src/namespaceable_name.rs +++ b/edn/src/namespaceable_name.rs @@ -121,7 +121,7 @@ impl NamespaceableName { if name.starts_with('_') { Self::new(self.namespace(), &name[1..]) } else { - Self::new(self.namespace(), &format!("_{}", name)) + Self::new(self.namespace(), format!("_{}", name)) } } diff --git a/edn/src/query.rs b/edn/src/query.rs index a788a8f0..c2aaa185 100644 --- a/edn/src/query.rs +++ b/edn/src/query.rs @@ -1123,14 +1123,14 @@ impl OrJoin { (self.clauses, self.unify_vars, vars) } - pub fn mentioned_variables<'a>(&'a mut self) -> &'a BTreeSet { + pub fn mentioned_variables(mut self) -> BTreeSet { if self.mentioned_vars.is_none() { let m = self.collect_mentioned_variables(); self.mentioned_vars = Some(m); } if let Some(ref mentioned) = self.mentioned_vars { - mentioned + mentioned.clone() } else { unreachable!() } diff --git a/edn/src/types.rs b/edn/src/types.rs index 3622693e..4ad8f975 100644 --- a/edn/src/types.rs +++ b/edn/src/types.rs @@ -668,7 +668,7 @@ pub trait FromMicros { impl FromMicros for DateTime { fn from_micros(ts: i64) -> Self { - Utc.timestamp(ts / 1_000_000, ((ts % 1_000_000).abs() as u32) * 1_000) + Utc.timestamp_opt(ts / 1_000_000, ((ts % 1_000_000).unsigned_abs() as u32) * 1_000).unwrap() } } @@ -690,7 +690,7 @@ pub trait FromMillis { impl FromMillis for DateTime { fn from_millis(ts: i64) -> Self { - Utc.timestamp(ts / 1_000, ((ts % 1_000).abs() as u32) * 1_000) + Utc.timestamp_opt(ts / 1_000, ((ts % 1_000).abs() as u32) * 1_000).unwrap() } } diff --git a/edn/src/utils.rs b/edn/src/utils.rs index de8a9407..61b1177b 100644 --- a/edn/src/utils.rs +++ b/edn/src/utils.rs @@ -23,7 +23,7 @@ pub fn merge(left: &Value, right: &Value) -> Option { match (left, right) { (&Value::Map(ref l), &Value::Map(ref r)) => { let mut result = l.clone(); - result.extend(r.clone().into_iter()); + result.extend(r.clone()); Some(Value::Map(result)) } _ => None,