This seems to be working, so commit it.
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
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;
--- /dev/null
+// 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,
+}
// There is NO WARRANTY.
pub use crate::imports::*;
+pub use crate::shapelib_toml::*;
use parking_lot::{const_rwlock, RwLock};
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,
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)]
const INHERIT_DEPTH_LIMIT: u8 = 20;
-type LLE = LibraryLoadError;
type TV = toml::Value;
type SE = SpecError;