From 5cd225e208c12559265844504f09d886e7178760 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Tue, 12 Jan 2021 22:00:12 +0000 Subject: [PATCH] Move shapelib docs to shapelib-toml.rs This seems to be working, so commit it. Signed-off-by: Ian Jackson --- src/lib.rs | 1 + src/shapelib-toml.rs | 55 ++++++++++++++++++++++++++++++++++++++ src/shapelib.rs | 63 +++++++++----------------------------------- 3 files changed, 69 insertions(+), 50 deletions(-) create mode 100644 src/shapelib-toml.rs diff --git a/src/lib.rs b/src/lib.rs index 5594fd61..de6136ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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 index 00000000..838d0e64 --- /dev/null +++ b/src/shapelib-toml.rs @@ -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, // 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, + /// One of `"Circle"` or `"Square"` + #[serde(flatten)] pub outline: Box, +} + +#[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, +} + +#[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); + +#[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, +} diff --git a/src/shapelib.rs b/src/shapelib.rs index 47594b13..be5a37dc 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -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; +#[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,IE>; +} + #[derive(Debug)] pub struct Contents { libname: String, @@ -35,55 +48,6 @@ struct ItemData { group: Arc, } -#[derive(Debug,Deserialize)] -struct GroupDetails { - size: Vec, // 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, - #[serde(flatten)] outline: Box, -} - -#[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); - -#[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,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; -- 2.30.2