chiark / gitweb /
Move shapelib docs to shapelib-toml.rs
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 12 Jan 2021 22:00:12 +0000 (22:00 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 12 Jan 2021 22:00:12 +0000 (22:00 +0000)
This seems to be working, so commit it.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/lib.rs
src/shapelib-toml.rs [new file with mode: 0644]
src/shapelib.rs

index 5594fd61a139a03fc75a12455ded42646bb3f03c..de6136ce1dd7ea4a65e96a966a6134d5ea8eaf87 100644 (file)
@@ -28,5 +28,6 @@ pub mod updates;
 pub mod ui;
 pub mod utils;
 
+#[path = "shapelib-toml.rs"]      pub mod shapelib_toml;
 #[path = "slotmap-slot-idx.rs"]   pub mod slotmap_slot_idx;
 #[path = "toml-de.rs"]            pub mod toml_de;
diff --git a/src/shapelib-toml.rs b/src/shapelib-toml.rs
new file mode 100644 (file)
index 0000000..838d0e6
--- /dev/null
@@ -0,0 +1,55 @@
+// Copyright 2020-2021 Ian Jackson and contributors to Otter
+// SPDX-License-Identifier: AGPL-3.0-or-later
+// There is NO WARRANTY.
+
+pub use crate::imports::*;
+
+pub type IE = InternalError;
+pub type LLE = shapelib::LibraryLoadError;
+
+#[derive(Debug,Deserialize)]
+pub struct GroupDetails {
+  /// Should be either a 1- or 2- element list, x and y, or just one
+  /// number for both.
+  pub size: Vec<f64>, // scaled when put into GroupData
+  #[serde(default)] pub centre: [f64; 2],
+  #[serde(default)] pub flip: bool,
+  /// `size` and `centre` are in the SVG's own internal coordinate
+  /// system, not the Otter scaled one generated by this scale factor.
+  #[serde(default="num_traits::identities::One::one")] pub scale: f64,
+  #[serde(default)] pub colours: HashMap<String, RecolourData>,
+  /// One of `"Circle"` or `"Square"`
+  #[serde(flatten)] pub outline: Box<dyn shapelib::OutlineDefn>,
+}
+
+#[derive(Debug,Deserialize)]
+pub struct RecolourData {
+  pub abbrev: String,
+  #[cfg(doc)]
+  /// Each entry is `"from" = "to"` where both are 6-character
+  /// RGB hex strings (without the leading `#`).
+  pub map: HashMap<String, String>,
+}
+
+#[derive(Debug,Deserialize)]
+pub struct GroupDefn {
+  /// `files` is a multi-line string, each line of which has three
+  /// fields (the first two terminated by whitespace).  The fields
+  /// are those in `FileData`.
+  pub files: FileList,
+  #[serde(default)] pub item_prefix: String,
+  #[serde(default)] pub item_suffix: String,
+  #[serde(flatten)] pub d: GroupDetails,
+}
+
+#[derive(Deserialize,Debug)]
+#[serde(try_from="String")]
+pub struct FileList(pub Vec<FileData>);
+
+#[derive(Deserialize,Debug)]
+pub struct FileData {
+  pub item_spec: String,
+  #[cfg(doc)] pub r_file_spec: String,
+  #[cfg(not(doc))] pub r_file_spec: (),
+  pub desc: Html,
+}
index 47594b13b5ba9747243098b9b3cdc31cebd2ed99..be5a37dc5624d9ffd226e86bcbfd78a05d6d04c4 100644 (file)
@@ -3,6 +3,7 @@
 // There is NO WARRANTY.
 
 pub use crate::imports::*;
+pub use crate::shapelib_toml::*;
 
 use parking_lot::{const_rwlock, RwLock};
 use parking_lot::{MappedRwLockReadGuard, RwLockReadGuard};
@@ -16,6 +17,18 @@ use parking_lot::{MappedRwLockReadGuard, RwLockReadGuard};
 
 pub type Registry = HashMap<String, shapelib::Contents>;
 
+#[derive(Debug)]
+pub struct GroupData {
+  pub groupname: String,
+  pub d: GroupDetails,
+}
+
+#[typetag::deserialize(tag="outline")]
+pub trait OutlineDefn : Debug + Sync + Send {
+  fn check(&self, lgi: &GroupData) -> Result<(),LLE>;
+  fn load(&self, lgi: &GroupData) -> Result<Box<dyn Outline>,IE>;
+}
+
 #[derive(Debug)]
 pub struct Contents {
   libname: String,
@@ -35,55 +48,6 @@ struct ItemData {
   group: Arc<GroupData>,
 }
 
-#[derive(Debug,Deserialize)]
-struct GroupDetails {
-  size: Vec<f64>, // scaled when put into GroupData
-  #[serde(default)] centre: [f64; 2],
-  #[serde(default)] flip: bool,
-  #[serde(default="num_traits::identities::One::one")] scale: f64,
-  #[serde(default)] colours: HashMap<String, RecolourData>,
-  #[serde(flatten)] outline: Box<dyn OutlineDefn>,
-}
-
-#[derive(Debug,Deserialize)]
-struct RecolourData {
-  abbrev: String,
-  // `map` not used by Rust
-}
-
-#[derive(Debug)]
-struct GroupData {
-  groupname: String,
-  d: GroupDetails,
-}
-
-#[derive(Debug,Deserialize)]
-struct GroupDefn {
-  files: FileList,
-  #[serde(default)] item_prefix: String,
-  #[serde(default)] item_suffix: String,
-  #[serde(flatten)] d: GroupDetails,
-}
-
-#[derive(Deserialize,Debug)]
-#[serde(try_from="String")]
-struct FileList(Vec<FileData>);
-
-#[derive(Deserialize,Debug)]
-struct FileData {
-  item_spec: String,
-  r_file_spec: (), // string, in the actual source file
-  desc: Html,
-}
-
-type IE = InternalError;
-
-#[typetag::deserialize(tag="outline")]
-trait OutlineDefn : Debug + Sync + Send {
-  fn check(&self, lgi: &GroupData) -> Result<(),LLE>;
-  fn load(&self, lgi: &GroupData) -> Result<Box<dyn Outline>,IE>;
-}
-
 #[derive(Error,Debug)]
 pub enum LibraryLoadError {
   #[error(transparent)]
@@ -126,7 +90,6 @@ impl LibraryLoadError {
 
 const INHERIT_DEPTH_LIMIT: u8 = 20;
 
-type LLE = LibraryLoadError;
 type TV = toml::Value;
 type SE = SpecError;