reformatted some code
Dieser Commit ist enthalten in:
Ursprung
dbc7c9e7ef
Commit
b683e45aff
6 geänderte Dateien mit 88 neuen und 72 gelöschten Zeilen
14
rustfmt.toml
14
rustfmt.toml
|
@ -1,11 +1,13 @@
|
||||||
|
#binop_separator= "Back"
|
||||||
|
#brace_style="SameLineWhere"
|
||||||
|
#force_multiline_blocks = true
|
||||||
|
#imports_layout = "Vertical"
|
||||||
array_width = 0
|
array_width = 0
|
||||||
binop_separator= "Back"
|
attr_fn_like_width = 80
|
||||||
brace_style="SameLineWhere"
|
chain_width = 144
|
||||||
chain_width = 240
|
|
||||||
fn_params_layout = "Tall"
|
fn_params_layout = "Tall"
|
||||||
force_explicit_abi = true
|
force_explicit_abi = true
|
||||||
hard_tabs = false
|
hard_tabs = false
|
||||||
imports_layout = "Vertical"
|
|
||||||
match_block_trailing_comma = true
|
match_block_trailing_comma = true
|
||||||
max_width = 240
|
max_width = 240
|
||||||
merge_derives = true
|
merge_derives = true
|
||||||
|
@ -14,4 +16,8 @@ remove_nested_parens = true
|
||||||
reorder_imports = true
|
reorder_imports = true
|
||||||
reorder_modules = true
|
reorder_modules = true
|
||||||
single_line_if_else_max_width = 0
|
single_line_if_else_max_width = 0
|
||||||
|
single_line_let_else_max_width = 0
|
||||||
tab_spaces = 4
|
tab_spaces = 4
|
||||||
|
use_field_init_shorthand = true
|
||||||
|
use_small_heuristics = "Off"
|
||||||
|
use_try_shorthand = true
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
use std::fmt::Display;
|
use std::fmt::Display;
|
||||||
|
|
||||||
|
use crate::enum_alias;
|
||||||
|
|
||||||
use super::{Kartesian, KartesianIterator};
|
use super::{Kartesian, KartesianIterator};
|
||||||
use num::*;
|
use num::*;
|
||||||
|
|
||||||
|
@ -17,6 +19,20 @@ pub enum KartesianDirection {
|
||||||
BottomRight,
|
BottomRight,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl KartesianDirection {
|
||||||
|
enum_alias!(KartesianDirection, NorthWest, TopLeft);
|
||||||
|
enum_alias!(KartesianDirection, North, Top);
|
||||||
|
enum_alias!(KartesianDirection, Up, Top);
|
||||||
|
enum_alias!(KartesianDirection, NorthEast, TopRight);
|
||||||
|
enum_alias!(KartesianDirection, West, Left);
|
||||||
|
enum_alias!(KartesianDirection, Center, None);
|
||||||
|
enum_alias!(KartesianDirection, East, Right);
|
||||||
|
enum_alias!(KartesianDirection, SouthWest, BottomLeft);
|
||||||
|
enum_alias!(KartesianDirection, South, Bottom);
|
||||||
|
enum_alias!(KartesianDirection, Down, Bottom);
|
||||||
|
enum_alias!(KartesianDirection, SouthEast, BottomLeft);
|
||||||
|
}
|
||||||
|
|
||||||
impl KartesianDirection {
|
impl KartesianDirection {
|
||||||
pub fn vector<T: Integer>(self) -> Kartesian<T> {
|
pub fn vector<T: Integer>(self) -> Kartesian<T> {
|
||||||
Kartesian {
|
Kartesian {
|
||||||
|
|
|
@ -5,32 +5,23 @@ pub trait MaximumFromMap<T: Integer> {
|
||||||
fn maximum<U>(map: &Vec<Vec<U>>) -> Kartesian<T>;
|
fn maximum<U>(map: &Vec<Vec<U>>) -> Kartesian<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MaximumFromMap<u32> for Kartesian<u32> {
|
macro_rules! impl_maximum {
|
||||||
fn maximum<U>(map: &Vec<Vec<U>>) -> Kartesian<u32> {
|
($type:ident) => {
|
||||||
Kartesian {
|
impl MaximumFromMap<$type> for Kartesian<$type> {
|
||||||
x: map.len().to_u32().unwrap(),
|
fn maximum<U>(map: &Vec<Vec<U>>) -> Kartesian<$type> {
|
||||||
y: map[0].len().to_u32().unwrap(),
|
Kartesian {
|
||||||
|
x: map.len() as $type,
|
||||||
|
y: map[0].len() as $type,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
|
||||||
impl MaximumFromMap<u64> for Kartesian<u64> {
|
|
||||||
fn maximum<U>(map: &Vec<Vec<U>>) -> Kartesian<u64> {
|
|
||||||
Kartesian {
|
|
||||||
x: map.len().to_u64().unwrap(),
|
|
||||||
y: map[0].len().to_u64().unwrap(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl MaximumFromMap<u128> for Kartesian<u128> {
|
|
||||||
fn maximum<U>(map: &Vec<Vec<U>>) -> Kartesian<u128> {
|
|
||||||
Kartesian {
|
|
||||||
x: map.len().to_u128().unwrap(),
|
|
||||||
y: map[0].len().to_u128().unwrap(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
impl_maximum!(u8);
|
||||||
|
impl_maximum!(u16);
|
||||||
|
impl_maximum!(u32);
|
||||||
|
impl_maximum!(u64);
|
||||||
|
impl_maximum!(u128);
|
||||||
|
|
||||||
impl MaximumFromMap<usize> for Kartesian<usize> {
|
impl MaximumFromMap<usize> for Kartesian<usize> {
|
||||||
fn maximum<U>(map: &Vec<Vec<U>>) -> Kartesian<usize> {
|
fn maximum<U>(map: &Vec<Vec<U>>) -> Kartesian<usize> {
|
||||||
|
|
|
@ -18,10 +18,6 @@ pub use traits::*;
|
||||||
|
|
||||||
pub type KD = KartesianDirection;
|
pub type KD = KartesianDirection;
|
||||||
|
|
||||||
pub trait ToCoords: Copy {
|
|
||||||
fn to_coords(self) -> Kartesian<usize>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||||
pub struct Kartesian<T>
|
pub struct Kartesian<T>
|
||||||
where
|
where
|
||||||
|
@ -37,42 +33,6 @@ impl<T: Integer> Kartesian<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToCoords for Kartesian<u8> {
|
|
||||||
fn to_coords(self) -> Kartesian<usize> {
|
|
||||||
Kartesian { x: self.x as usize, y: self.y as usize }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToCoords for Kartesian<u16> {
|
|
||||||
fn to_coords(self) -> Kartesian<usize> {
|
|
||||||
Kartesian { x: self.x as usize, y: self.y as usize }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToCoords for Kartesian<u32> {
|
|
||||||
fn to_coords(self) -> Kartesian<usize> {
|
|
||||||
Kartesian { x: self.x as usize, y: self.y as usize }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToCoords for Kartesian<u64> {
|
|
||||||
fn to_coords(self) -> Kartesian<usize> {
|
|
||||||
Kartesian { x: self.x as usize, y: self.y as usize }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToCoords for Kartesian<u128> {
|
|
||||||
fn to_coords(self) -> Kartesian<usize> {
|
|
||||||
Kartesian { x: self.x as usize, y: self.y as usize }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ToCoords for Kartesian<usize> {
|
|
||||||
fn to_coords(self) -> Kartesian<usize> {
|
|
||||||
Kartesian { x: self.x, y: self.y }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn wrap<T: Integer + Rem + MaximumValue + From<u32> + Copy + MaximumValue + Display, const FACTOR: u32>(v: T, max: T) -> T {
|
fn wrap<T: Integer + Rem + MaximumValue + From<u32> + Copy + MaximumValue + Display, const FACTOR: u32>(v: T, max: T) -> T {
|
||||||
if v < max {
|
if v < max {
|
||||||
v
|
v
|
||||||
|
|
|
@ -1,9 +1,15 @@
|
||||||
use num::*;
|
use num::*;
|
||||||
|
|
||||||
macro_rules! predefined_const {
|
use crate::predefined_const;
|
||||||
($trait_name:ident, $const:ident, $t:ty) => {
|
|
||||||
impl $trait_name for $t {
|
use super::Kartesian;
|
||||||
const $const: $t = <$t>::$const;
|
|
||||||
|
macro_rules! to_coords_impl {
|
||||||
|
($subtype:ident) => {
|
||||||
|
impl ToCoords for Kartesian<$subtype> {
|
||||||
|
fn to_coords(self) -> Kartesian<usize> {
|
||||||
|
Kartesian { x: self.x as usize, y: self.y as usize }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -41,3 +47,19 @@ predefined_const!(MinimumValue, MIN, i32);
|
||||||
predefined_const!(MinimumValue, MIN, i64);
|
predefined_const!(MinimumValue, MIN, i64);
|
||||||
predefined_const!(MinimumValue, MIN, i128);
|
predefined_const!(MinimumValue, MIN, i128);
|
||||||
predefined_const!(MinimumValue, MIN, isize);
|
predefined_const!(MinimumValue, MIN, isize);
|
||||||
|
|
||||||
|
pub trait ToCoords: Copy {
|
||||||
|
fn to_coords(self) -> Kartesian<usize>;
|
||||||
|
}
|
||||||
|
|
||||||
|
to_coords_impl!(u8);
|
||||||
|
to_coords_impl!(u16);
|
||||||
|
to_coords_impl!(u32);
|
||||||
|
to_coords_impl!(u64);
|
||||||
|
to_coords_impl!(u128);
|
||||||
|
|
||||||
|
impl ToCoords for Kartesian<usize> {
|
||||||
|
fn to_coords(self) -> Kartesian<usize> {
|
||||||
|
Kartesian { x: self.x, y: self.y }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
21
src/lib.rs
21
src/lib.rs
|
@ -65,3 +65,24 @@ pub enum ExtendedOption<T> {
|
||||||
Some(T),
|
Some(T),
|
||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! enum_alias {
|
||||||
|
($enum:ident, $alias:ident, $target:ident) => {
|
||||||
|
#[allow(non_upper_case_globals)]
|
||||||
|
pub const $alias: $enum = <$enum>::$target;
|
||||||
|
};
|
||||||
|
($visibility:vis $enum:ident, $alias:ident, $target:ident) => {
|
||||||
|
#[allow(non_upper_case_globals)]
|
||||||
|
$visibility const $alias: $enum = <$enum>::$target;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! predefined_const {
|
||||||
|
($trait_name:ident, $const:ident, $t:ty) => {
|
||||||
|
impl $trait_name for $t {
|
||||||
|
const $const: $t = <$t>::$const;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
Laden …
Tabelle hinzufügen
In neuem Issue referenzieren