From c079fc3153edb8ec0d47b1abacbf4690371a9cd5 Mon Sep 17 00:00:00 2001 From: timofey Date: Sun, 23 Apr 2023 16:25:40 +0000 Subject: [PATCH] import reorganized --- rustfmt.toml | 3 ++ src/core.rs | 14 ++++---- src/func/derivations.rs | 2 +- src/func/test_suite.rs | 3 +- src/func/tests.rs | 7 ++-- src/lib.rs | 2 -- src/std/atomic.rs | 3 +- src/std/atomic/plain.rs | 2 +- src/std/cast.rs | 4 +-- src/std/collections/pair.rs | 3 +- src/std/collections/stack.rs | 5 +-- src/std/inlining.rs | 10 +++--- src/std/inlining/static_pair.rs | 3 +- src/std/local_origin.rs | 3 +- src/std/nullable.rs | 5 ++- src/std/point.rs | 4 +-- src/std/tracing.rs | 8 +++-- src/std/typeless.rs | 3 +- src/testing.rs | 7 ++-- src/testing/counted.rs | 3 +- src/testing/traced.rs | 3 +- src/xrcs.rs | 64 --------------------------------- 22 files changed, 52 insertions(+), 109 deletions(-) create mode 100644 rustfmt.toml delete mode 100644 src/xrcs.rs diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..d114892 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,3 @@ +# imports_granularity = "Item" +# group_imports = "StdExternalCrate" +use_field_init_shorthand = true diff --git a/src/core.rs b/src/core.rs index b987146..04341e3 100644 --- a/src/core.rs +++ b/src/core.rs @@ -10,17 +10,17 @@ mod serialization; mod slice_deserializer; mod typeless; -pub use addresses::*; -pub use hashing::*; -pub use resolution::*; -pub use serialization::*; -pub use slice_deserializer::*; -pub use typeless::*; - use std::{error::Error, fmt::Display, rc::Rc}; use crate::func::*; +pub use self::addresses::*; +pub use self::hashing::*; +pub use self::resolution::*; +pub use self::serialization::*; +pub use self::slice_deserializer::*; +pub use self::typeless::*; + pub trait Diagnostic { fn after<'a, A>(fa: T::F<'a, A>, event: &'a str) -> T::F<'a, A>; fn before<'a, A>(fa: T::F<'a, A>, event: &'a str) -> T::F<'a, A>; diff --git a/src/func/derivations.rs b/src/func/derivations.rs index 6a2a698..37e6dce 100644 --- a/src/func/derivations.rs +++ b/src/func/derivations.rs @@ -1,6 +1,6 @@ //! Useful helper functions/methods to extrapolate the existing behaviour. -use crate::func::*; +use super::*; /// Equivalent of Haskell's `fmap`. `function-function` equivalent of [Functor::fmap]. pub fn fmap<'a, T: 'a + Functor, A: 'a, B: 'a>( diff --git a/src/func/test_suite.rs b/src/func/test_suite.rs index db12779..9ab3ce2 100644 --- a/src/func/test_suite.rs +++ b/src/func/test_suite.rs @@ -1,4 +1,5 @@ -use super::{tests::*, *}; +use super::tests::*; +use super::*; pub trait FunctorTestSuite: WeakFunctor + Eqr { fn sample<'a, A: 'a, F: FnMut(&'a dyn Fn(A) -> Self::F<'a, A>)>(f: F) diff --git a/src/func/tests.rs b/src/func/tests.rs index 8f247ba..35a0935 100644 --- a/src/func/tests.rs +++ b/src/func/tests.rs @@ -1,6 +1,9 @@ +use std::{ + fmt::Debug, + ops::{Add, AddAssign}, +}; + use super::*; -use core::fmt::Debug; -use std::ops::{Add, AddAssign}; pub struct TestResults { success: usize, diff --git a/src/lib.rs b/src/lib.rs index 8e5afd7..ab75570 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,5 +3,3 @@ pub mod func; pub mod std; #[cfg(test)] mod testing; -#[cfg(test)] -mod xrcs; diff --git a/src/std/atomic.rs b/src/std/atomic.rs index bc56b7c..e1563c0 100644 --- a/src/std/atomic.rs +++ b/src/std/atomic.rs @@ -7,7 +7,8 @@ pub mod plain; use std::marker::PhantomData; use crate::core::*; -use crate::std::*; + +use super::*; /// This trait combines functionality of [`Mentionable`] and [`Factory`], /// while limiting [`Mentionable::points`] (and corresponding [`Mentionable::topology`]) to an empty sequence. diff --git a/src/std/atomic/plain.rs b/src/std/atomic/plain.rs index 15169ef..86c184a 100644 --- a/src/std/atomic/plain.rs +++ b/src/std/atomic/plain.rs @@ -1,6 +1,6 @@ //! [`Plain`] type for storing raw byte sequnces. -use crate::std::atomic::*; +use super::*; /// Raw bytes storage. Use [`Plain::raw`] to get the data. /// diff --git a/src/std/cast.rs b/src/std/cast.rs index 670f183..2e61363 100644 --- a/src/std/cast.rs +++ b/src/std/cast.rs @@ -5,9 +5,9 @@ use std::convert::identity; -use super::typeless::*; use crate::core::*; -use crate::std::*; + +use super::{typeless::*, *}; struct CastResolver<'a, Ctx: 'a + Context> { points: Vec>>, diff --git a/src/std/collections/pair.rs b/src/std/collections/pair.rs index 9002412..c841386 100644 --- a/src/std/collections/pair.rs +++ b/src/std/collections/pair.rs @@ -4,8 +4,7 @@ use std::error::Error; use std::fmt::Display; use crate::core::*; -use crate::std::inlining::static_pair::*; -use crate::std::inlining::*; +use crate::std::inlining::{static_pair::*, *}; #[derive(Clone)] pub struct Pair { diff --git a/src/std/collections/stack.rs b/src/std/collections/stack.rs index eac33fc..775e4c7 100644 --- a/src/std/collections/stack.rs +++ b/src/std/collections/stack.rs @@ -1,10 +1,7 @@ //! Basic implementation of a stack/linked list. use crate::core::*; -use crate::std::inlining::*; -use crate::std::nullable::*; -use crate::std::point::*; -use crate::std::*; +use crate::std::{inlining::*, nullable::*, point::*, *}; /// Node containing a (nullable) reference to the next node and an element. pub struct StackNode<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> { diff --git a/src/std/inlining.rs b/src/std/inlining.rs index 5c7bbcc..4cf3d9d 100644 --- a/src/std/inlining.rs +++ b/src/std/inlining.rs @@ -2,11 +2,13 @@ pub mod static_pair; -use super::atomic::atomic_object::*; -use super::atomic::*; -use super::point::*; use crate::core::*; -use crate::std::*; + +use super::{ + atomic::{atomic_object::*, *}, + point::*, + *, +}; /// This factory should return an error on EOF. pub trait InlineableFactory {} diff --git a/src/std/inlining/static_pair.rs b/src/std/inlining/static_pair.rs index 0670e96..fae1b6c 100644 --- a/src/std/inlining/static_pair.rs +++ b/src/std/inlining/static_pair.rs @@ -3,8 +3,9 @@ use std::ops::Deref; +use crate::std::*; + use super::*; -use crate::core::*; /// Trait to represent serialisation of object's data. /// Due to serialisation being [Context]-free in RADN, diff --git a/src/std/local_origin.rs b/src/std/local_origin.rs index 9be8e4f..3beb310 100644 --- a/src/std/local_origin.rs +++ b/src/std/local_origin.rs @@ -1,7 +1,8 @@ use std::rc::Rc; use crate::core::*; -use crate::func::*; + +use super::*; impl<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> Point<'a, Ctx, A> { fn prepare_bytes_for_hashing(mentioned: &A) -> Vec { diff --git a/src/std/nullable.rs b/src/std/nullable.rs index c983480..9ef461f 100644 --- a/src/std/nullable.rs +++ b/src/std/nullable.rs @@ -1,9 +1,8 @@ //! This module introduces [`Option`]-like concepts into RADN typesystem using [`Nullable`]. -use super::inlining::*; -use super::point::*; use crate::core::*; -use crate::std::*; + +use super::{inlining::*, point::*, *}; /// Nullable reference type. Made for use as a linking element in data structures. pub enum Nullable<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> { diff --git a/src/std/point.rs b/src/std/point.rs index 46685e2..e0b0d6f 100644 --- a/src/std/point.rs +++ b/src/std/point.rs @@ -1,8 +1,6 @@ //! Module responsible for making [Point]s [Mentionable]. -use std::error::Error; -use std::fmt::Display; -use std::rc::Rc; +use std::{error::Error, fmt::Display, rc::Rc}; use crate::core::*; diff --git a/src/std/tracing.rs b/src/std/tracing.rs index 24fd45e..7b0dcec 100644 --- a/src/std/tracing.rs +++ b/src/std/tracing.rs @@ -2,9 +2,11 @@ mod trace; mod traced; use crate::core::*; -use crate::func::*; -use trace::*; -pub use traced::Traced; + +use super::*; + +use self::trace::*; +pub use self::traced::*; pub struct TracedDiagnostic; diff --git a/src/std/typeless.rs b/src/std/typeless.rs index 5a8067b..e4956e6 100644 --- a/src/std/typeless.rs +++ b/src/std/typeless.rs @@ -1,7 +1,8 @@ use std::rc::Rc; use crate::core::*; -use crate::func::*; + +use super::*; struct WrappedOrigin<'a, Ctx: 'a + Context, A: Mentionable<'a, Ctx>> { w_factory: A::Fctr, diff --git a/src/testing.rs b/src/testing.rs index 87ac8ab..5d2ea0b 100644 --- a/src/testing.rs +++ b/src/testing.rs @@ -1,14 +1,13 @@ pub mod counted; pub mod traced; -use std::error::Error; -use std::fmt::Display; -use std::rc::Rc; +use std::{error::Error, fmt::Display, rc::Rc}; + +use sha2::{Digest, Sha256}; use crate::core::*; use crate::func::*; use crate::std::cast::*; -use sha2::{Digest, Sha256}; pub struct NoDiagnostic; diff --git a/src/testing/counted.rs b/src/testing/counted.rs index 596163a..b3e55c1 100644 --- a/src/testing/counted.rs +++ b/src/testing/counted.rs @@ -1,9 +1,10 @@ use std::cmp::max; -use super::*; use crate::core::*; use crate::func::*; +use super::*; + pub struct TestContextCounted; impl Context for TestContextCounted { diff --git a/src/testing/traced.rs b/src/testing/traced.rs index ac9a22e..e14fe0b 100644 --- a/src/testing/traced.rs +++ b/src/testing/traced.rs @@ -1,8 +1,9 @@ -use super::*; use crate::core::*; use crate::func::*; use crate::std::tracing::*; +use super::*; + pub struct TestContextTraced; impl Context for TestContextTraced { diff --git a/src/xrcs.rs b/src/xrcs.rs deleted file mode 100644 index 754612a..0000000 --- a/src/xrcs.rs +++ /dev/null @@ -1,64 +0,0 @@ -/// Solutions to some exercises by Alisa Feistel. -/// Included here for their relevance to the whole Monad theme. -/// Also, Alisa is too lazy to put them in a separate project for now. -#[cfg(test)] -mod tests { - fn bind Option>(f: F, fa: Option) -> Option { - match fa { - Some(a) => f(a), - None => None, - } - } - - #[test] - fn test() { - assert_eq!(bind(|x: i32| Some(x + 3), Some(2)), Some(5)); - assert_eq!(bind(|x: i32| Some(x + 3), None), None); - assert_eq!(bind(|_: i32| None, Some(2)), None); - assert_eq!(bind(|_: i32| None, None), None); - - assert_eq!(bind(|x: &str| Some(x), Some("apple")), Some("apple")); - assert_eq!( - bind(|_: &str| Some("banana"), Some("apple")), - Some("banana") - ); - - let banana = "banana".to_string(); - assert_eq!( - bind(|_: &str| Some(banana.as_str()), Some("apple")), - Some("banana") - ); - - let banana = "banana".to_string(); - assert_eq!( - bind(|_: String| Some(banana), Some("apple".to_string())), - Some("banana".to_string()) - ); - } -} - -#[cfg(test)] -mod reftests { - fn refbind<'a, 'b, T: 'a + ?Sized, F: 'a + Fn(&'a T) -> Option<&'b T>>( - f: F, - fa: Option<&'a T>, - ) -> Option<&'b T> { - match fa { - Some(a) => f(a), - None => None, - } - } - - #[test] - fn test() { - let apple = "apple".to_string(); - let banana = "banana".to_string(); - assert_eq!( - refbind(|_: &String| Some(&banana), Some(&apple)), - Some(&banana) - ); - - let banana = "banana"; - assert_eq!(refbind(|_: &str| Some(banana), Some("apple")), Some(banana)); - } -}