chiark / gitweb /
wip for test
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 18 Jul 2020 11:58:46 +0000 (12:58 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 18 Jul 2020 11:58:46 +0000 (12:58 +0100)
src/bin/slotmap-slot-idx-test.rs [new file with mode: 0644]
src/slotmap-slot-idx.rs

diff --git a/src/bin/slotmap-slot-idx-test.rs b/src/bin/slotmap-slot-idx-test.rs
new file mode 100644 (file)
index 0000000..f445586
--- /dev/null
@@ -0,0 +1,2 @@
+fn main () {
+}
index 9560393c00022ca2f602de1479942bcfe47cd9d7..c764dab55796ada240b58df07da762b5ef994cbb 100644 (file)
@@ -3,12 +3,30 @@ use serde::ser::{self,*};
 use thiserror::Error;
 use std::line;
 
+pub trait KeyData {
+  fn get_idx_version(self) -> (u32, u32);
+}
+
+impl KeyData for slotmap::KeyData {
+  fn get_idx_version(self) -> (u32, u32) {
+    keydata_extract(self).unwrap()
+  }
+}
+
+pub fn keydata_extract(key : slotmap::KeyData) -> Result<(u32, u32), Error> {
+  let mut m : MainExtractor = std::default::Default::default();
+  key.serialize(&mut m)?;
+  Ok(( m.idx    .ok_or(error(line!()))?,
+       m.version.ok_or(error(line!()))? ))
+}
+
 #[derive(Error,Debug)]
-enum Error {
+pub enum Error {
   WasCustomSerialize,
   Unexpected(std::num::NonZeroU32),
 }
 
+#[derive(Default)]
 struct MainExtractor {
   idx: Option<u32>,
   version: Option<u32>,
@@ -20,7 +38,8 @@ type R<Return> = Result<Return,Error>;
 type ROk = R<()>;
 
 
-fn unexpected<T>(line: u32) -> R<T> { Err(Error::Unexpected(std::convert::TryFrom::try_from(line).unwrap())) }
+fn error(line: u32) -> Error { Error::Unexpected(std::convert::TryFrom::try_from(line).unwrap()) }
+fn unexpected<T>(line: u32) -> R<T> { Err(error(line)) }
 
 type Imp = Impossible<(),Error>;