"htmlescape",
"index_vec",
"inventory",
- "itertools",
"lazy-init",
"lazy_static",
"libc",
"uds",
"url 2.2.1",
"vecdeque-stableix",
- "void",
]
[[package]]
"derive_more",
"fehler",
"if_chain",
+ "itertools",
+ "num-derive",
+ "num-traits",
"serde",
"serde_with",
"thiserror",
+ "void",
]
[[package]]
glob="0.3"
htmlescape="0.3"
inventory="0.1"
-itertools="0.10"
lazy-init="0.5"
lazy_static="1"
libc="0.2"
uds="0.2"
url="2"
vecdeque-stableix="1"
-void="1"
[dependencies.enum-map]
version="0.6"
arrayvec = "0.5"
derive_more = "0.99"
if_chain = "1"
+itertools="0.10"
+num-derive="0.3"
+num-traits="0.2"
+void="1"
# Repeated in other Cargo.toml's because importing does not work properly
fehler = "1"
// SPDX-License-Identifier: AGPL-3.0-or-later
// There is NO WARRANTY.
-use crate::imports::*;
use crate::prelude::*;
use std::ops::{Add,Sub,Mul,Neg};
+use num_traits::NumCast;
+
//---------- common types ----------
pub type Coord = i32;
pub struct AreaC<T>(pub [PosC<T>; 2]);
pub type Area = AreaC<Coord>;
+// ---------- CheckedArith ----------
+
+#[derive(Error,Clone,Copy,Debug,Serialize,Deserialize)]
+#[error("error parsing Z coordinate")]
+pub struct CoordinateOverflow;
+
+pub trait CheckedArith: Copy + Clone + Debug + 'static {
+ fn checked_add(self, rhs: Self) -> Result<Self, CoordinateOverflow>;
+ fn checked_sub(self, rhs: Self) -> Result<Self, CoordinateOverflow>;
+ fn checked_neg(self) -> Result<Self, CoordinateOverflow>;
+}
+pub trait CheckedArithMul<RHS: Copy + Clone + Debug + 'static>:
+ Copy + Clone + Debug + 'static {
+ fn checked_mul(self, rhs: RHS) -> Result<Self, CoordinateOverflow>;
+}
+
+macro_rules! checked_inherent { {$n:ident($($formal:tt)*) $($actual:tt)*} => {
+ fn $n(self $($formal)*) -> Result<Self, CoordinateOverflow> {
+ self.$n($($actual)*).ok_or(CoordinateOverflow)
+ }
+} }
+
+impl CheckedArith for i32 {
+ checked_inherent!{checked_add(, rhs: Self) rhs}
+ checked_inherent!{checked_sub(, rhs: Self) rhs}
+ checked_inherent!{checked_neg( ) }
+}
+impl CheckedArithMul<i32> for i32 {
+ checked_inherent!{checked_mul(, rhs: Self) rhs}
+}
+impl CheckedArithMul<f64> for i32 {
+ fn checked_mul(self, rhs: f64) -> Result<Self, CoordinateOverflow> {
+ let lhs: f64 = self.into();
+ let out: f64 = lhs.checked_mul(rhs)?;
+ let out: Self = NumCast::from(out).ok_or(CoordinateOverflow)?;
+ Ok(out)
+ }
+}
+
+macro_rules! checked_float { {$n:ident($($formal:tt)*) $($modify:tt)*} => {
+ fn $n(self $($formal)*) -> Result<Self, CoordinateOverflow> {
+ let out = self $($modify)*;
+ if out.is_finite() { Ok(out) } else { Err(CoordinateOverflow) }
+ }
+} }
+
+impl CheckedArith for f64 {
+ checked_float!{checked_add(, rhs: Self) + rhs }
+ checked_float!{checked_sub(, rhs: Self) - rhs }
+ checked_float!{checked_neg() .neg()}
+}
+impl CheckedArithMul<f64> for f64 {
+ checked_float!{checked_mul(, rhs: Self) * rhs }
+}
+
//---------- Pos ----------
pub trait Mean { fn mean(&self, other: &Self) -> Self; }
pub use arrayvec;
pub use derive_more;
pub use if_chain;
+pub use itertools;
+pub use num_derive;
pub use thiserror;
+pub use void;
pub mod imports;
pub mod prelude;
+pub mod geometry;
pub mod zcoord;
pub mod misc;
// This is in this crate for convenience, not because it's to do with
// Z coordinates.
-use arrayvec::ArrayVec;
-use if_chain::if_chain;
+use crate::prelude::*;
pub fn timestring_abbreviate<'x>(base: &str, this: &'x str)
-> (&'x str, bool)
}
pub fn default<T:Default>() -> T { Default::default() }
+
+#[macro_export]
+macro_rules! display_as_debug {
+ {$x:ty $( , $($gen_tt:tt)* )?} => {
+ impl $( $($gen_tt)* )? std::fmt::Display for $x {
+ #[throws(std::fmt::Error)]
+ fn fmt(&self, f: &mut std::fmt::Formatter) {
+ <Self as Debug>::fmt(self, f)?
+ }
+ }
+ }
+}
+pub use crate::display_as_debug;
pub use std::str;
pub use std::str::FromStr;
+pub use arrayvec::ArrayVec;
pub use derive_more::*;
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::Void;
+pub use crate::geometry::CoordinateOverflow;
pub use crate::misc::default;
+pub use crate::misc::display_as_debug;
const ERROR: POE = POE::PieceGone;
}
-#[macro_export]
-macro_rules! display_as_debug {
- {$x:ty $( , $($gen_tt:tt)* )?} => {
- impl $( $($gen_tt)* )? std::fmt::Display for $x {
- #[throws(std::fmt::Error)]
- fn fmt(&self, f: &mut std::fmt::Formatter) {
- <Self as Debug>::fmt(self, f)?
- }
- }
- }
-}
-pub use crate::display_as_debug;
-
#[macro_export]
macro_rules! error_from_losedetails {
{$to:ty, $variant:ident, $from:ty} => {
// SPDX-License-Identifier: AGPL-3.0-or-later
// There is NO WARRANTY.
+use crate::imports::*;
use crate::prelude::*;
#[path="vpid.rs"] mod vpid;
pub use lazy_init;
pub use lazy_static;
pub use inventory;
-pub use itertools;
pub use libc;
pub use log;
pub use nix;
-pub use num_derive;
pub use once_cell;
pub use ordered_float;
pub use parking_lot;
pub use toml;
pub use uds;
pub use vecdeque_stableix;
-pub use void;
pub mod deck;
pub mod debugreader;
pub mod error;
-pub mod geometry;
pub mod gamestate;
pub mod global;
pub mod hand;
pub const CLOCK_REALTIME : ClockId = ClockId::CLOCK_REALTIME ;
pub const CLOCK_MONOTONIC: ClockId = ClockId::CLOCK_MONOTONIC;
+pub use otter_base::geometry::{Coord,Pos,PosC,Area,AreaC};
+pub use otter_base::geometry::CoordinateOverflow;
pub use otter_base::zcoord::{self, ZCoord};
pub use otter_base::misc as base_misc;
pub use base_misc::default;
+pub use base_misc::display_as_debug;
pub use crate::dbgc;
pub use crate::{deref_to_field, deref_to_field_mut};
pub use crate::error::*;
pub use crate::fake_rng::*;
pub use crate::gamestate::*;
-pub use crate::geometry::{Coord,Pos,PosC,Area,AreaC};
pub use crate::global::*;
pub use crate::hidden::*;
pub use crate::keydata::*;
use strum::{EnumString, Display};
use thiserror::Error;
+use otter_base::geometry::{Coord,Pos};
+use otter_base::misc::display_as_debug;
+
use crate::accounts::AccountName;
-use crate::error::display_as_debug;
use crate::gamestate::PieceSpec;
-use crate::geometry::{Coord,Pos};
use crate::prelude::default;
pub use implementation::PlayerAccessSpec;
use crate::imports::*;
use crate::prelude::*;
-use std::ops::Neg;
-
#[macro_export]
macro_rules! ensure_eq {
($v1:expr, $v2:expr) => {
#[error("error parsing Z coordinate")]
pub struct FooParseError;
-#[derive(Error,Clone,Copy,Debug,Serialize,Deserialize)]
-#[error("error parsing Z coordinate")]
-pub struct CoordinateOverflow;
-
-pub trait CheckedArith: Copy + Clone + Debug + 'static {
- fn checked_add(self, rhs: Self) -> Result<Self, CoordinateOverflow>;
- fn checked_sub(self, rhs: Self) -> Result<Self, CoordinateOverflow>;
- fn checked_neg(self) -> Result<Self, CoordinateOverflow>;
-}
-pub trait CheckedArithMul<RHS: Copy + Clone + Debug + 'static>:
- Copy + Clone + Debug + 'static {
- fn checked_mul(self, rhs: RHS) -> Result<Self, CoordinateOverflow>;
-}
-
-macro_rules! checked_inherent { {$n:ident($($formal:tt)*) $($actual:tt)*} => {
- fn $n(self $($formal)*) -> Result<Self, CoordinateOverflow> {
- self.$n($($actual)*).ok_or(CoordinateOverflow)
- }
-} }
-
-impl CheckedArith for i32 {
- checked_inherent!{checked_add(, rhs: Self) rhs}
- checked_inherent!{checked_sub(, rhs: Self) rhs}
- checked_inherent!{checked_neg( ) }
-}
-impl CheckedArithMul<i32> for i32 {
- checked_inherent!{checked_mul(, rhs: Self) rhs}
-}
-impl CheckedArithMul<f64> for i32 {
- fn checked_mul(self, rhs: f64) -> Result<Self, CoordinateOverflow> {
- let lhs: f64 = self.into();
- let out: f64 = lhs.checked_mul(rhs)?;
- let out: Self = num::NumCast::from(out).ok_or(CoordinateOverflow)?;
- Ok(out)
- }
-}
-
-macro_rules! checked_float { {$n:ident($($formal:tt)*) $($modify:tt)*} => {
- fn $n(self $($formal)*) -> Result<Self, CoordinateOverflow> {
- let out = self $($modify)*;
- if out.is_finite() { Ok(out) } else { Err(CoordinateOverflow) }
- }
-} }
-
-impl CheckedArith for f64 {
- checked_float!{checked_add(, rhs: Self) + rhs }
- checked_float!{checked_sub(, rhs: Self) - rhs }
- checked_float!{checked_neg() .neg()}
-}
-impl CheckedArithMul<f64> for f64 {
- checked_float!{checked_mul(, rhs: Self) * rhs }
-}
-
pub mod timespec_serde {
use super::*;