chiark / gitweb /
move our default() into zcoord::misc and use it everywhere
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 31 Jan 2021 23:47:41 +0000 (23:47 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 31 Jan 2021 23:47:41 +0000 (23:47 +0000)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/imports.rs
src/slotmap-slot-idx.rs
wasm/wasm.rs
zcoord/misc.rs
zcoord/zcoord.rs

index 467fe9e6f1ea7b26125d29c350d2b39e98794a55..88c807403b56b255bad9862406bc64b192f1cd3c 100644 (file)
@@ -77,6 +77,7 @@ pub use thiserror::Error;
 pub use url::Url;
 pub use vecdeque_stableix::Deque as StableIndexVecDeque;
 pub use zcoord::{self, ZCoord};
+pub use zcoord::misc::default;
 
 pub use crate::from_instance_lock_error;
 
@@ -109,8 +110,6 @@ pub type SecondarySlotMap<K,V> = slotmap::secondary::SecondaryMap<K,V>;
 pub type SvgData = Vec<u8>;
 pub type Colour = Html;
 
-pub fn default<T:Default>() -> T { Default::default() }
-
 #[derive(Debug,Copy,Clone)]
 pub enum Impossible { }
 display_as_debug!(Impossible);
index d571f6e0329f673e3ed85fc28ffda2840e99e615..fdaf9a14cd836642258ba5b33856e17011dbec77 100644 (file)
@@ -7,6 +7,8 @@
 //! Provides a [`get_idx_key`](trait.KeyDataExt.html#tymethod.get_idx_version) method on
 //! `slotmap::KeyData`.  See [KeyDataExt::get_idx_version].
 
+use zcoord::misc::default;
+
 /// Extension trait for `slotmap::KeyData`, providing `get_idx_version`.
 ///
 /// No-one is expected to implement this trait for anything else.
@@ -47,7 +49,7 @@ impl KeyDataExt for slotmap::KeyData {
 /// representation has changed too much.  Should not be able to fail
 /// otherwise.
 pub fn keydata_extract(key: slotmap::KeyData) -> Result<(u32, u32), Error> {
-  let mut m: MainExtractor = Default::default();
+  let mut m: MainExtractor = default();
   key.serialize(&mut m)?;
   Ok(( m.idx    .ok_or(error(line!()))?,
        m.version.ok_or(error(line!()))? ))
index 6499ce75a1a915e7fc2d7f0e2481006016c5c5bf..e6142d4c5d246859c2091bed104e552267b9bfa2 100644 (file)
@@ -10,6 +10,7 @@ use thiserror::Error;
 use wasm_bindgen::prelude::*;
 
 use zcoord::{Mutable,ZCoord};
+use zcoord::misc::default;
 
 #[derive(Error,Clone,Copy,Debug,Eq,PartialEq)]
 #[error("packed Z coordinate wrong JS type (not a string)")]
@@ -54,7 +55,7 @@ pub fn increment(packed: &JsValue) -> JsValue {
 
 #[wasm_bindgen]
 pub fn def_zcoord() -> JsValue {
-  let z: ZCoord = Default::default();
+  let z: ZCoord = default();
   z.to_string().into()
 }
 
index 31065c29749de19065873c2c25f9ac816c2d21a6..e2d170dd995d38ae1ce607e7292e6fd661a20057 100644 (file)
@@ -27,6 +27,8 @@ pub fn timestring_abbreviate<'x>(base: &str, this: &'x str)
 
 pub fn raw_angle_transform(compass: u8) -> String {
   assert!(compass < 8);
-  if compass == 0 { Default::default() }
+  if compass == 0 { default() }
   else { format!("rotate({})", -45 * (compass as i16)) }
 }
+
+pub fn default<T:Default>() -> T { Default::default() }
index b970585c78194e08a846e22a37c9769fd8e46dd3..5224a751115de6a3c12f02ccf3d5e98d25cc0def 100644 (file)
@@ -821,7 +821,7 @@ mod test {
       fn tinc(self, e: &str) -> Self { self.tincdec(e, Increment, Greater) }
       fn tdec(self, e: &str) -> Self { self.tincdec(e, Decrement, Less)    }
     }
-    let start: ZCoord = Default::default();
+    let start: ZCoord = default();
     assert_eq!(format!("{}", &start), "g000000000");
     start.clone_mut()
       .tinc("g001000000");