From: Ian Jackson Date: Sat, 14 May 2022 15:29:19 +0000 (+0100) Subject: crate structure: Introduce otter-support crate X-Git-Tag: otter-1.1.0~176 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=59c9d4df25d9762b473b608ff01bbc3e767dda50;p=otter.git crate structure: Introduce otter-support crate Currently this only has tz. Signed-off-by: Ian Jackson --- diff --git a/Cargo.lock b/Cargo.lock index 5b7bb540..4a8488c5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2681,8 +2681,6 @@ dependencies = [ "bundle-sources", "byteorder", "cast_trait_object", - "chrono", - "chrono-tz", "console", "const-default", "crossbeam-utils", @@ -2707,7 +2705,6 @@ dependencies = [ "lazy-regex", "lazy_static", "libc", - "log", "mio 0.8.2", "nix 0.23.1", "num", @@ -2716,8 +2713,7 @@ dependencies = [ "once_cell", "openssh-keys", "ordered-float", - "otter-base", - "parking_lot", + "otter-support", "paste", "percent-encoding", "pwd", @@ -2734,6 +2730,7 @@ dependencies = [ "subtle", "tempfile", "tera", + "thiserror", "toml", "typetag", "uds", @@ -2831,6 +2828,20 @@ dependencies = [ "structopt", ] +[[package]] +name = "otter-support" +version = "1.0.0" +dependencies = [ + "chrono", + "chrono-tz", + "fehler", + "log", + "otter-base", + "parking_lot", + "serde", + "serde_with", +] + [[package]] name = "otter-wasm" version = "1.0.0" diff --git a/Cargo.toml b/Cargo.toml index 153f30d6..e696f42f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ [package] name="otter" -description="Otter game system; common infrastructure Rust crate." +description="Otter game system; main data structures Rust crate." version="1.0.0" license="AGPL-3.0-or-later" @@ -29,8 +29,8 @@ bundle-sources="0.0.1" [dependencies] -otter-base.path="base" -otter-base.version="=1.0.0" +otter-support.path="support" +otter-support.version="=1.0.0" anyhow="1" backtrace="0.3" @@ -38,8 +38,6 @@ base64="0.13" boolinator="2" byteorder="1.3" cast_trait_object="0.1" -chrono="0.4" -chrono-tz="0.6" console="0.15" crossbeam-utils="0.8" delegate="0.6" @@ -50,7 +48,6 @@ educe="0.4" either="1" enum_dispatch="0.3.5" env_logger="0.9" -fehler="1" fs2="0.4" glob="0.3" humantime-serde="1" @@ -59,7 +56,6 @@ lazy-init="0.5" lazy-regex="2" lazy_static="1" libc="0.2" -log="0.4" nix="0.23" num="0.4" num-derive="0.3" @@ -68,14 +64,12 @@ once_cell="1" openssh-keys="0.5" ordered-float="2" paste="1" -parking_lot="0.12" percent-encoding="2" pwd="1" rand="0.8" regex="1" rmp="0.8" rmp-serde="1" -serde_with="1" structopt="0.3" sha2="0.10" subtle="2.4" @@ -100,9 +94,14 @@ flexi_logger = { version="0.22" , features=["specfile" ] } image = { version = "0.24", default-features=false, features=["jpeg","png"] } index_vec = { version="0.1.1", features=["serde" ] } mio = { version="0.8", features=["os-ext", "os-poll" ] } -serde = { version="1" , features=["derive", "rc"] } strum = { version="0.24" , features=["derive" ] } slotmap = { package="slotmap-fork-otter", version="1", git="https://github.com/ijackson/slotmap", branch="slotmap-fork-otter", features=["serde"] } +# Repeated in other Cargo.toml's because importing does not work properly +fehler="1" +serde = { version="1" , features=["derive", "rc"] } +serde_with="1" +thiserror="1" + #fin. diff --git a/apitest/apitest.rs b/apitest/apitest.rs index 9819759f..ca3337ff 100644 --- a/apitest/apitest.rs +++ b/apitest/apitest.rs @@ -346,6 +346,7 @@ impl Result { pub mod cleanup_notify { use super::imports::*; use super::AE; + pub use super::Void; // TODO remove the need for this use anyhow::Context; use fehler::{throw, throws}; @@ -353,7 +354,6 @@ pub mod cleanup_notify { use nix::{unistd::*, fcntl::OFlag}; use nix::sys::signal::*; use nix::Error as NE; - use void::Void; use std::io; use std::os::unix::io::RawFd; use std::panic::catch_unwind; diff --git a/base/lib.rs b/base/lib.rs index 2366f15c..be02056a 100644 --- a/base/lib.rs +++ b/base/lib.rs @@ -14,6 +14,9 @@ pub mod imports; pub mod prelude; +#[path="prelude-part.rs"] +pub mod prelude_part; + pub mod geometry; pub mod html; pub mod zcoord; diff --git a/base/prelude-part.rs b/base/prelude-part.rs new file mode 100644 index 00000000..5b999183 --- /dev/null +++ b/base/prelude-part.rs @@ -0,0 +1,38 @@ +// Copyright 2020-2021 Ian Jackson and contributors to Otter +// SPDX-License-Identifier: AGPL-3.0-or-later +// There is NO WARRANTY. + +pub use std::borrow::Borrow; +pub use std::cmp::{max, Ordering}; +pub use std::convert::{TryFrom, TryInto}; +pub use std::f64::consts::TAU; +pub use std::fmt::{self, Debug, Display, Formatter, Write as _}; +pub use std::hash::{Hash, Hasher}; +pub use std::iter::{self, FusedIterator}; +pub use std::mem; +pub use std::num::{TryFromIntError, Wrapping}; +pub use std::ops::{Deref, DerefMut, Index, IndexMut}; +pub use std::str; +pub use std::str::FromStr; + +pub use arrayvec::ArrayVec; +pub use derive_more::*; +pub use extend::ext; +pub use fehler::{throw, throws}; +pub use if_chain::if_chain; +pub use itertools::{chain, iproduct, izip, zip_eq, EitherOrBoth, Itertools}; +pub use serde::{Deserialize, Serialize}; +pub use serde_with::DeserializeFromStr; +pub use serde_with::SerializeDisplay; +pub use thiserror::Error; +pub use void::Void; + +pub use crate::html::*; + +pub use crate::{pos_zip_map, pos_zip_try_map}; +pub use crate::geometry::{CoordinateOverflow, PosC, PosPromote}; +pub use crate::{dbgc, hformat, hformat_as_display, hwrite}; +pub use crate::misc::default; +pub use crate::misc::display_as_debug; + +pub use crate::if_let; diff --git a/base/prelude.rs b/base/prelude.rs index 5355dfda..01726c19 100644 --- a/base/prelude.rs +++ b/base/prelude.rs @@ -2,37 +2,5 @@ // SPDX-License-Identifier: AGPL-3.0-or-later // There is NO WARRANTY. -pub use std::borrow::Borrow; -pub use std::cmp::{max, Ordering}; -pub use std::convert::{TryFrom, TryInto}; -pub use std::f64::consts::TAU; -pub use std::fmt::{self, Debug, Display, Formatter, Write as _}; -pub use std::hash::{Hash, Hasher}; -pub use std::iter::{self, FusedIterator}; -pub use std::mem; -pub use std::num::{TryFromIntError, Wrapping}; -pub use std::ops::{Deref, DerefMut, Index, IndexMut}; -pub use std::str; -pub use std::str::FromStr; - -pub use arrayvec::ArrayVec; -pub use derive_more::*; -pub use extend::ext; -pub use fehler::{throw, throws}; -pub use if_chain::if_chain; -pub use itertools::izip; -pub use serde::{Deserialize, Serialize}; -pub use serde_with::DeserializeFromStr; -pub use serde_with::SerializeDisplay; -pub use thiserror::Error; -pub use void::{self, Void}; - -pub use crate::html::*; - -pub use crate::{pos_zip_map, pos_zip_try_map}; -pub use crate::geometry::{CoordinateOverflow, PosC, PosPromote}; -pub use crate::{dbgc, hformat, hformat_as_display, hwrite}; -pub use crate::misc::default; -pub use crate::misc::display_as_debug; - -pub use crate::if_let; +pub use crate::imports::*; +pub use crate::prelude_part::*; diff --git a/daemon/session.rs b/daemon/session.rs index aa6172de..b8903b84 100644 --- a/daemon/session.rs +++ b/daemon/session.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: AGPL-3.0-or-later // There is NO WARRANTY. -use crate::imports::*; +//use crate::imports::*; use super::*; diff --git a/src/gamestate.rs b/src/gamestate.rs index 83ed3799..e215250f 100644 --- a/src/gamestate.rs +++ b/src/gamestate.rs @@ -19,10 +19,6 @@ pub struct Generation(pub u64); visible_slotmap_key!{ VisiblePieceId(b'.') } -#[derive(Copy,Clone,Debug,Serialize,Deserialize,Eq,Ord,PartialEq,PartialOrd)] -#[serde(transparent)] -pub struct Timestamp(pub u64); /* time_t */ - #[derive(Copy,Clone,Debug,Eq,Ord,PartialEq,PartialOrd)] pub struct SpecDepth(u16); @@ -408,22 +404,6 @@ impl SpecDepth { } } -impl Timestamp { - /// Always >= previously - pub fn now() -> Timestamp { - use std::time::SystemTime; - let now = SystemTime::now() - .duration_since(SystemTime::UNIX_EPOCH) - .unwrap() - .as_secs(); - Timestamp(now) - } - - pub fn render(&self, tz: &Timezone) -> String { - tz.format(*self) - } -} - #[derive(Error, Debug)] #[error("{self:?}")] pub struct PieceTraitDowncastFailed<'p> { diff --git a/src/imports.rs b/src/imports.rs index 7c402af6..0df7da8a 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -2,16 +2,13 @@ // SPDX-License-Identifier: AGPL-3.0-or-later // There is NO WARRANTY. -pub use otter_base; -pub use otter_base::imports::*; +pub use otter_support; pub use anyhow; pub use async_condvar_fair; pub use base64; pub use boolinator; pub use cast_trait_object; -pub use chrono; -pub use chrono_tz; pub use delegate; pub use digest; pub use educe; @@ -26,11 +23,9 @@ pub use lazy_init; pub use lazy_static; pub use inventory; pub use libc; -pub use log; pub use nix; pub use once_cell; pub use ordered_float; -pub use parking_lot; pub use pwd; pub use regex; pub use rmp_serde; diff --git a/src/lib.rs b/src/lib.rs index 3c6b129e..76f80d02 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,6 +21,9 @@ pub mod imports; pub mod prelude; +#[path="prelude-part.rs"] +pub mod prelude_part; + pub mod accounts; pub mod asseturl; pub mod authproofs; @@ -55,7 +58,6 @@ pub mod shapelib; pub mod spec; pub mod termprogress; pub mod timedfd; -pub mod tz; pub mod updates; pub mod ui; pub mod utils; diff --git a/src/prelude-part.rs b/src/prelude-part.rs new file mode 100644 index 00000000..1e583f4c --- /dev/null +++ b/src/prelude-part.rs @@ -0,0 +1,235 @@ +// Copyright 2020-2021 Ian Jackson and contributors to Otter +// SPDX-License-Identifier: AGPL-3.0-or-later +// There is NO WARRANTY. + +use crate::imports::*; +use otter_support::imports::*; +use otter_base::imports::*; + +use otter_base::prelude_part::*; + +pub use std::any::Any; +pub use std::borrow::Cow; +pub use std::cmp::{self, max, min, Ordering}; +pub use std::collections::VecDeque; +pub use std::collections::{btree_map, BTreeMap}; +pub use std::collections::{btree_set, BTreeSet}; +pub use std::convert::{Infallible, TryFrom, TryInto}; +pub use std::env; +pub use std::error::Error; +pub use std::ffi::OsStr; +pub use std::fmt::Formatter; +pub use std::fmt::Write as _; +pub use std::fmt::{self, Debug, Display}; +pub use std::fs; +pub use std::fs::File; +pub use std::hash::Hash; +pub use std::io; +pub use std::io::ErrorKind; +pub use std::io::{BufRead, BufReader, BufWriter, Read, Write}; +pub use std::iter; +pub use std::iter::{repeat_with}; +pub use std::marker::PhantomData; +pub use std::num::{NonZeroUsize, TryFromIntError, Wrapping}; +pub use std::os::linux::fs::MetadataExt as _; // todo why linux for st_mode?? +pub use std::os::unix; +pub use std::os::unix::ffi::OsStrExt; +pub use std::os::unix::fs::{MetadataExt, OpenOptionsExt}; +pub use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd}; +pub use std::os::unix::net::UnixStream; +pub use std::os::unix::process::{CommandExt, ExitStatusExt}; +pub use std::net::{IpAddr, SocketAddr, ToSocketAddrs, Ipv6Addr, Ipv4Addr}; +pub use std::path::PathBuf; +pub use std::process::{exit, Child, Command, Stdio}; +pub use std::str; +pub use std::str::FromStr; +pub use std::string::ParseError; +pub use std::sync::atomic::AtomicBool; +pub use std::sync::mpsc; +pub use std::thread::{self, sleep}; +pub use std::time::{self, Duration, Instant}; + +pub use anyhow::{anyhow, ensure, Context}; +pub use async_condvar_fair::{Condvar, BatonExt as _}; +pub use boolinator::Boolinator as _; +pub use byteorder::{BigEndian, LittleEndian, ReadBytesExt, WriteBytesExt}; +pub use cast_trait_object::{dyn_upcast, DynCastExt}; +pub use const_default::ConstDefault; +pub use delegate::delegate; +pub use derive_into_owned::IntoOwned; +pub use digest::Digest; +pub use downcast_rs::{impl_downcast, Downcast}; +pub use educe::Educe; +pub use either::{Either, Left, Right}; +pub use enum_dispatch::enum_dispatch; +pub use enum_map::{Enum, EnumMap}; +pub use fehler::{throw, throws}; +pub use flexi_logger::LogSpecification; +pub use fs2::FileExt; +pub use index_vec::{define_index_type, index_vec, IndexSlice, IndexVec}; +pub use lazy_regex::regex; +pub use lazy_static::lazy_static; +pub use log::{log, log_enabled}; +pub use nix::unistd::{self, Uid}; +pub use nix::sys::time::TimeSpec; +pub use nix::time::clock_gettime; +pub use num_derive::{ToPrimitive, FromPrimitive}; +pub use num_traits::{Bounded, FromPrimitive, ToPrimitive}; +pub use ordered_float::OrderedFloat; +pub use paste::paste; +pub use percent_encoding::percent_decode_str; +pub use percent_encoding::utf8_percent_encode; +pub use percent_encoding::NON_ALPHANUMERIC; +pub use rand::distributions::Alphanumeric; +pub use rand::thread_rng; +pub use rand::Rng; +pub use rand::prelude::SliceRandom; +pub use regex::Regex; +pub use sha2::{Sha512, Sha512_256}; +pub use slotmap::{dense::DenseSlotMap, SparseSecondaryMap, Key as _}; +pub use strum::{EnumCount, EnumDiscriminants}; +pub use strum::{EnumString, EnumIter, EnumMessage, EnumProperty}; +pub use strum::{AsRefStr, IntoEnumIterator, IntoStaticStr}; +pub use subtle::ConstantTimeEq; +pub use tempfile::{self, NamedTempFile}; +pub use tera::Tera; +pub use unicase::UniCase; +pub use url::Url; +pub use vecdeque_stableix::Deque as StableIndexVecDeque; +pub use vecdeque_stableix::Offset as StableIndexOffset; +pub use void::{unreachable, Void, ResultVoidExt, ResultVoidErrExt}; +pub use crate::imports::zipfile::{self, read::ZipFile, result::ZipError}; + +use nix::time::ClockId; +pub const CLOCK_REALTIME : ClockId = ClockId::CLOCK_REALTIME ; +pub const CLOCK_MONOTONIC: ClockId = ClockId::CLOCK_MONOTONIC; + +pub use otter_base::{pos_zip_map, pos_zip_try_map}; +pub use otter_base::geometry::{self,Coord,Pos,PosC,Rect,RectC}; +pub use otter_base::geometry::{CoordinateOverflow,Region}; +pub use otter_base::zcoord::{self, ZCoord}; +pub use otter_base::misc as base_misc; +pub use otter_base::dbgc; +pub use base_misc::*; + +pub use crate::{deref_to_field, deref_to_field_mut}; +pub use crate::ensure_eq; +pub use crate::format_by_fmt_hex; +pub use crate::impl_via_ambassador; +pub use crate::matches_doesnot; +pub use crate::trace_dbg; +pub use crate::{want, wantok, wants, want_let, want_failed_internal}; +pub use crate::serde_with_compat; + +pub use crate::accounts::loaded_acl::{self, EffectiveACL, LoadedAcl, PermSet}; +pub use crate::accounts::*; +pub use crate::authproofs::{self, Authorisation, Unauthorised}; +pub use crate::authproofs::AuthorisationSuperuser; +pub use crate::asseturl::*; +pub use crate::bundles::{self, InstanceBundles, MgmtBundleListExt}; +pub use crate::childio; +pub use crate::commands::{AccessTokenInfo, AccessTokenReport, MgmtError}; +pub use crate::commands::{MgmtCommand, MgmtResponse}; +pub use crate::commands::{MgmtGameInstruction, MgmtGameResponse}; +pub use crate::commands::{MgmtBundleList, MgmtGameUpdateMode}; +pub use crate::commands::{ProgressUpdateMode}; +pub use crate::config::*; +pub use crate::debugmutex::DebugIdentify; +pub use crate::debugreader::DebugReader; +pub use crate::digestrw::{self, *}; +pub use crate::error::*; +pub use crate::fake_rng::*; +pub use crate::fake_time::*; +pub use crate::fastsplit::*; +pub use crate::gamestate::*; +pub use crate::global::*; +pub use crate::hidden::*; +pub use crate::keydata::*; +pub use crate::nwtemplates; +pub use crate::materials_format; +pub use crate::mgmtchannel::*; +pub use crate::occultilks::*; +pub use crate::organise; +pub use crate::packetframe::{FrameReader, FrameWriter, ReadFrame, WriteFrame}; +pub use crate::packetframe::{ReadExt, ResponseWriter}; +pub use crate::pcaliases::*; +pub use crate::pcrender::*; +pub use crate::pieces::*; +pub use crate::progress::{self, ProgressInfo, OriginatorExt as _}; +pub use crate::shapelib; +pub use crate::shapelib::{CircleShape, RectShape}; +pub use crate::shapelib::{ItemEnquiryData, LibraryEnquiryData}; +pub use crate::shapelib::{LibraryLoadError}; +pub use crate::slotmap_slot_idx::*; +pub use crate::spec::*; +pub use crate::spec::piece_specs::{FaceColourSpecs, SimpleCommon}; +pub use crate::toml_de; +pub use crate::timedfd::*; +pub use crate::termprogress; +pub use crate::updates::*; +pub use crate::utils::*; +pub use crate::ui::*; + +pub use crate::gamestate::RefTraitObjectPieceTraitExt as _; +pub use crate::fastsplit::RefTraitObjectPieceTraitExt as _; + +pub type SecondarySlotMap = slotmap::secondary::SecondaryMap; +pub type SvgData = Vec; +pub type Colour = Html; + +pub const MS: time::Duration = time::Duration::from_millis(1); + +// ---------- type abbreviations ---------- + +pub type AE = anyhow::Error; + +// accounts.rs +pub type AS = AccountScope; + +// commands.rs +pub type MC = MgmtCommand; +pub type ME = MgmtError; +pub type MGI = MgmtGameInstruction; +pub type MGR = MgmtGameResponse; +pub type MR = MgmtResponse; +pub type PUM = ProgressUpdateMode; + +// error.rs +pub type APOE = ApiPieceOpError; +pub type ESVU = ErrorSignaledViaUpdate; +pub type IE = InternalError; +pub type Ia = Inapplicable; +pub type POEPP = PieceOpErrorPartiallyProcessed; +pub type SvgE = SVGProcessingError; +pub type SpE = SpecError; + +// gamestate.rs +pub use PieceLoadArgs as PLA; + +// hidden.rs +pub type OccK = OccultationKind; +pub use OccultationKindGeneral as OccKG; +pub use OccultationKindAlwaysOk as OccKA; + +// materials-format.rs + +pub use materials_format::VersionError as MFVE; + +// occultilks.rs +pub type LOI = LOccultIlk; +pub type IOI = IOccultIlk; + +// pcrender.rs +pub use PriOccultedGeneral as PriOG; + +// updates.rs +pub use OpOutcomeThunkGeneric as OOTG; +pub type PUE = PreparedUpdateEntry; +pub type PUFOS = PieceUpdateFromOpSimple; +pub type PUO = PieceUpdateOp; +pub type PUOs = PieceUpdateOps; +pub type WRC = WhatResponseToClientOp; +#[allow(non_camel_case_types)] pub type PUE_P = PreparedUpdateEntry_Piece; + +// utils.rs +pub use SVGSizeError as SvSE; diff --git a/src/prelude.rs b/src/prelude.rs index d48a9cb8..74d83ff7 100644 --- a/src/prelude.rs +++ b/src/prelude.rs @@ -3,252 +3,11 @@ // There is NO WARRANTY. pub use crate::imports::*; -pub use otter_base::prelude::*; +pub use crate::prelude_part::*; -pub use std::any::Any; -pub use std::borrow::Cow; -pub use std::cmp::{self, max, min, Ordering}; -pub use std::collections::VecDeque; -pub use std::collections::{btree_map, BTreeMap}; -pub use std::collections::{btree_set, BTreeSet}; -pub use std::collections::{hash_map, HashMap, HashSet}; -pub use std::convert::{Infallible, TryFrom, TryInto}; -pub use std::env; -pub use std::error::Error; -pub use std::ffi::OsStr; -pub use std::fmt::Formatter; -pub use std::fmt::Write as _; -pub use std::fmt::{self, Debug, Display}; -pub use std::fs; -pub use std::fs::File; -pub use std::hash::Hash; -pub use std::io; -pub use std::io::ErrorKind; -pub use std::io::{BufRead, BufReader, BufWriter, Read, Write}; -pub use std::iter; -pub use std::iter::{repeat_with}; -pub use std::marker::PhantomData; -pub use std::num::{NonZeroUsize, TryFromIntError, Wrapping}; -pub use std::os::linux::fs::MetadataExt as _; // todo why linux for st_mode?? -pub use std::os::unix; -pub use std::os::unix::ffi::OsStrExt; -pub use std::os::unix::fs::{MetadataExt, OpenOptionsExt}; -pub use std::os::unix::io::{AsRawFd, IntoRawFd, RawFd}; -pub use std::os::unix::net::UnixStream; -pub use std::os::unix::process::{CommandExt, ExitStatusExt}; -pub use std::net::{IpAddr, SocketAddr, ToSocketAddrs, Ipv6Addr, Ipv4Addr}; -pub use std::path::PathBuf; -pub use std::process::{exit, Child, Command, Stdio}; -pub use std::str; -pub use std::str::FromStr; -pub use std::string::ParseError; -pub use std::sync::Arc; -pub use std::sync::atomic::AtomicBool; -pub use std::sync::mpsc; -pub use std::thread::{self, sleep}; -pub use std::time::{self, Duration, Instant}; +pub use otter_base::imports::*; +pub use otter_base::prelude_part::*; -pub use anyhow::{anyhow, ensure, Context}; -pub use async_condvar_fair::{Condvar, BatonExt as _}; -pub use arrayvec::ArrayVec; -pub use boolinator::Boolinator as _; -pub use byteorder::{BigEndian, LittleEndian, ReadBytesExt, WriteBytesExt}; -pub use cast_trait_object::{dyn_upcast, DynCastExt}; -pub use const_default::ConstDefault; -pub use delegate::delegate; -pub use derive_into_owned::IntoOwned; -pub use derive_more::*; -pub use digest::Digest; -pub use downcast_rs::{impl_downcast, Downcast}; -pub use educe::Educe; -pub use either::{Either, Left, Right}; -pub use enum_dispatch::enum_dispatch; -pub use enum_map::{Enum, EnumMap}; -pub use fehler::{throw, throws}; -pub use flexi_logger::LogSpecification; -pub use fs2::FileExt; -pub use if_chain::if_chain; -pub use index_vec::{define_index_type, index_vec, IndexSlice, IndexVec}; -pub use itertools::{chain, iproduct, izip, zip_eq, EitherOrBoth, Itertools}; -pub use lazy_regex::regex; -pub use lazy_static::lazy_static; -pub use log::{debug, error, info, trace, warn}; -pub use log::{log, log_enabled}; -pub use nix::unistd::{self, Uid}; -pub use nix::sys::time::TimeSpec; -pub use nix::time::clock_gettime; -pub use num_derive::{ToPrimitive, FromPrimitive}; -pub use num_traits::{Bounded, FromPrimitive, ToPrimitive}; -pub use ordered_float::OrderedFloat; -pub use paste::paste; -pub use percent_encoding::percent_decode_str; -pub use percent_encoding::utf8_percent_encode; -pub use percent_encoding::NON_ALPHANUMERIC; -pub use rand::distributions::Alphanumeric; -pub use rand::thread_rng; -pub use rand::Rng; -pub use rand::prelude::SliceRandom; -pub use regex::Regex; -pub use serde::ser::SerializeTuple; -pub use serde::{de::DeserializeOwned, Deserialize, Serialize}; -pub use serde::de::Error as _; -pub use serde::{Deserializer, Serializer}; -pub use serde_with::DeserializeFromStr; -pub use serde_with::SerializeDisplay; -pub use sha2::{Sha512, Sha512_256}; -pub use slotmap::{dense::DenseSlotMap, SparseSecondaryMap, Key as _}; -pub use strum::{EnumCount, EnumDiscriminants}; -pub use strum::{EnumString, EnumIter, EnumMessage, EnumProperty}; -pub use strum::{AsRefStr, IntoEnumIterator, IntoStaticStr}; -pub use subtle::ConstantTimeEq; -pub use tempfile::{self, NamedTempFile}; -pub use tera::Tera; -pub use thiserror::Error; -pub use unicase::UniCase; -pub use url::Url; -pub use vecdeque_stableix::Deque as StableIndexVecDeque; -pub use vecdeque_stableix::Offset as StableIndexOffset; -pub use void::{unreachable, Void, ResultVoidExt, ResultVoidErrExt}; -pub use crate::imports::zipfile::{self, read::ZipFile, result::ZipError}; +pub use otter_support::imports::*; +pub use otter_support::prelude_part::*; -// No debug version of this -pub use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; - -// Swap this over for debugging -pub use parking_lot::{Mutex, MutexGuard}; -//pub use crate::debugmutex::{Mutex, MutexGuard}; - -use nix::time::ClockId; -pub const CLOCK_REALTIME : ClockId = ClockId::CLOCK_REALTIME ; -pub const CLOCK_MONOTONIC: ClockId = ClockId::CLOCK_MONOTONIC; - -pub use otter_base::{pos_zip_map, pos_zip_try_map}; -pub use otter_base::geometry::{self,Coord,Pos,PosC,Rect,RectC}; -pub use otter_base::geometry::{CoordinateOverflow,Region}; -pub use otter_base::zcoord::{self, ZCoord}; -pub use otter_base::misc as base_misc; -pub use otter_base::dbgc; -pub use base_misc::*; - -pub use crate::{deref_to_field, deref_to_field_mut}; -pub use crate::ensure_eq; -pub use crate::format_by_fmt_hex; -pub use crate::impl_via_ambassador; -pub use crate::matches_doesnot; -pub use crate::trace_dbg; -pub use crate::{want, wantok, wants, want_let, want_failed_internal}; -pub use crate::serde_with_compat; - -pub use crate::accounts::loaded_acl::{self, EffectiveACL, LoadedAcl, PermSet}; -pub use crate::accounts::*; -pub use crate::authproofs::{self, Authorisation, Unauthorised}; -pub use crate::authproofs::AuthorisationSuperuser; -pub use crate::asseturl::*; -pub use crate::bundles::{self, InstanceBundles, MgmtBundleListExt}; -pub use crate::childio; -pub use crate::commands::{AccessTokenInfo, AccessTokenReport, MgmtError}; -pub use crate::commands::{MgmtCommand, MgmtResponse}; -pub use crate::commands::{MgmtGameInstruction, MgmtGameResponse}; -pub use crate::commands::{MgmtBundleList, MgmtGameUpdateMode}; -pub use crate::commands::{ProgressUpdateMode}; -pub use crate::config::*; -pub use crate::debugmutex::DebugIdentify; -pub use crate::debugreader::DebugReader; -pub use crate::digestrw::{self, *}; -pub use crate::error::*; -pub use crate::fake_rng::*; -pub use crate::fake_time::*; -pub use crate::fastsplit::*; -pub use crate::gamestate::*; -pub use crate::global::*; -pub use crate::hidden::*; -pub use crate::keydata::*; -pub use crate::nwtemplates; -pub use crate::materials_format; -pub use crate::mgmtchannel::*; -pub use crate::occultilks::*; -pub use crate::organise; -pub use crate::packetframe::{FrameReader, FrameWriter, ReadFrame, WriteFrame}; -pub use crate::packetframe::{ReadExt, ResponseWriter}; -pub use crate::pcaliases::*; -pub use crate::pcrender::*; -pub use crate::pieces::*; -pub use crate::progress::{self, ProgressInfo, OriginatorExt as _}; -pub use crate::shapelib; -pub use crate::shapelib::{CircleShape, RectShape}; -pub use crate::shapelib::{ItemEnquiryData, LibraryEnquiryData}; -pub use crate::shapelib::{LibraryLoadError}; -pub use crate::slotmap_slot_idx::*; -pub use crate::spec::*; -pub use crate::spec::piece_specs::{FaceColourSpecs, SimpleCommon}; -pub use crate::toml_de; -pub use crate::timedfd::*; -pub use crate::termprogress; -pub use crate::tz::*; -pub use crate::updates::*; -pub use crate::utils::*; -pub use crate::ui::*; - -pub use crate::gamestate::RefTraitObjectPieceTraitExt as _; -pub use crate::fastsplit::RefTraitObjectPieceTraitExt as _; - -pub type SecondarySlotMap = slotmap::secondary::SecondaryMap; -pub type SvgData = Vec; -pub type Colour = Html; - -pub const MS: time::Duration = time::Duration::from_millis(1); - -// ---------- type abbreviations ---------- - -pub type AE = anyhow::Error; - -// accounts.rs -pub type AS = AccountScope; - -// commands.rs -pub type MC = MgmtCommand; -pub type ME = MgmtError; -pub type MGI = MgmtGameInstruction; -pub type MGR = MgmtGameResponse; -pub type MR = MgmtResponse; -pub type PUM = ProgressUpdateMode; - -// error.rs -pub type APOE = ApiPieceOpError; -pub type ESVU = ErrorSignaledViaUpdate; -pub type IE = InternalError; -pub type Ia = Inapplicable; -pub type POEPP = PieceOpErrorPartiallyProcessed; -pub type SvgE = SVGProcessingError; -pub type SpE = SpecError; - -// gamestate.rs -pub use PieceLoadArgs as PLA; - -// hidden.rs -pub type OccK = OccultationKind; -pub use OccultationKindGeneral as OccKG; -pub use OccultationKindAlwaysOk as OccKA; - -// materials-format.rs - -pub use materials_format::VersionError as MFVE; - -// occultilks.rs -pub type LOI = LOccultIlk; -pub type IOI = IOccultIlk; - -// pcrender.rs -pub use PriOccultedGeneral as PriOG; - -// updates.rs -pub use OpOutcomeThunkGeneric as OOTG; -pub type PUE = PreparedUpdateEntry; -pub type PUFOS = PieceUpdateFromOpSimple; -pub type PUO = PieceUpdateOp; -pub type PUOs = PieceUpdateOps; -pub type WRC = WhatResponseToClientOp; -#[allow(non_camel_case_types)] pub type PUE_P = PreparedUpdateEntry_Piece; - -// utils.rs -pub use SVGSizeError as SvSE; diff --git a/src/shapelib-toml.rs b/src/shapelib-toml.rs index 367ac628..bd5e71be 100644 --- a/src/shapelib-toml.rs +++ b/src/shapelib-toml.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: AGPL-3.0-or-later // There is NO WARRANTY. -pub use crate::prelude::*; +use crate::prelude::*; use shapelib::OutlineDefnEnum; diff --git a/src/shapelib.rs b/src/shapelib.rs index 110a988d..475819f2 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -2,9 +2,11 @@ // SPDX-License-Identifier: AGPL-3.0-or-later // There is NO WARRANTY. -pub use crate::prelude::*; +use crate::prelude::*; pub use crate::shapelib_toml::*; +pub use crate::prelude::GoodItemName; // not sure why this is needed + use parking_lot::{const_rwlock, RwLock}; use parking_lot::RwLockReadGuard; diff --git a/src/slotmap-slot-idx.rs b/src/slotmap-slot-idx.rs index 64cf5fed..12812ee9 100644 --- a/src/slotmap-slot-idx.rs +++ b/src/slotmap-slot-idx.rs @@ -7,7 +7,7 @@ //! Provides a [`get_idx_key`](trait.KeyDataExt.html#tymethod.get_idx_version) method on //! `slotmap::KeyData`. See [KeyDataExt::get_idx_version]. -use otter_base::misc::default; +use crate::prelude::otter_base::misc::default; /// Extension trait for `slotmap::KeyData`, providing `get_idx_version`. /// diff --git a/src/spec.rs b/src/spec.rs index b259cbf1..5cb6985e 100644 --- a/src/spec.rs +++ b/src/spec.rs @@ -5,6 +5,8 @@ // game specs use crate::imports::*; +use otter_support::imports::*; +use otter_base::imports::*; use std::borrow::Cow; use std::collections::hash_map::HashMap; diff --git a/src/toml-de.rs b/src/toml-de.rs index a1310e17..589938d0 100644 --- a/src/toml-de.rs +++ b/src/toml-de.rs @@ -3,6 +3,8 @@ // There is NO WARRANTY. use crate::imports::*; +use otter_support::imports::*; +use otter_base::imports::*; use std::fmt::{Debug, Display}; use std::iter::Peekable; diff --git a/src/utils.rs b/src/utils.rs index 8c5f58be..c50e756e 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -2,9 +2,10 @@ // SPDX-License-Identifier: AGPL-3.0-or-later // There is NO WARRANTY. -use crate::imports::*; use crate::prelude::*; +pub use otter_base::imports::extend::ext; + //========== miscellany ========== // (roughly in order of implementation length) @@ -407,7 +408,7 @@ macro_rules! entry_define_insert_remove { { #[allow(non_snake_case)] mod $name_mod { - use $crate::imports::extend::ext; + use $crate::prelude::extend::ext; use $entry as Entry; use Entry::{Occupied, Vacant}; #[ext(pub, name=EntryExt)] diff --git a/support/Cargo.toml b/support/Cargo.toml new file mode 100644 index 00000000..d748536d --- /dev/null +++ b/support/Cargo.toml @@ -0,0 +1,39 @@ +# Copyright 2020-2021 Ian Jackson and contributors to Otter +# SPDX-License-Identifier: AGPL-3.0-or-later +# There is NO WARRANTY. + +[package] +name="otter-support" +description="Otter game system; support code Rust crate." + +version="1.0.0" +license="AGPL-3.0-or-later" +edition="2021" +resolver="1" # new resolver crashes! +homepage="https://www.chiark.greenend.org.uk/~ianmdlvl/otter/docs/" +repository="https://salsa.debian.org/iwj/otter" +keywords=["games"] +authors=["Ian Jackson ", + "and the contributors to Otter"] + +[lib] +name="otter_support" +path="lib.rs" + + +[dependencies] + +otter-base.path="../base" +otter-base.version="=1.0.0" + +chrono="0.4" +chrono-tz="0.6" +fehler="1" +log="0.4" +parking_lot="0.12" + +serde_with="1" + +serde = { version="1" , features=["derive", "rc"] } + +#fin. diff --git a/support/imports.rs b/support/imports.rs new file mode 100644 index 00000000..bc76d968 --- /dev/null +++ b/support/imports.rs @@ -0,0 +1,10 @@ +// Copyright 2020-2021 Ian Jackson and contributors to Otter +// SPDX-License-Identifier: AGPL-3.0-or-later +// There is NO WARRANTY. + +pub use otter_base; + +pub use chrono; +pub use chrono_tz; +pub use log; +pub use parking_lot; diff --git a/support/lib.rs b/support/lib.rs new file mode 100644 index 00000000..d06e385f --- /dev/null +++ b/support/lib.rs @@ -0,0 +1,13 @@ +// Copyright 2020-2021 Ian Jackson and contributors to Otter +// SPDX-License-Identifier: AGPL-3.0-or-later +// There is NO WARRANTY. + +pub mod imports; +pub mod prelude; + +#[path="prelude-part.rs"] +pub mod prelude_part; + +pub mod support; + +#[path="../src/tz.rs"] pub mod tz; diff --git a/support/prelude-part.rs b/support/prelude-part.rs new file mode 100644 index 00000000..fb422a55 --- /dev/null +++ b/support/prelude-part.rs @@ -0,0 +1,25 @@ +// Copyright 2020-2021 Ian Jackson and contributors to Otter +// SPDX-License-Identifier: AGPL-3.0-or-later +// There is NO WARRANTY. + +pub use std::collections::{hash_map, HashMap, HashSet}; +pub use std::sync::Arc; + +pub use log::{debug, error, info, trace, warn}; +pub use serde::ser::SerializeTuple; +pub use serde::{de::DeserializeOwned, Deserialize, Serialize}; +pub use serde::de::Error as _; +pub use serde::{Deserializer, Serializer}; +pub use serde_with::DeserializeFromStr; +pub use serde_with::SerializeDisplay; + +// No debug version of this +pub use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard}; + +// Swap this over for debugging +pub use parking_lot::{Mutex, MutexGuard}; +//pub use crate::debugmutex::{Mutex, MutexGuard}; + +pub use crate::support::*; +pub use crate::tz::*; + diff --git a/support/prelude.rs b/support/prelude.rs new file mode 100644 index 00000000..2aa0399d --- /dev/null +++ b/support/prelude.rs @@ -0,0 +1,10 @@ +// 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 use crate::prelude_part::*; + +pub use otter_base::imports::*; +pub use otter_base::prelude_part::*; + diff --git a/support/support.rs b/support/support.rs new file mode 100644 index 00000000..3296df06 --- /dev/null +++ b/support/support.rs @@ -0,0 +1,27 @@ +// Copyright 2020-2021 Ian Jackson and contributors to Otter +// SPDX-License-Identifier: AGPL-3.0-or-later +// There is NO WARRANTY. + +use crate::prelude::*; + +#[derive(Copy,Clone,Debug,Serialize,Deserialize,Eq,Ord,PartialEq,PartialOrd)] +#[serde(transparent)] +pub struct Timestamp(pub u64); /* time_t */ + +impl Timestamp { + /// Always >= previously + pub fn now() -> Timestamp { + use std::time::SystemTime; + let now = SystemTime::now() + .duration_since(SystemTime::UNIX_EPOCH) + .unwrap() + .as_secs(); + Timestamp(now) + } + + pub fn render(&self, tz: &Timezone) -> String { + tz.format(*self) + } +} + +