chiark / gitweb /
wip timestamp_abbreviate
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 26 Nov 2020 21:32:13 +0000 (21:32 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 26 Nov 2020 21:32:13 +0000 (21:32 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Cargo.lock.example
zcoord/Cargo.toml
zcoord/misc.rs [new file with mode: 0644]
zcoord/zcoord.rs

index 6b1e531da9cc8f2de0e0a0bc1e12c55c97fd54ec..89c6c15cd795be03fe4c286a13ac145940a000ad 100644 (file)
@@ -1186,8 +1186,10 @@ dependencies = [
 name = "otter-zcoord"
 version = "0.0.1"
 dependencies = [
+ "arrayvec",
  "derive_more",
  "fehler",
+ "if_chain",
  "serde",
  "serde_with",
  "thiserror",
index 7a29c1f0c5e5c90823c590757c66947c165ea537..8fa43fa56851416654efb7a74f15d35f02f474e2 100644 (file)
@@ -13,8 +13,10 @@ path = "zcoord.rs"
 
 [dependencies]
 
+arrayvec = "0"
 derive_more = "0.99"
 fehler = "1"
+if_chain = "1"
 thiserror = "1"
 serde = { version = "1", features = ["derive","rc"] }
 serde_with = "1"
diff --git a/zcoord/misc.rs b/zcoord/misc.rs
new file mode 100644 (file)
index 0000000..43531cc
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright 2020 Ian Jackson
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// There is NO WARRANTY.
+
+// This is in this crate for convenience, not because it's to do with
+// Z coordinates.
+
+use if_chain::if_chain;
+use arrayvec::ArrayVec;
+
+pub fn timesting_abbreviate<'x>(base: &str, this: &'x str) -> (&'x str, bool) {
+  fn split(s: &str) -> ArrayVec<[&str; 3]> {
+    s.splitn(3, ' ').collect()
+  }
+  let base3 = split(base);
+  let this3 = split(this);
+  let matches = |i| base3.get(i) == this3.get(i);
+  if_chain! {
+    if matches(0) && matches(2);
+    if let Some(abbrev) = this3.get(1);
+    then { (abbrev, true) }
+    else { (this, false) }
+  }
+}
index 745e4ec96d69626172e2022b189861813263edef..bab9cfd04c850ad41260195a4cf2a54cf7333509 100644 (file)
@@ -79,6 +79,8 @@ use thiserror::Error;
 use serde_with::DeserializeFromStr;
 use serde_with::SerializeDisplay;
 
+mod misc;
+
 //---------- core definitions ----------
 
 pub type RangeCount = u32;