From dda095c720764255885d4fa1178a9cff3cbfc22e Mon Sep 17 00:00:00 2001 From: Joe McCain III Date: Sun, 28 Apr 2024 12:54:32 -0500 Subject: [PATCH 01/10] update Signed-off-by: Joe McCain III --- .gitignore | 61 ++----------------- core/src/hkt/mod.rs | 7 +++ core/src/id/mod.rs | 7 ++- core/src/lib.rs | 2 +- derive/Cargo.toml | 4 ++ derive/src/lib.rs | 11 ---- .../derive.rs => derive/tests/display.rs | 11 ++-- scsys/Cargo.toml | 6 -- scsys/examples/messages.rs | 3 +- scsys/src/lib.rs | 13 ++-- 10 files changed, 39 insertions(+), 86 deletions(-) rename scsys/tests/derive.rs => derive/tests/display.rs (86%) diff --git a/.gitignore b/.gitignore index d56a6360..d77e5ac3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,61 +1,12 @@ -# Config -**/config.* -**/*.config.* -**/*.env -**/*.env.* -# Directories -**/__pycache__/ -**/__sapper__/ - -**/.DS_STORE/ -**/.artifacts/data/ -**/.cache/ -**/.docker/data/ -**/.idea/ -**/.pytest_cache/ -**/.svelte-kit/ -**/.vscode/ - -**/artifacts/ -**/build/ -**/debug/ -**/dist/ -**/env/ -**/node_modules/ +### Rust **/target/ -**/venv/ - -# File Extensions -**/*.bk -**/*.bk.* - -**/*.csv -**/*.csv.* - -**/*.db -**/*.db.* -**/*.db-*.* +**/Cargo.lock -**/*.lock -**/*.lock.* - -**/*-lock.* - -**/*.log -**/*.log.* - -**/*.whl -**/*.whl.* - -**/*.zip -**/*.zip.* +**/*.bk +**/*.bk-* -# Exceptions -!**/.circleci/config.* -!**/default.config.* -!**/*.env.example -!**/*.config.js -!**/*.config.cjs +*-log.* +**/log.* diff --git a/core/src/hkt/mod.rs b/core/src/hkt/mod.rs index a955c2ce..26497072 100644 --- a/core/src/hkt/mod.rs +++ b/core/src/hkt/mod.rs @@ -5,6 +5,7 @@ //! # Higher Kinded Types //! //! +pub use self::prelude::*; pub mod applicative; pub mod functor; @@ -33,6 +34,12 @@ hkt!(Option); hkt!(Rc); hkt!(Vec); +pub(crate) mod prelude { + pub use super::applicative::Applicative; + pub use super::functor::Functor; + pub use super::monad::Monad; +} + #[cfg(test)] mod tests { diff --git a/core/src/id/mod.rs b/core/src/id/mod.rs index f6584444..b9d8adda 100644 --- a/core/src/id/mod.rs +++ b/core/src/id/mod.rs @@ -11,10 +11,15 @@ mod kinds { pub mod atomic; pub mod indexed; + + pub(crate) mod prelude { + pub use super::atomic::AtomicId; + pub use super::indexed::IndexId; + } } pub(crate) mod prelude { - pub use super::kinds::*; + pub use super::kinds::prelude::*; pub use super::traits::*; } diff --git a/core/src/lib.rs b/core/src/lib.rs index 2175cc98..c06b37ba 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -36,7 +36,7 @@ pub mod prelude { pub use crate::DEFAULT_IGNORE_CHARS; pub use crate::errors::*; - pub use crate::hkt::*; + pub use crate::hkt::prelude::*; pub use crate::id::prelude::*; pub use crate::net::prelude::*; pub use crate::time::*; diff --git a/derive/Cargo.toml b/derive/Cargo.toml index 725cc665..c715da4e 100644 --- a/derive/Cargo.toml +++ b/derive/Cargo.toml @@ -22,6 +22,10 @@ proc-macro2 = "1" quote = "1" syn = { features = ["full"], version = "2" } +[dev-dependencies] +serde = "1" +serde_json = "1" + [package.metadata.docs.rs] all-features = true rustc-args = ["--cfg", "docsrs"] diff --git a/derive/src/lib.rs b/derive/src/lib.rs index 052867b0..f0d862be 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -21,17 +21,6 @@ pub(crate) mod utils; use proc_macro::TokenStream; use syn::{parse_macro_input, Data, DeriveInput}; -#[proc_macro_derive(SerdeDisplay)] -pub fn serde_display(input: TokenStream) -> TokenStream { - // Parse the inputs into the proper struct - let ast = parse_macro_input!(input as DeriveInput); - - // Build the impl - let gen = display::handle_serde_display(&ast.ident, &ast.generics); - - gen.into() -} - #[proc_macro_derive(Display, attributes(display))] pub fn any_display(input: TokenStream) -> TokenStream { // Parse the inputs into the proper struct diff --git a/scsys/tests/derive.rs b/derive/tests/display.rs similarity index 86% rename from scsys/tests/derive.rs rename to derive/tests/display.rs index 8d1e0796..aa4cfc34 100644 --- a/scsys/tests/derive.rs +++ b/derive/tests/display.rs @@ -1,10 +1,10 @@ /* - Appellation: derive + Appellation: default Contrib: FL03 */ #![cfg(test)] -use scsys::prelude::{SerdeDisplay, Timestamp, VariantConstructors}; +use scsys_derive::{Display, VariantConstructors}; use serde::{Deserialize, Serialize}; #[derive( @@ -12,16 +12,17 @@ use serde::{Deserialize, Serialize}; Debug, Default, Deserialize, + Display, Eq, Hash, Ord, PartialEq, PartialOrd, - SerdeDisplay, Serialize, )] +#[display] pub struct TestStruct { - timestamp: Timestamp, + pub id: usize, } #[derive(Clone, Copy, Debug, Default, Eq, Ord, PartialEq, PartialOrd, VariantConstructors)] @@ -50,4 +51,4 @@ fn test_variant_constructors() { assert_eq!(SampleUnit::b(0), SampleUnit::B(0)); assert_eq!(SampleUnit::c(0), SampleUnit::C { inner: 0 }); assert_eq!(SampleUnit::abc_def(0), SampleUnit::AbcDef(0)); -} +} \ No newline at end of file diff --git a/scsys/Cargo.toml b/scsys/Cargo.toml index e2626884..4bef4e07 100644 --- a/scsys/Cargo.toml +++ b/scsys/Cargo.toml @@ -90,12 +90,6 @@ required-features = ["actors"] name = "params" required-features = ["derive"] - -[[test]] -name = "derive" -required-features = ["serde", "derive"] - - [build-dependencies] [dependencies] diff --git a/scsys/examples/messages.rs b/scsys/examples/messages.rs index 6f7cd075..bef63bdb 100644 --- a/scsys/examples/messages.rs +++ b/scsys/examples/messages.rs @@ -2,8 +2,7 @@ Appellation: messages Creator: FL03 */ -use scsys::core::id::AtomicId; -use scsys::prelude::Message; +use scsys::prelude::{AtomicId, Message}; fn main() { let id = AtomicId::new(); diff --git a/scsys/src/lib.rs b/scsys/src/lib.rs index 77e2c686..6f43f984 100644 --- a/scsys/src/lib.rs +++ b/scsys/src/lib.rs @@ -6,29 +6,32 @@ //! //! #[doc(inline)] -pub use scsys_core as core; +pub use scsys_core::*; #[cfg(feature = "actors")] #[doc(inline)] pub use scsys_actors as actors; #[cfg(feature = "derive")] +#[doc(inline)] pub use scsys_derive::*; #[cfg(feature = "macros")] +#[doc(inline)] pub use scsys_macros::*; #[cfg(feature = "stores")] #[doc(inline)] pub use scsys_stores as stores; pub mod prelude { - #[doc(inline)] - pub use super::core::prelude::*; + #[cfg(feature = "actors")] #[doc(inline)] - pub use super::actors::prelude::*; + pub use scsys_actors::prelude::*; + #[doc(inline)] + pub use scsys_core::prelude::*; #[cfg(feature = "stores")] #[doc(inline)] - pub use crate::stores::prelude::*; + pub use scsys_stores::prelude::*; #[cfg(feature = "derive")] pub use scsys_derive::*; #[cfg(feature = "macros")] From f9e45c9c7ded18c52d0737f61e3a1060466f3fb0 Mon Sep 17 00:00:00 2001 From: Joe McCain III Date: Sun, 28 Apr 2024 13:38:59 -0500 Subject: [PATCH 02/10] update Signed-off-by: Joe McCain III --- .github/workflows/clippy.yml | 4 --- .github/workflows/rust.yml | 1 - core/src/hkt/applicative.rs | 70 +++++++++++++++--------------------- core/src/hkt/functor.rs | 47 ++++++++++++------------ core/src/hkt/mod.rs | 27 ++++++++------ core/src/hkt/monad.rs | 9 +++-- core/src/lib.rs | 13 ++++--- core/src/macros.rs | 18 ++++++++++ core/src/net/mod.rs | 17 --------- core/src/sync/atomic/mod.rs | 4 +++ core/src/sync/mod.rs | 4 +++ core/src/time/epoch.rs | 2 +- core/src/time/mod.rs | 4 +++ core/src/time/timestamp.rs | 46 ++++++++++++++++++------ core/src/traits/mod.rs | 12 +++++-- core/src/types/mod.rs | 7 ++++ derive/src/lib.rs | 36 ++++++++++++------- derive/src/params.rs | 2 +- macros/src/lib.rs | 10 ++++++ scsys/examples/derive.rs | 9 ++--- scsys/examples/params.rs | 8 ++--- scsys/src/lib.rs | 3 +- 22 files changed, 208 insertions(+), 145 deletions(-) create mode 100644 core/src/macros.rs delete mode 100644 core/src/net/mod.rs diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index 3a17c007..aefdbaf8 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -7,11 +7,7 @@ concurrency: on: pull_request: branches: [ main ] - push: - branches: [ main ] - tags: [ nightly*, v*.*.* ] release: - types: [ created ] repository_dispatch: types: [ clippy ] schedule: diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index fcd74841..34fe4e82 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -10,7 +10,6 @@ env: on: push: branches: [ main ] - tags: [ nightly*, v*.*.* ] release: types: [ created ] repository_dispatch: diff --git a/core/src/hkt/applicative.rs b/core/src/hkt/applicative.rs index 81909c69..5ced77ab 100644 --- a/core/src/hkt/applicative.rs +++ b/core/src/hkt/applicative.rs @@ -8,8 +8,11 @@ use super::functor::Functor; use super::HKT; -use std::rc::Rc; -use std::sync::Arc; +#[cfg(not(feature = "std"))] +use alloc::{boxed::Box, rc::Rc, sync::Arc, vec::Vec}; + +#[cfg(feature = "std")] +use std::{rc::Rc, sync::Arc}; pub trait Applicative: Functor { fn pure_(value: U) -> Self::T @@ -21,40 +24,39 @@ pub trait Applicative: Functor { Self: HKT; } -impl Applicative for Arc { - fn pure_(value: U) -> Self::T { - Arc::new(value) - } +macro_rules! applicative { + ($($t:ident($e:expr)),* $(,)?) => { + $( + applicative!(@impl $t($e)); + )* + }; + (@impl $t:ident($e:expr)) => { + impl Applicative for $t { + fn pure_(value: U) -> Self::T { + $e(value) + } - fn seq(&self, fs: >::T) -> Arc - where - F: Fn(&T) -> U, - { - let v = fs(self); - Arc::new(v) - } + fn seq(&self, fs: >::T) -> $t + where + F: Fn(&>::C) -> U, + { + let v = fs(self); + $e(v) + } + } + }; } -impl Applicative for Box { - fn pure_(value: U) -> Self::T { - Box::new(value) - } +applicative!(Arc(Arc::new), Box(Box::new), Rc(Rc::new)); + - fn seq(&self, fs: >::T) -> Box - where - F: Fn(&T) -> U, - { - let v = fs(self); - Box::new(v) - } -} -impl Applicative for Option { +impl Applicative for core::option::Option { fn pure_(value: U) -> Self::T { Some(value) } - fn seq(&self, fs: >::T) -> Option + fn seq(&self, fs: >::T) -> core::option::Option where F: Fn(&T) -> U, { @@ -68,20 +70,6 @@ impl Applicative for Option { } } -impl Applicative for Rc { - fn pure_(value: U) -> Self::T { - Rc::new(value) - } - - fn seq(&self, fs: >::T) -> Rc - where - F: Fn(&T) -> U, - { - let v = fs(self); - Rc::new(v) - } -} - impl Applicative for Vec { fn pure_(value: U) -> Self::T { vec![value] diff --git a/core/src/hkt/functor.rs b/core/src/hkt/functor.rs index 0f865492..4348348a 100644 --- a/core/src/hkt/functor.rs +++ b/core/src/hkt/functor.rs @@ -7,8 +7,11 @@ //! A functor is a type that when mapped over, preserves the structure of the type while applying a function to the values within the type. //! Functors are useful for modeling the functional effects on values of parameterized data types. use super::HKT; -use std::rc::Rc; -use std::sync::Arc; +#[cfg(not(feature = "std"))] +use alloc::{boxed::Box, rc::Rc, sync::Arc, vec::Vec}; + +#[cfg(feature = "std")] +use std::{rc::Rc, sync::Arc}; pub trait Functor: HKT { fn fmap(&self, f: F) -> Self::T @@ -16,23 +19,25 @@ pub trait Functor: HKT { F: Fn(&Self::C) -> U; } -impl Functor for Arc { - fn fmap(&self, f: F) -> Arc - where - F: Fn(&T) -> U, - { - Arc::new(f(self)) - } +macro_rules! functor { + ($($t:ident),* $(,)?) => { + $( + functor!(@impl $t); + )* + }; + (@impl $t:ident) => { + impl Functor for $t { + fn fmap(&self, f: F) -> $t + where + F: Fn(&T) -> U, + { + $t::new(f(self)) + } + } + }; } -impl Functor for Box { - fn fmap(&self, f: F) -> Box - where - F: Fn(&T) -> U, - { - Box::new(f(self)) - } -} +functor!(Arc, Box, Rc); impl Functor for Option { fn fmap(&self, f: F) -> Option @@ -46,14 +51,6 @@ impl Functor for Option { } } -impl Functor for Rc { - fn fmap(&self, f: F) -> Rc - where - F: Fn(&T) -> U, - { - Rc::new(f(self)) - } -} impl Functor for Vec { fn fmap(&self, f: F) -> Vec diff --git a/core/src/hkt/mod.rs b/core/src/hkt/mod.rs index 26497072..95247f6e 100644 --- a/core/src/hkt/mod.rs +++ b/core/src/hkt/mod.rs @@ -11,30 +11,37 @@ pub mod applicative; pub mod functor; pub mod monad; -use std::rc::Rc; -use std::sync::Arc; +#[cfg(not(feature = "std"))] +use alloc::{boxed::Box, rc::Rc, sync::Arc, vec::Vec}; + +#[cfg(feature = "std")] +use std::{rc::Rc, sync::Arc}; pub trait HKT { type C; // Current Type type T; // Type C swapped with U } +#[macro_export] macro_rules! hkt { - ($t:ident) => { - impl HKT for $t { + ($($($p:ident)::*),*) => { + $( + hkt!(@impl $($p)::*); + )* + }; + (@impl $($p:ident)::*) => { + impl HKT for $($p)::* { type C = T; - type T = $t; + type T = $($p)::*; } }; } -hkt!(Arc); -hkt!(Box); -hkt!(Option); -hkt!(Rc); -hkt!(Vec); +hkt!(Arc, Box, core::option::Option, Rc, Vec); + pub(crate) mod prelude { + pub use super::HKT; pub use super::applicative::Applicative; pub use super::functor::Functor; pub use super::monad::Monad; diff --git a/core/src/hkt/monad.rs b/core/src/hkt/monad.rs index 74c091dc..f78d05e2 100644 --- a/core/src/hkt/monad.rs +++ b/core/src/hkt/monad.rs @@ -2,11 +2,14 @@ Appellation: monad Contrib: FL03 */ -use super::applicative::Applicative; +use super::Applicative; use super::HKT; -use std::rc::Rc; -use std::sync::Arc; +#[cfg(not(feature = "std"))] +use alloc::{boxed::Box, rc::Rc, sync::Arc, vec::Vec}; + +#[cfg(feature = "std")] +use std::{rc::Rc, sync::Arc}; pub trait Monad: Applicative { fn return_(x: U) -> Self::T diff --git a/core/src/lib.rs b/core/src/lib.rs index c06b37ba..3322af1e 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -11,18 +11,17 @@ extern crate alloc; #[doc(inline)] -pub use self::utils::*; +pub use self::{traits::prelude::*, types::prelude::*, utils::*}; +#[macro_use] +pub(crate) mod macros; #[macro_use] pub(crate) mod seal; - pub(crate) mod utils; pub mod errors; pub mod hkt; pub mod id; -#[doc(hidden)] -pub mod net; pub mod sync; pub mod time; pub mod traits; @@ -32,14 +31,14 @@ pub mod types; pub const DEFAULT_IGNORE_CHARS: &[char] = &['[', ']', ',', '.', ' ']; pub mod prelude { - pub use crate::utils::*; pub use crate::DEFAULT_IGNORE_CHARS; pub use crate::errors::*; pub use crate::hkt::prelude::*; pub use crate::id::prelude::*; - pub use crate::net::prelude::*; + pub use crate::sync::prelude::*; pub use crate::time::*; pub use crate::traits::prelude::*; - pub use crate::types::*; + pub use crate::types::prelude::*; + pub use crate::utils::*; } diff --git a/core/src/macros.rs b/core/src/macros.rs new file mode 100644 index 00000000..9d5d44c7 --- /dev/null +++ b/core/src/macros.rs @@ -0,0 +1,18 @@ +/* + Appellation: macros + Contrib: FL03 +*/ + +#[allow(unused_macros)] +macro_rules! impl_fmt { + ($name:ty: $($t:ident($($rest:tt)*)),*) => { + $(impl_fmt!($name: $t($($rest)*));)* + }; + (@impl $name:ty: $t:ident($($rest:tt)*)) => { + impl core::fmt::$t for $name { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, $($rest)*) + } + } + }; +} \ No newline at end of file diff --git a/core/src/net/mod.rs b/core/src/net/mod.rs deleted file mode 100644 index 2f481e59..00000000 --- a/core/src/net/mod.rs +++ /dev/null @@ -1,17 +0,0 @@ -/* - Appellation: net - Contrib: FL03 -*/ -pub use self::utils::*; - -pub(crate) mod utils { - use core::net::{self, SocketAddr}; - /// This function attempts to convert the given input into a [core::net::SocketAddr] - pub fn try_str_to_socketaddr(addr: impl ToString) -> Result { - addr.to_string().parse() - } -} - -pub(crate) mod prelude { - pub use super::utils::*; -} diff --git a/core/src/sync/atomic/mod.rs b/core/src/sync/atomic/mod.rs index fb0117aa..0a475a27 100644 --- a/core/src/sync/atomic/mod.rs +++ b/core/src/sync/atomic/mod.rs @@ -6,5 +6,9 @@ pub use self::order::AtomicOrder; pub(crate) mod order; +pub(crate) mod prelude { + pub use super::order::AtomicOrder; +} + #[cfg(test)] mod tests {} diff --git a/core/src/sync/mod.rs b/core/src/sync/mod.rs index ad281a82..6a7205bd 100644 --- a/core/src/sync/mod.rs +++ b/core/src/sync/mod.rs @@ -8,5 +8,9 @@ pub mod atomic; +pub(crate) mod prelude { + pub use super::atomic::prelude::*; +} + #[cfg(test)] mod tests {} diff --git a/core/src/time/epoch.rs b/core/src/time/epoch.rs index 12e0e684..80c1e447 100644 --- a/core/src/time/epoch.rs +++ b/core/src/time/epoch.rs @@ -4,7 +4,7 @@ */ #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] -#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize,))] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct Epoch { size: u128, timestamp: i64, diff --git a/core/src/time/mod.rs b/core/src/time/mod.rs index 8cfd12f5..80760a10 100644 --- a/core/src/time/mod.rs +++ b/core/src/time/mod.rs @@ -9,6 +9,8 @@ pub(crate) mod datetime; pub(crate) mod epoch; pub(crate) mod timestamp; + + /// Interface for time-related data-structures pub trait Temporal { type Timestamp; @@ -19,6 +21,8 @@ pub trait Temporal { pub(crate) mod utils { /// [systime] is a utilitarian function that returns the current system time in milliseconds. + #[cfg(feature = "std")] + #[inline] pub fn systime() -> u128 { std::time::SystemTime::now() .duration_since(std::time::UNIX_EPOCH) diff --git a/core/src/time/timestamp.rs b/core/src/time/timestamp.rs index 31ea349f..db152191 100644 --- a/core/src/time/timestamp.rs +++ b/core/src/time/timestamp.rs @@ -2,23 +2,26 @@ Appellation: timestamp Contrib: FL03 */ -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; -use std::ops::Deref; +use core::borrow::Borrow; +use core::ops::Deref; /// Timestamp implements a host of useful utilities for stamping data #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] -#[cfg_attr(feature = "serde", derive(Deserialize, Serialize,))] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] #[repr(transparent)] pub struct Timestamp(u128); impl Timestamp { + pub fn new(timestamp: u128) -> Self { + Self(timestamp) + } + /// Create a new timestamp pub fn now() -> Self { Self(crate::time::systime()) } - pub const fn timestamp(&self) -> u128 { + pub const fn get(&self) -> u128 { self.0 } } @@ -29,6 +32,12 @@ impl AsRef for Timestamp { } } +impl Borrow for Timestamp { + fn borrow(&self) -> &u128 { + &self.0 + } +} + impl Default for Timestamp { fn default() -> Self { Self::now() @@ -43,11 +52,6 @@ impl Deref for Timestamp { } } -impl std::fmt::Display for Timestamp { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - write!(f, "{}", self.0) - } -} impl From for Timestamp { fn from(timestamp: u128) -> Self { @@ -61,6 +65,28 @@ impl From for u128 { } } +macro_rules! fmt_timestamp { + ($($t:ident($($rest:tt)*)),*) => { + $( + impl core::fmt::$t for Timestamp { + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + write!(f, $($rest)*, self.0) + } + } + )* + }; +} + +fmt_timestamp! { + Binary("{:b}"), + Display("{}"), + LowerExp("{:e}"), + LowerHex("{:x}"), + Octal("{:o}"), + UpperExp("{:E}"), + UpperHex("{:X}") +} + #[cfg(test)] mod tests { use super::*; diff --git a/core/src/traits/mod.rs b/core/src/traits/mod.rs index 87d9feab..3f274404 100644 --- a/core/src/traits/mod.rs +++ b/core/src/traits/mod.rs @@ -2,16 +2,22 @@ Appellation: specs Contrib: FL03 */ -pub use self::{appellation::*, classify::*, ext::*}; +pub use self::{appellation::*, classify::*, ext::prelude::*}; pub mod appellation; pub mod classify; pub mod ext { - pub use self::{slice::*, string::StringExt}; + pub use self::prelude::*; pub mod slice; pub mod string; + + pub(crate) mod prelude { + pub use super::slice::*; + pub use super::string::*; + + } } /// Interface for data-structures that can be compared for equality @@ -49,6 +55,6 @@ pub trait Name { pub(crate) mod prelude { pub use super::appellation::*; pub use super::classify::*; - pub use super::ext::*; + pub use super::ext::prelude::*; pub use super::{Contain, Name}; } diff --git a/core/src/types/mod.rs b/core/src/types/mod.rs index 12941c57..3f6807b9 100644 --- a/core/src/types/mod.rs +++ b/core/src/types/mod.rs @@ -56,6 +56,13 @@ pub(crate) mod utils { } } +pub(crate) mod prelude { + pub use super::{AnyAsync, Result}; + pub use super::utils::*; + #[cfg(feature = "std")] + pub use super::std_types::*; +} + #[cfg(test)] mod tests { use super::*; diff --git a/derive/src/lib.rs b/derive/src/lib.rs index f0d862be..e13b9403 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -1,12 +1,7 @@ /* Appellation: scsys-derive Contrib: FL03 - */ -//! # scsys-derive -//! -//! Useful derive macros for the scsys ecosystem - extern crate proc_macro; extern crate quote; extern crate syn; @@ -22,7 +17,7 @@ use proc_macro::TokenStream; use syn::{parse_macro_input, Data, DeriveInput}; #[proc_macro_derive(Display, attributes(display))] -pub fn any_display(input: TokenStream) -> TokenStream { +pub fn display(input: TokenStream) -> TokenStream { // Parse the inputs into the proper struct let ast = parse_macro_input!(input as DeriveInput); @@ -32,8 +27,21 @@ pub fn any_display(input: TokenStream) -> TokenStream { gen.into() } -#[proc_macro_derive(VariantConstructors)] -pub fn derive_functional_constructors(input: TokenStream) -> TokenStream { +/// This macro generates a parameter struct and an enum of parameter keys. +#[proc_macro_derive(Params, attributes(param))] +pub fn params(input: TokenStream) -> TokenStream { + // Parse the input tokens into a syntax tree + let input = parse_macro_input!(input as DeriveInput); + + let gen = params::impl_params(&input); + + // Return the generated code as a TokenStream + gen.into() +} + +/// This macro automatically generates functional constructors for all enclosed variants. +#[proc_macro_derive(VariantConstructors, attributes(variant))] +pub fn variant_constructors(input: TokenStream) -> TokenStream { let ast: DeriveInput = syn::parse(input).unwrap(); match ast.data { @@ -43,14 +51,18 @@ pub fn derive_functional_constructors(input: TokenStream) -> TokenStream { .into() } -/// This macro generates a parameter struct and an enum of parameter keys. -#[proc_macro_derive(Keyed, attributes(key))] +/* + ******** DEPRECATED ******** +*/ + +#[proc_macro_derive(Keyed, attributes(param))] +#[deprecated(since = "0.2.2", note = "Use `Params` instead")] pub fn keyed(input: TokenStream) -> TokenStream { // Parse the input tokens into a syntax tree let input = parse_macro_input!(input as DeriveInput); - let gen = params::impl_keyed(&input); + let gen = params::impl_params(&input); // Return the generated code as a TokenStream gen.into() -} +} \ No newline at end of file diff --git a/derive/src/params.rs b/derive/src/params.rs index df4d88cb..10f63fcf 100644 --- a/derive/src/params.rs +++ b/derive/src/params.rs @@ -9,7 +9,7 @@ use proc_macro2::TokenStream; use quote::{format_ident, quote}; use syn::{Data, DataStruct, DeriveInput}; -pub fn impl_keyed(input: &DeriveInput) -> TokenStream { +pub fn impl_params(input: &DeriveInput) -> TokenStream { // Get the name of the struct let struct_name = &input.ident; let store_name = format_ident!("{}Key", struct_name); diff --git a/macros/src/lib.rs b/macros/src/lib.rs index ff6fa93d..4378eee7 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -5,3 +5,13 @@ //! # scsys-macros //! //! +extern crate proc_macro; + +use proc_macro::TokenStream; + +#[doc(hidden)] +#[proc_macro] +pub fn display(input: TokenStream) -> TokenStream { + println!("display: {:?}", input); + input +} \ No newline at end of file diff --git a/scsys/examples/derive.rs b/scsys/examples/derive.rs index 9660ff01..a0ee9be9 100644 --- a/scsys/examples/derive.rs +++ b/scsys/examples/derive.rs @@ -4,9 +4,10 @@ */ extern crate scsys; -use scsys::{Keyed, VariantConstructors}; +use scsys::{Params, VariantConstructors}; +use scsys::prelude::Result; -fn main() -> Result<(), Box> { +fn main() -> Result<()> { let params = LinearParams { weight: 1.0 }; println!("{:?}", ¶ms); let wk = LinearParamsKey::Weight; @@ -17,9 +18,9 @@ fn main() -> Result<(), Box> { Ok(()) } -#[derive(Clone, Copy, Debug, Default, Eq, Hash, Keyed, Ord, PartialEq, PartialOrd)] +#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, Params, PartialEq, PartialOrd)] pub struct LinearParams { - #[key] + #[param] pub weight: T, } diff --git a/scsys/examples/params.rs b/scsys/examples/params.rs index eed91989..65013536 100644 --- a/scsys/examples/params.rs +++ b/scsys/examples/params.rs @@ -4,9 +4,9 @@ */ extern crate scsys; -use scsys::Keyed; +use scsys::Params; -fn main() -> Result<(), Box> { +fn main() -> scsys::prelude::Result<()> { let _params = LinearParams { weight: 1.0 }; let wk = LinearParamsKey::Weight; println!("{:?}", &wk); @@ -15,8 +15,8 @@ fn main() -> Result<(), Box> { Ok(()) } -#[derive(Keyed)] +#[derive(Params)] pub struct LinearParams { - #[key] + #[param] pub weight: T, } diff --git a/scsys/src/lib.rs b/scsys/src/lib.rs index 6f43f984..8f147e37 100644 --- a/scsys/src/lib.rs +++ b/scsys/src/lib.rs @@ -21,9 +21,8 @@ pub use scsys_macros::*; #[doc(inline)] pub use scsys_stores as stores; +// #66 - Cleanup the prelude module(s) pub mod prelude { - - #[cfg(feature = "actors")] #[doc(inline)] pub use scsys_actors::prelude::*; From f747158c229b3b129c66596ca5a65e092b2f397e Mon Sep 17 00:00:00 2001 From: Joe McCain III Date: Tue, 30 Apr 2024 09:55:27 -0500 Subject: [PATCH 03/10] update Signed-off-by: Joe McCain III --- core/src/id/traits.rs | 11 +++++++---- core/src/traits/appellation.rs | 18 ++++-------------- core/src/traits/mod.rs | 7 +++---- stores/Cargo.toml | 15 +++++++++------ 4 files changed, 23 insertions(+), 28 deletions(-) diff --git a/core/src/id/traits.rs b/core/src/id/traits.rs index 61d71010..04f93eef 100644 --- a/core/src/id/traits.rs +++ b/core/src/id/traits.rs @@ -15,9 +15,10 @@ pub trait Identifier: ToString { pub trait Id where K: Identifier, - Self: Borrow, { - fn get(&self) -> &K; + type Item: Borrow; + + fn get(&self) -> &Self::Item; } pub trait Identifiable @@ -65,8 +66,10 @@ where S: Borrow, K: Identifier, { - fn get(&self) -> &K { - self.borrow() + type Item = S; + + fn get(&self) -> &Self::Item { + &self } } diff --git a/core/src/traits/appellation.rs b/core/src/traits/appellation.rs index 33b7240b..7d306417 100644 --- a/core/src/traits/appellation.rs +++ b/core/src/traits/appellation.rs @@ -4,13 +4,10 @@ */ use crate::prelude::{Classifier, Identifier}; -/// An appellation is defined to be a name or title given to a person or thing; often being used in the context of wine. -/// Here, the `Appellation` is a unique object identifier that is composed of three independent parts: -/// - Classifier -/// - Identifier -/// - Name -/// -/// While the name is typically referenced by external users, the classifier and id are used to navigate through computational space. +/// An appellation is considered to be a name or title that is used to identify an object. +/// For our purposes, an `Appellation` is a type that is used to identify an object in a computational space. +/// The appellation outlines a notation that combines an idenfifier, classifier, and name into a single unique +/// identifier for an object. pub trait Appellation { type Class: Classifier; type Id: Identifier; @@ -24,13 +21,6 @@ pub trait Appellation { fn slug(&self) -> String { self.name().to_lowercase().replace(" ", "-") } - - fn type_id(&self) -> core::any::TypeId - where - Self: Sized + 'static, - { - core::any::TypeId::of::() - } } pub trait FromAppellation diff --git a/core/src/traits/mod.rs b/core/src/traits/mod.rs index 3f274404..3d7779a7 100644 --- a/core/src/traits/mod.rs +++ b/core/src/traits/mod.rs @@ -10,13 +10,12 @@ pub mod classify; pub mod ext { pub use self::prelude::*; - pub mod slice; - pub mod string; + pub(crate) mod slice; + pub(crate) mod string; pub(crate) mod prelude { pub use super::slice::*; pub use super::string::*; - } } @@ -53,8 +52,8 @@ pub trait Name { } pub(crate) mod prelude { + pub use super::{Contain, Name}; pub use super::appellation::*; pub use super::classify::*; pub use super::ext::prelude::*; - pub use super::{Contain, Name}; } diff --git a/stores/Cargo.toml b/stores/Cargo.toml index 865c565d..b86aadc9 100644 --- a/stores/Cargo.toml +++ b/stores/Cargo.toml @@ -27,14 +27,13 @@ serde = [ ] serde-ext = [ - "dep:serde_json" + "dep:serde_json", + "scsys-core/serde" ] -std = [] - -wasi = [] - -wasm = [] +std = [ + "scsys-core/std" +] [lib] bench = false @@ -49,6 +48,10 @@ serde_json = { optional = true, version = "1" } smart-default.workspace = true strum.workspace = true +[dependencies.scsys-core] +path = "../core" +version = "0.2.2" + [dev-dependencies] [package.metadata.docs.rs] From 79fab16a3916c0de0d12d4bbca00d4b5d1cf0cc7 Mon Sep 17 00:00:00 2001 From: Joe McCain III Date: Tue, 30 Apr 2024 10:26:11 -0500 Subject: [PATCH 04/10] update Signed-off-by: Joe McCain III --- actors/src/actor.rs | 6 ++ actors/src/lib.rs | 8 +-- actors/src/messages/message.rs | 52 ++++++++++---- actors/src/power/mod.rs | 2 +- actors/src/states/state.rs | 9 ++- core/src/hkt/applicative.rs | 2 - core/src/hkt/functor.rs | 3 +- core/src/hkt/mod.rs | 3 +- core/src/id/traits.rs | 2 +- core/src/macros.rs | 2 +- core/src/time/mod.rs | 2 - core/src/time/timestamp.rs | 1 - core/src/traits/mod.rs | 2 +- {actors/src => core/src/types}/direction.rs | 0 core/src/types/mod.rs | 14 ++-- derive/src/lib.rs | 4 +- derive/tests/display.rs | 14 +--- macros/src/lib.rs | 2 +- scsys/examples/derive.rs | 2 +- scsys/src/lib.rs | 6 +- stores/src/actions/crud/mode.rs | 80 ++++++++++++++------- 21 files changed, 130 insertions(+), 86 deletions(-) create mode 100644 actors/src/actor.rs rename {actors/src => core/src/types}/direction.rs (100%) diff --git a/actors/src/actor.rs b/actors/src/actor.rs new file mode 100644 index 00000000..9044a997 --- /dev/null +++ b/actors/src/actor.rs @@ -0,0 +1,6 @@ +/* + Appellation: actor + Creator: FL03 +*/ + +pub trait Actor {} diff --git a/actors/src/lib.rs b/actors/src/lib.rs index e80558fb..c8c6c846 100644 --- a/actors/src/lib.rs +++ b/actors/src/lib.rs @@ -4,15 +4,15 @@ */ //! # Actors //! -//! +//! This library seeks to provide a suite of tools for creating and managing actors in Rust. #[cfg(not(feature = "std"))] extern crate alloc; extern crate scsys_core as scsys; -pub use self::{direction::*, traits::*}; +pub use self::{actor::*, traits::*}; -pub(crate) mod direction; +pub(crate) mod actor; #[macro_use] pub(crate) mod macros; @@ -24,7 +24,7 @@ pub mod traits; pub type Job = Box; pub mod prelude { - pub use crate::direction::*; + pub use crate::actor::*; pub use crate::messages::*; pub use crate::power::*; pub use crate::states::prelude::*; diff --git a/actors/src/messages/message.rs b/actors/src/messages/message.rs index 27401994..0aa7dd18 100644 --- a/actors/src/messages/message.rs +++ b/actors/src/messages/message.rs @@ -3,11 +3,9 @@ Contrib: FL03 */ use scsys::prelude::{AtomicId, Timestamp}; -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; -#[cfg_attr(feature = "serde", derive(Deserialize, Serialize,))] #[derive(Clone, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)] +#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] pub struct Message { id: AtomicId, data: Option, @@ -15,48 +13,74 @@ pub struct Message { } impl Message { - pub fn new(data: Option) -> Self { + pub fn new() -> Self { Self { id: AtomicId::new(), - data, + data: None, ts: Timestamp::now(), } } - pub fn content(&self) -> Option<&T> { + pub fn clear(&mut self) { + self.on_update(); + self.data = None; + } + + pub fn data(&self) -> Option<&T> { self.data.as_ref() } + pub fn data_mut(&mut self) -> Option<&mut T> { + self.data.as_mut() + } + pub fn id(&self) -> usize { *self.id } + pub fn set_data(&mut self, data: Option) { + self.on_update(); + self.data = data; + } + pub fn timestamp(&self) -> Timestamp { self.ts } + + pub fn with_data(mut self, data: T) -> Self { + self.on_update(); + self.data = Some(data); + self + } + + fn on_update(&mut self) { + self.ts = Timestamp::now(); + } } -impl std::fmt::Display for Message +impl core::fmt::Display for Message where - T: std::fmt::Display, + T: core::fmt::Display, { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - if let Some(data) = self.content() { - return write!(f, "Timestamp: {}\n{}", self.ts, data,); + fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { + if let Some(data) = self.data() { + return write!(f, "{}", data); } - write!(f, "Timestamp: {}", self.ts) + write!(f, "{}", self.timestamp()) } } impl From> for Message { fn from(data: Option) -> Self { - Self::new(data) + let mut msg = Message::new(); + msg.set_data(data); + msg } } impl From for Message { fn from(data: T) -> Self { - Self::new(Some(data)) + Self::new().with_data(data) } } diff --git a/actors/src/power/mod.rs b/actors/src/power/mod.rs index 3084c817..7da7b2cb 100644 --- a/actors/src/power/mod.rs +++ b/actors/src/power/mod.rs @@ -15,7 +15,7 @@ pub mod shutdown; #[cfg(test)] mod tests { use super::*; - use std::str::FromStr; + use core::str::FromStr; #[test] fn test_power() { diff --git a/actors/src/states/state.rs b/actors/src/states/state.rs index f2645999..05d50476 100644 --- a/actors/src/states/state.rs +++ b/actors/src/states/state.rs @@ -2,6 +2,7 @@ Appellation: state Contrib: FL03 */ +use core::borrow::{Borrow, BorrowMut}; use scsys::id::AtomicId; #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] @@ -43,8 +44,14 @@ impl StateBase { } } -impl core::borrow::Borrow for StateBase { +impl Borrow for StateBase { fn borrow(&self) -> &Q { &self.state } } + +impl BorrowMut for StateBase { + fn borrow_mut(&mut self) -> &mut Q { + &mut self.state + } +} diff --git a/core/src/hkt/applicative.rs b/core/src/hkt/applicative.rs index 5ced77ab..5a3fa5e8 100644 --- a/core/src/hkt/applicative.rs +++ b/core/src/hkt/applicative.rs @@ -49,8 +49,6 @@ macro_rules! applicative { applicative!(Arc(Arc::new), Box(Box::new), Rc(Rc::new)); - - impl Applicative for core::option::Option { fn pure_(value: U) -> Self::T { Some(value) diff --git a/core/src/hkt/functor.rs b/core/src/hkt/functor.rs index 4348348a..7011f9aa 100644 --- a/core/src/hkt/functor.rs +++ b/core/src/hkt/functor.rs @@ -33,7 +33,7 @@ macro_rules! functor { { $t::new(f(self)) } - } + } }; } @@ -51,7 +51,6 @@ impl Functor for Option { } } - impl Functor for Vec { fn fmap(&self, f: F) -> Vec where diff --git a/core/src/hkt/mod.rs b/core/src/hkt/mod.rs index 95247f6e..43fa24bf 100644 --- a/core/src/hkt/mod.rs +++ b/core/src/hkt/mod.rs @@ -39,12 +39,11 @@ macro_rules! hkt { hkt!(Arc, Box, core::option::Option, Rc, Vec); - pub(crate) mod prelude { - pub use super::HKT; pub use super::applicative::Applicative; pub use super::functor::Functor; pub use super::monad::Monad; + pub use super::HKT; } #[cfg(test)] diff --git a/core/src/id/traits.rs b/core/src/id/traits.rs index 04f93eef..d22f1732 100644 --- a/core/src/id/traits.rs +++ b/core/src/id/traits.rs @@ -67,7 +67,7 @@ where K: Identifier, { type Item = S; - + fn get(&self) -> &Self::Item { &self } diff --git a/core/src/macros.rs b/core/src/macros.rs index 9d5d44c7..f1e1266c 100644 --- a/core/src/macros.rs +++ b/core/src/macros.rs @@ -15,4 +15,4 @@ macro_rules! impl_fmt { } } }; -} \ No newline at end of file +} diff --git a/core/src/time/mod.rs b/core/src/time/mod.rs index 80760a10..64a21449 100644 --- a/core/src/time/mod.rs +++ b/core/src/time/mod.rs @@ -9,8 +9,6 @@ pub(crate) mod datetime; pub(crate) mod epoch; pub(crate) mod timestamp; - - /// Interface for time-related data-structures pub trait Temporal { type Timestamp; diff --git a/core/src/time/timestamp.rs b/core/src/time/timestamp.rs index db152191..8dc9826f 100644 --- a/core/src/time/timestamp.rs +++ b/core/src/time/timestamp.rs @@ -52,7 +52,6 @@ impl Deref for Timestamp { } } - impl From for Timestamp { fn from(timestamp: u128) -> Self { Self(timestamp) diff --git a/core/src/traits/mod.rs b/core/src/traits/mod.rs index 3d7779a7..11c00901 100644 --- a/core/src/traits/mod.rs +++ b/core/src/traits/mod.rs @@ -52,8 +52,8 @@ pub trait Name { } pub(crate) mod prelude { - pub use super::{Contain, Name}; pub use super::appellation::*; pub use super::classify::*; pub use super::ext::prelude::*; + pub use super::{Contain, Name}; } diff --git a/actors/src/direction.rs b/core/src/types/direction.rs similarity index 100% rename from actors/src/direction.rs rename to core/src/types/direction.rs diff --git a/core/src/types/mod.rs b/core/src/types/mod.rs index 3f6807b9..a4601ad7 100644 --- a/core/src/types/mod.rs +++ b/core/src/types/mod.rs @@ -2,14 +2,12 @@ Appellation: types Contrib: FL03 */ -//! # types -//! -//! - -pub use self::utils::*; #[cfg(feature = "std")] -pub use std_types::*; +pub use self::std_types::*; +pub use self::{direction::Direction, utils::*}; + +pub mod direction; pub type AnyAsync = Box; @@ -57,10 +55,10 @@ pub(crate) mod utils { } pub(crate) mod prelude { - pub use super::{AnyAsync, Result}; - pub use super::utils::*; #[cfg(feature = "std")] pub use super::std_types::*; + pub use super::utils::*; + pub use super::{AnyAsync, Result}; } #[cfg(test)] diff --git a/derive/src/lib.rs b/derive/src/lib.rs index e13b9403..af193daa 100644 --- a/derive/src/lib.rs +++ b/derive/src/lib.rs @@ -52,7 +52,7 @@ pub fn variant_constructors(input: TokenStream) -> TokenStream { } /* - ******** DEPRECATED ******** + ******** DEPRECATED ******** */ #[proc_macro_derive(Keyed, attributes(param))] @@ -65,4 +65,4 @@ pub fn keyed(input: TokenStream) -> TokenStream { // Return the generated code as a TokenStream gen.into() -} \ No newline at end of file +} diff --git a/derive/tests/display.rs b/derive/tests/display.rs index aa4cfc34..85b0f209 100644 --- a/derive/tests/display.rs +++ b/derive/tests/display.rs @@ -8,17 +8,7 @@ use scsys_derive::{Display, VariantConstructors}; use serde::{Deserialize, Serialize}; #[derive( - Clone, - Debug, - Default, - Deserialize, - Display, - Eq, - Hash, - Ord, - PartialEq, - PartialOrd, - Serialize, + Clone, Debug, Default, Deserialize, Display, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, )] #[display] pub struct TestStruct { @@ -51,4 +41,4 @@ fn test_variant_constructors() { assert_eq!(SampleUnit::b(0), SampleUnit::B(0)); assert_eq!(SampleUnit::c(0), SampleUnit::C { inner: 0 }); assert_eq!(SampleUnit::abc_def(0), SampleUnit::AbcDef(0)); -} \ No newline at end of file +} diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 4378eee7..a71ce375 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -14,4 +14,4 @@ use proc_macro::TokenStream; pub fn display(input: TokenStream) -> TokenStream { println!("display: {:?}", input); input -} \ No newline at end of file +} diff --git a/scsys/examples/derive.rs b/scsys/examples/derive.rs index a0ee9be9..90a86288 100644 --- a/scsys/examples/derive.rs +++ b/scsys/examples/derive.rs @@ -4,8 +4,8 @@ */ extern crate scsys; -use scsys::{Params, VariantConstructors}; use scsys::prelude::Result; +use scsys::{Params, VariantConstructors}; fn main() -> Result<()> { let params = LinearParams { weight: 1.0 }; diff --git a/scsys/src/lib.rs b/scsys/src/lib.rs index 8f147e37..e24b9c0e 100644 --- a/scsys/src/lib.rs +++ b/scsys/src/lib.rs @@ -28,11 +28,11 @@ pub mod prelude { pub use scsys_actors::prelude::*; #[doc(inline)] pub use scsys_core::prelude::*; - #[cfg(feature = "stores")] - #[doc(inline)] - pub use scsys_stores::prelude::*; #[cfg(feature = "derive")] pub use scsys_derive::*; #[cfg(feature = "macros")] pub use scsys_macros::*; + #[cfg(feature = "stores")] + #[doc(inline)] + pub use scsys_stores::prelude::*; } diff --git a/stores/src/actions/crud/mode.rs b/stores/src/actions/crud/mode.rs index 535b5d9c..9b28b2ab 100644 --- a/stores/src/actions/crud/mode.rs +++ b/stores/src/actions/crud/mode.rs @@ -2,22 +2,21 @@ Appellation: mode Contrib: FL03 */ -#[cfg(feature = "serde")] -use serde::{Deserialize, Serialize}; -use strum::{Display, EnumCount, EnumIs, EnumIter, EnumString, VariantNames}; +use strum::{ + AsRefStr, Display, EnumCount, EnumDiscriminants, EnumIs, EnumIter, EnumString, VariantNames, +}; /// The mode of a CRUD operation. /// #[derive( + AsRefStr, Clone, Copy, Debug, - Default, Display, EnumCount, + EnumDiscriminants, EnumIs, - EnumIter, - EnumString, Eq, Hash, Ord, @@ -27,32 +26,59 @@ use strum::{Display, EnumCount, EnumIs, EnumIter, EnumString, VariantNames}; )] #[cfg_attr( feature = "serde", - derive(Deserialize, Serialize), + derive(serde::Deserialize, serde::Serialize), serde(rename_all = "lowercase", untagged) )] +#[cfg_attr( + feature = "serde", + strum_discriminants( + derive(serde::Deserialize, serde::Serialize), + serde(rename_all = "lowercase", untagged) + ) +)] #[strum(serialize_all = "lowercase")] -pub enum CRUD { - #[default] - Create, - Read, - Update, - Delete, +#[strum_discriminants( + name(CRUD), + derive( + AsRefStr, + Display, + EnumCount, + EnumIs, + EnumIter, + EnumString, + Hash, + Ord, + PartialOrd, + VariantNames + ), + strum(serialize_all = "lowercase") +)] +pub enum CRUDEvent { + Create(T), + Read(T), + Update(T), + Delete(T), } -impl CRUD { - pub fn create() -> Self { - Self::Create - } - - pub fn read() -> Self { - Self::Read - } +macro_rules! crud_constructors { + ($($variant:ident.$call:ident),* $(,)?) => { + impl CRUDEvent { + $( + pub fn $call(data: T) -> Self { + Self::$variant(data) + } + )* + } - pub fn update() -> Self { - Self::Update - } + impl CRUD { + $( + pub fn $call() -> Self { + Self::$variant + } + )* + } + }; - pub fn delete() -> Self { - Self::Delete - } } + +crud_constructors!(Create.create, Read.read, Update.update, Delete.delete,); From 2cf0e1795880abfaeef3fb006ca59d8090557067 Mon Sep 17 00:00:00 2001 From: Joe McCain III Date: Thu, 2 May 2024 10:19:31 -0500 Subject: [PATCH 05/10] update Signed-off-by: Joe McCain III --- Cargo.toml | 16 +++++++--------- actors/Cargo.toml | 15 +-------------- core/Cargo.toml | 12 +----------- scsys/Cargo.toml | 16 ++++++---------- stores/Cargo.toml | 7 +------ 5 files changed, 16 insertions(+), 50 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 61071fec..acae219f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [workspace.package] authors = ["FL03 (https://github.com/FL03)", "Scattered-Systems (https://github.com/scattered-systems)"] categories = [] -description = "scsys lays the foundation for the Scattered-Systems ecosystem, delivering critical primitives throughout" +description = "scsys is a collection of primitives and utilities for use throughout the ecosystem." edition = "2021" homepage = "https://github.com/scattered-systems/scsys/wiki" keywords = ["blockchain", "primitives", "scsys"] @@ -10,19 +10,12 @@ readme = "README.md" repository = "https://github.com/scattered-systems/scsys" version = "0.2.2" -[workspace.dependencies] -paste = "1" -smart-default = "0.7" -strum = { features = ["derive"], version = "0.26" } - [workspace] default-members = [ "scsys", ] -exclude = [ - "examples/*", -] +exclude = [] members = [ "actors", @@ -35,6 +28,11 @@ members = [ resolver = "2" +[workspace.dependencies] +paste = "1" +smart-default = "0.7" +strum = { features = ["derive"], version = "0.26" } + [profile.dev] codegen-units = 256 debug = true diff --git a/actors/Cargo.toml b/actors/Cargo.toml index deae9e78..95a67a9a 100644 --- a/actors/Cargo.toml +++ b/actors/Cargo.toml @@ -24,14 +24,9 @@ full = [ serde = [ "dep:serde", - "serde-ext", "scsys-core/serde", ] -serde-ext = [ - "dep:serde_json", -] - std = [ "scsys-core/std", ] @@ -45,14 +40,6 @@ tokio-ext = [ "tokio/sync", ] -wasi = [ - "scsys-core/wasi" -] - -wasm = [ - "scsys-core/wasm" -] - [lib] bench = false crate-type = ["cdylib", "rlib"] @@ -65,7 +52,7 @@ futures = "0.3" glob = "0.3" paste.workspace = true serde = { optional = true, features = ["derive"], version = "1" } -serde_json = { optional = true, version = "1" } +# serde_json = { optional = true, version = "1" } smart-default.workspace = true strum.workspace = true tokio = { optional = true, version = "1" } diff --git a/core/Cargo.toml b/core/Cargo.toml index a7c2570a..89e20b46 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -29,19 +29,10 @@ rand = [ serde = [ "dep:serde", - "serde-ext", -] - -serde-ext = [ - "dep:serde_json", ] std = [] -wasi = [] - -wasm = [] - [lib] bench = false crate-type = ["cdylib", "rlib"] @@ -54,9 +45,8 @@ test = true glob = "0.3" rand = { optional = true, version = "0.8" } serde = { optional = true, features = ["derive"], version = "1" } -serde_json = { optional = true, version = "1" } smart-default.workspace = true -strum = { features = ["derive"], version = "0.26" } +strum.workspace = true [dev-dependencies] anyhow = "1" diff --git a/scsys/Cargo.toml b/scsys/Cargo.toml index 4bef4e07..231653a5 100644 --- a/scsys/Cargo.toml +++ b/scsys/Cargo.toml @@ -63,19 +63,10 @@ tokio = [ "scsys-actors/tokio", ] -wasi = [ - "scsys-actors/wasi", - "scsys-core/wasi" -] - -wasm = [ - "scsys-actors/wasm", - "scsys-core/wasm", -] - [lib] bench = true crate-type = ["cdylib", "rlib"] +doctest = true test = true [[example]] @@ -107,6 +98,11 @@ serde_json = "1" [package.metadata.docs.rs] all-features = true rustc-args = ["--cfg", "docsrs"] +version = "v{{version}}" + +[package.metadata.release] +no-dev-version = true +tag-name = "{{version}}" [target.wasm32-unknown-unknown] diff --git a/stores/Cargo.toml b/stores/Cargo.toml index b86aadc9..12427700 100644 --- a/stores/Cargo.toml +++ b/stores/Cargo.toml @@ -23,11 +23,6 @@ full = [ serde = [ "dep:serde", - "serde-ext" -] - -serde-ext = [ - "dep:serde_json", "scsys-core/serde" ] @@ -38,13 +33,13 @@ std = [ [lib] bench = false crate-type = ["cdylib", "rlib"] +doctest = false test = true [build-dependencies] [dependencies] serde = { optional = true, features = ["derive"], version = "1" } -serde_json = { optional = true, version = "1" } smart-default.workspace = true strum.workspace = true From f8e1811ac580f9708094393485945abc4e38cb1c Mon Sep 17 00:00:00 2001 From: Joe McCain III Date: Mon, 6 May 2024 09:58:31 -0500 Subject: [PATCH 06/10] update Signed-off-by: Joe McCain III --- .github/dependabot.yml | 4 -- .github/workflows/clippy.yml | 3 +- .github/workflows/crates.yml | 21 +++---- .github/workflows/rust.yml | 4 +- Cargo.toml | 5 +- actors/Cargo.toml | 8 ++- actors/src/actor.rs | 8 ++- actors/src/actor/engine.rs | 6 ++ actors/src/lib.rs | 4 +- actors/src/power/mod.rs | 2 +- actors/src/power/shutdown.rs | 2 + actors/tests/default.rs | 3 +- core/Cargo.toml | 8 ++- core/src/lib.rs | 8 +-- core/src/stores/mod.rs | 11 ++++ core/src/stores/store.rs | 93 +++++++++++++++++++++++++++++++ core/src/types/mod.rs | 5 +- core/src/utils.rs | 87 ++++++++++++----------------- core/tests/default.rs | 5 +- core/tests/errors.rs | 24 ++++++++ core/tests/time.rs | 5 -- scsys/Cargo.toml | 14 +---- scsys/src/lib.rs | 6 -- scsys/tests/default.rs | 5 +- stores/Cargo.toml | 58 ------------------- stores/src/actions/crud/mod.rs | 10 ---- stores/src/actions/crud/mode.rs | 84 ---------------------------- stores/src/actions/mod.rs | 13 ----- stores/src/caches/mod.rs | 12 ---- stores/src/kv/mod.rs | 66 ---------------------- stores/src/lib.rs | 21 ------- stores/src/queues/mod.rs | 13 ----- stores/src/queues/queue.rs | 6 -- stores/src/registries/mod.rs | 15 ----- stores/src/registries/registry.rs | 6 -- stores/src/repos/mod.rs | 12 ---- stores/src/store.rs | 6 -- stores/tests/default.rs | 18 ------ 38 files changed, 221 insertions(+), 460 deletions(-) create mode 100644 actors/src/actor/engine.rs create mode 100644 core/src/stores/mod.rs create mode 100644 core/src/stores/store.rs create mode 100644 core/tests/errors.rs delete mode 100644 core/tests/time.rs delete mode 100644 stores/Cargo.toml delete mode 100644 stores/src/actions/crud/mod.rs delete mode 100644 stores/src/actions/crud/mode.rs delete mode 100644 stores/src/actions/mod.rs delete mode 100644 stores/src/caches/mod.rs delete mode 100644 stores/src/kv/mod.rs delete mode 100644 stores/src/lib.rs delete mode 100644 stores/src/queues/mod.rs delete mode 100644 stores/src/queues/queue.rs delete mode 100644 stores/src/registries/mod.rs delete mode 100644 stores/src/registries/registry.rs delete mode 100644 stores/src/repos/mod.rs delete mode 100644 stores/src/store.rs delete mode 100644 stores/tests/default.rs diff --git a/.github/dependabot.yml b/.github/dependabot.yml index f8752176..b682a5f4 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -28,7 +28,3 @@ updates: directory: /scsys schedule: interval: daily - - package-ecosystem: cargo - directory: /stores - schedule: - interval: daily diff --git a/.github/workflows/clippy.yml b/.github/workflows/clippy.yml index aefdbaf8..f6e706d2 100644 --- a/.github/workflows/clippy.yml +++ b/.github/workflows/clippy.yml @@ -8,10 +8,9 @@ on: pull_request: branches: [ main ] release: + types: [ created ] repository_dispatch: types: [ clippy ] - schedule: - - cron: 30 21 * * 0 # Every Sunday at 9:30PM UTC workflow_dispatch: permissions: diff --git a/.github/workflows/crates.yml b/.github/workflows/crates.yml index f9090de2..babb5dc8 100644 --- a/.github/workflows/crates.yml +++ b/.github/workflows/crates.yml @@ -9,31 +9,26 @@ env: on: release: - types: [created] + types: [ created ] repository_dispatch: - types: [publish] + types: [ crates-io ] workflow_dispatch: jobs: core: name: Publish (core) runs-on: ubuntu-latest - strategy: - matrix: - package: [ core ] - env: - PACKAGE_NAME: ${{ github.event.repository.name }}-${{ matrix.package }} steps: - uses: actions/checkout@v4 - - name: Publish (${{ env.PACKAGE_NAME }}) - run: cargo publish --all-features -v -p ${{ env.PACKAGE_NAME }} --token ${{ secrets.CARGO_REGISTRY_TOKEN }} + - name: publish + run: cargo publish --all-features -v -p ${{ github.event.repository.name }}-core --token ${{ secrets.CARGO_REGISTRY_TOKEN }} features: name: Publish (features) needs: core runs-on: ubuntu-latest strategy: matrix: - package: [ actors, derive, macros, stores ] + package: [ actors, derive, macros, ] env: PACKAGE_NAME: ${{ github.event.repository.name }}-${{ matrix.package }} steps: @@ -41,12 +36,10 @@ jobs: - name: Publish (${{ env.PACKAGE_NAME }}) run: cargo publish --all-features -v -p ${{ env.PACKAGE_NAME }} --token ${{ secrets.CARGO_REGISTRY_TOKEN }} sdk: - env: - PACKAGE_NAME: ${{ github.event.repository.name }} name: Publish (sdk) needs: features runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: Publish (${{ env.PACKAGE_NAME }}) - run: cargo publish --all-features -v -p ${{ env.PACKAGE_NAME }} --token ${{ secrets.CARGO_REGISTRY_TOKEN }} + - name: publish + run: cargo publish --all-features -v -p ${{ github.event.repository.name }} --token ${{ secrets.CARGO_REGISTRY_TOKEN }} diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 34fe4e82..a754a5fe 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -8,14 +8,12 @@ env: CARGO_TERM_COLOR: always on: - push: + pull_request: branches: [ main ] release: types: [ created ] repository_dispatch: types: [ rust ] - schedule: - - cron: 30 21 * * 0 # Every Sunday at 9:30pm UTC workflow_dispatch: jobs: diff --git a/Cargo.toml b/Cargo.toml index acae219f..f0aa3afc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,8 +22,7 @@ members = [ "core", "derive", "macros", - "scsys", - "stores", + "scsys", ] resolver = "2" @@ -31,7 +30,7 @@ resolver = "2" [workspace.dependencies] paste = "1" smart-default = "0.7" -strum = { features = ["derive"], version = "0.26" } +strum = { default-features = false, features = ["derive"], version = "0.26" } [profile.dev] codegen-units = 256 diff --git a/actors/Cargo.toml b/actors/Cargo.toml index 95a67a9a..55177a11 100644 --- a/actors/Cargo.toml +++ b/actors/Cargo.toml @@ -28,7 +28,10 @@ serde = [ ] std = [ + "futures/std", "scsys-core/std", + "serde/std", + "strum/std", ] tokio = [ @@ -48,16 +51,17 @@ test = true [dependencies] async-trait = "0.1" -futures = "0.3" +futures = { default-features = false, features = [], version = "0.3"} glob = "0.3" paste.workspace = true -serde = { optional = true, features = ["derive"], version = "1" } +serde = { default-features = false, optional = true, features = ["derive"], version = "1" } # serde_json = { optional = true, version = "1" } smart-default.workspace = true strum.workspace = true tokio = { optional = true, version = "1" } [dependencies.scsys-core] +default-features = false path = "../core" version = "0.2.2" # version = "0.2.2-nightly" diff --git a/actors/src/actor.rs b/actors/src/actor.rs index 9044a997..4ec88281 100644 --- a/actors/src/actor.rs +++ b/actors/src/actor.rs @@ -3,4 +3,10 @@ Creator: FL03 */ -pub trait Actor {} +pub mod engine; + +pub trait Actor { + type Ctx; + type Engine; + +} diff --git a/actors/src/actor/engine.rs b/actors/src/actor/engine.rs new file mode 100644 index 00000000..6dce6463 --- /dev/null +++ b/actors/src/actor/engine.rs @@ -0,0 +1,6 @@ +/* + Appellation: engine + Creator: FL03 +*/ + + diff --git a/actors/src/lib.rs b/actors/src/lib.rs index c8c6c846..9fa3017c 100644 --- a/actors/src/lib.rs +++ b/actors/src/lib.rs @@ -5,7 +5,9 @@ //! # Actors //! //! This library seeks to provide a suite of tools for creating and managing actors in Rust. -#[cfg(not(feature = "std"))] +#![cfg_attr(not(feature = "std"), no_std)] + +#[cfg(no_std)] extern crate alloc; extern crate scsys_core as scsys; diff --git a/actors/src/power/mod.rs b/actors/src/power/mod.rs index 7da7b2cb..b50329c5 100644 --- a/actors/src/power/mod.rs +++ b/actors/src/power/mod.rs @@ -9,7 +9,7 @@ pub use self::state::Power; pub(crate) mod state; -#[cfg(feature = "tokio-ext")] + pub mod shutdown; #[cfg(test)] diff --git a/actors/src/power/shutdown.rs b/actors/src/power/shutdown.rs index 2272add0..f54aba84 100644 --- a/actors/src/power/shutdown.rs +++ b/actors/src/power/shutdown.rs @@ -2,6 +2,8 @@ Appellation: shutdown Contrib: FL03 */ +#![cfg(feature = "tokio")] + use super::Power; use tokio::sync::broadcast; diff --git a/actors/tests/default.rs b/actors/tests/default.rs index f7f43e25..d9f69d40 100644 --- a/actors/tests/default.rs +++ b/actors/tests/default.rs @@ -2,11 +2,10 @@ Appellation: default Contrib: FL03 */ -#![cfg(test)] fn addition(a: A, b: B) -> C where - A: std::ops::Add, + A: core::ops::Add, { a + b } diff --git a/core/Cargo.toml b/core/Cargo.toml index 89e20b46..f2ba649d 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -31,7 +31,10 @@ serde = [ "dep:serde", ] -std = [] +std = [ + "serde/std", + "strum/std", +] [lib] bench = false @@ -44,12 +47,13 @@ test = true [dependencies] glob = "0.3" rand = { optional = true, version = "0.8" } -serde = { optional = true, features = ["derive"], version = "1" } +serde = { default-features = false, optional = true, features = ["derive"], version = "1" } smart-default.workspace = true strum.workspace = true [dev-dependencies] anyhow = "1" +serde_json = "1" [package.metadata.docs.rs] rustc-args = ["--cfg", "docsrs"] diff --git a/core/src/lib.rs b/core/src/lib.rs index 3322af1e..6b287be7 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -7,7 +7,7 @@ //! #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(not(feature = "std"))] +#[cfg(no_std)] extern crate alloc; #[doc(inline)] @@ -22,20 +22,18 @@ pub(crate) mod utils; pub mod errors; pub mod hkt; pub mod id; +pub mod stores; pub mod sync; pub mod time; pub mod traits; pub mod types; -/// -pub const DEFAULT_IGNORE_CHARS: &[char] = &['[', ']', ',', '.', ' ']; pub mod prelude { - pub use crate::DEFAULT_IGNORE_CHARS; - pub use crate::errors::*; pub use crate::hkt::prelude::*; pub use crate::id::prelude::*; + pub use crate::stores::prelude::*; pub use crate::sync::prelude::*; pub use crate::time::*; pub use crate::traits::prelude::*; diff --git a/core/src/stores/mod.rs b/core/src/stores/mod.rs new file mode 100644 index 00000000..1bdaf105 --- /dev/null +++ b/core/src/stores/mod.rs @@ -0,0 +1,11 @@ +/* + Appellation: stores + Contrib: FL03 +*/ +pub use self::store::*; + +pub(crate) mod store; + +pub(crate) mod prelude { + pub use super::store::*; +} \ No newline at end of file diff --git a/core/src/stores/store.rs b/core/src/stores/store.rs new file mode 100644 index 00000000..c0ded27f --- /dev/null +++ b/core/src/stores/store.rs @@ -0,0 +1,93 @@ +/* + Appellation: store + Contrib: FL03 +*/ +#[cfg(no_std)] +use alloc::collections::{btree_map, BTreeMap}; +#[cfg(not(no_std))] +use std::collections::{btree_map, BTreeMap}; + +pub trait Entry<'a> { + type Key; + type Value; + + fn key(&self) -> &Self::Key; + + fn or_insert(self, default: Self::Value) -> &'a mut Self::Value; +} + +pub trait OrInsert { + fn or_insert(&mut self, key: K, value: V) -> &mut V; +} + +pub trait Store { + fn get(&self, key: &K) -> Option<&V>; + + fn get_mut(&mut self, key: &K) -> Option<&mut V>; + + fn insert(&mut self, key: K, value: V) -> Option; + + fn remove(&mut self, key: &K) -> Option; +} + +/* + ********* Implementations ********* +*/ +macro_rules! entry { + ($($prefix:ident)::* -> $call:ident($($arg:tt),*)) => { + $($prefix)::*::Entry::$call($($arg),*) + }; + +} + +macro_rules! impl_entry { + ($($prefix:ident)::* where $($preds:tt)* ) => { + + impl<'a, K, V> Entry<'a> for $($prefix)::*::Entry<'a, K, V> where $($preds)* { + type Key = K; + type Value = V; + + fn key(&self) -> &Self::Key { + entry!($($prefix)::* -> key(self)) + } + + fn or_insert(self, default: Self::Value) -> &'a mut Self::Value { + entry!($($prefix)::* -> or_insert(self, default)) + } + } + + }; + +} + +macro_rules! impl_store { + ($t:ty, where $($preds:tt)* ) => { + + impl Store for $t where $($preds)* { + fn get(&self, key: &K) -> Option<&V> { + <$t>::get(self, &key) + } + + fn get_mut(&mut self, key: &K) -> Option<&mut V> { + <$t>::get_mut(self, &key) + } + + fn insert(&mut self, key: K, value: V) -> Option { + <$t>::insert(self, key, value) + } + + fn remove(&mut self, key: &K) -> Option { + <$t>::remove(self, &key) + } + } + + }; +} + +impl_entry!(btree_map where K: Ord); +impl_store!(BTreeMap, where K: Ord); + +#[cfg(feature = "std")] +impl_entry!(std::collections::hash_map where K: Eq + core::hash::Hash); +#[cfg(feature = "std")] +impl_store!(std::collections::HashMap, where K: Eq + core::hash::Hash); diff --git a/core/src/types/mod.rs b/core/src/types/mod.rs index a4601ad7..115bd1b0 100644 --- a/core/src/types/mod.rs +++ b/core/src/types/mod.rs @@ -9,7 +9,7 @@ pub use self::{direction::Direction, utils::*}; pub mod direction; -pub type AnyAsync = Box; +pub type BoxAny = Box; /// A type alias for [core::result::Result] that employs the [crate::errors::Error] type pub type Result = core::result::Result; @@ -55,10 +55,11 @@ pub(crate) mod utils { } pub(crate) mod prelude { + pub use super::{BoxAny, Result}; + pub use super::direction::Direction; #[cfg(feature = "std")] pub use super::std_types::*; pub use super::utils::*; - pub use super::{AnyAsync, Result}; } #[cfg(test)] diff --git a/core/src/utils.rs b/core/src/utils.rs index c7f3781a..d568ce18 100644 --- a/core/src/utils.rs +++ b/core/src/utils.rs @@ -2,27 +2,9 @@ Appellation: utils Contrib: FL03 */ -#[cfg(feature = "std")] -pub use self::fs::*; - -use core::fmt; -use core::str::FromStr; - -/// A simple extraction utility for getting values from a string and converting them into a [Vec] -pub fn extractor(bp: char, data: &S, exclude: Option<&[char]>) -> Vec -where - S: ToString, - T: FromStr + ToString, - ::Err: fmt::Debug, -{ - let data = data.to_string(); - let skip = exclude.unwrap_or(crate::DEFAULT_IGNORE_CHARS); - let trimmed: &str = data.trim_matches(skip); - trimmed - .split(bp) - .map(|i| i.trim_matches(skip).parse::().unwrap()) - .collect() -} +#[cfg(not(no_std))] +pub use self::std_utils::*; + /// Remove the first and last charecters of a string pub fn fnl_remove(data: impl ToString) -> String { let data = data.to_string(); @@ -32,16 +14,6 @@ pub fn fnl_remove(data: impl ToString) -> String { chars.as_str().to_string() } -/// Fetch the project root unless specified otherwise with a CARGO_MANIFEST_DIR env variable -#[cfg(feature = "std")] -pub fn project_root() -> std::path::PathBuf { - std::path::Path::new(&env!("CARGO_MANIFEST_DIR")) - .ancestors() - .nth(1) - .unwrap() - .to_path_buf() -} - pub fn snakecase(name: impl ToString) -> String { let data = name.to_string(); @@ -86,26 +58,41 @@ pub fn snakecase(name: impl ToString) -> String { buffer } -#[cfg(feature = "std")] -mod fs { - use std::fs::File; - use std::io::{self, BufRead, BufReader}; - /// A generic function wrapper extending glob::glob - pub fn collect_files_as(f: &dyn Fn(std::path::PathBuf) -> T, pat: &str) -> Vec { - let mut files = Vec::::new(); - for path in glob::glob(pat).expect("Failed to read glob pattern...") { - if let Ok(r) = path { - files.push(f(r)) + + +#[cfg(not(no_std))] +mod std_utils { + pub use self::fs::*; + + /// Fetch the project root unless specified otherwise with a CARGO_MANIFEST_DIR env variable + pub fn project_root() -> std::path::PathBuf { + std::path::Path::new(&env!("CARGO_MANIFEST_DIR")) + .ancestors() + .nth(1) + .unwrap() + .to_path_buf() + } + + mod fs { + use std::fs::File; + use std::io::{self, BufRead, BufReader}; + /// A generic function wrapper extending glob::glob + pub fn collect_files_as(f: &dyn Fn(std::path::PathBuf) -> T, pat: &str) -> Vec { + let mut files = Vec::::new(); + for path in glob::glob(pat).expect("Failed to read glob pattern...") { + if let Ok(r) = path { + files.push(f(r)) + } + continue; } - continue; + files } - files - } - /// This function converts the file found at path (fp) into a [Vec] - pub fn file_to_vec(fp: String) -> Result, io::Error> { - let file_in = File::open(fp)?; - let file_reader = BufReader::new(file_in); - Ok(file_reader.lines().filter_map(Result::ok).collect()) + /// This function converts the file found at path (fp) into a [Vec] + pub fn file_to_vec(fp: String) -> Result, io::Error> { + let file_in = File::open(fp)?; + let file_reader = BufReader::new(file_in); + Ok(file_reader.lines().filter_map(Result::ok).collect()) + } } -} +} \ No newline at end of file diff --git a/core/tests/default.rs b/core/tests/default.rs index f7f43e25..6353d6be 100644 --- a/core/tests/default.rs +++ b/core/tests/default.rs @@ -2,11 +2,10 @@ Appellation: default Contrib: FL03 */ -#![cfg(test)] fn addition(a: A, b: B) -> C where - A: std::ops::Add, + A: core::ops::Add, { a + b } @@ -14,5 +13,5 @@ where #[test] fn compiles() { assert_eq!(addition(1, 2), 3); - assert_ne!(addition(1_f64, 0_f64), 3_f64); + assert_ne!(addition(1f64, 0f64), 3f64); } diff --git a/core/tests/errors.rs b/core/tests/errors.rs new file mode 100644 index 00000000..2b88e170 --- /dev/null +++ b/core/tests/errors.rs @@ -0,0 +1,24 @@ +/* + Appellation: errors + Contrib: FL03 +*/ +extern crate scsys_core as scsys; + +use scsys::errors::{Error, ErrorKind}; + +#[test] +fn test_error() { + let msg = "test"; + let err = Error::new(ErrorKind::custom("custom"), msg.to_string()); + assert_eq!(err.kind(), &ErrorKind::custom("custom")); +} + +#[test] +#[cfg(feature = "serde")] +fn test_error_serde() { + let err = Error::new(ErrorKind::custom("custom"), "test".to_string()); + let json = serde_json::to_value(&err).unwrap(); + let err2: Error = serde_json::from_value(json).unwrap(); + assert_eq!(err, err2); +} + diff --git a/core/tests/time.rs b/core/tests/time.rs deleted file mode 100644 index d8c310c2..00000000 --- a/core/tests/time.rs +++ /dev/null @@ -1,5 +0,0 @@ -/* - Appellation: default - Contrib: FL03 -*/ -#![cfg(test)] diff --git a/scsys/Cargo.toml b/scsys/Cargo.toml index 231653a5..b4a0d92b 100644 --- a/scsys/Cargo.toml +++ b/scsys/Cargo.toml @@ -14,7 +14,6 @@ version.workspace = true [features] default = [ "actors", - "stores", "std", ] @@ -27,16 +26,16 @@ full = [ ] actors = [ - "dep:scsys-actors" + "dep:scsys-actors", ] derive = [ "dep:scsys-derive", - "macros" + "macros", ] macros = [ - "dep:scsys-macros" + "dep:scsys-macros", ] rand = [ @@ -46,17 +45,11 @@ rand = [ serde = [ "scsys-actors/serde", "scsys-core/serde", - "scsys-stores/serde", ] std = [ "scsys-actors/std", "scsys-core/std", - "scsys-stores/std", -] - -stores = [ - "dep:scsys-stores" ] tokio = [ @@ -89,7 +82,6 @@ scsys-core = { path = "../core", version = "0.2.2" } scsys-actors = { optional = true, path = "../actors", version = "0.2.2" } scsys-derive = { optional = true, path = "../derive", version = "0.2.2" } scsys-macros = { optional = true, path = "../macros", version = "0.2.2" } -scsys-stores = { optional = true, path = "../stores", version = "0.2.2" } [dev-dependencies] serde = { features = ["derive"], version = "1" } diff --git a/scsys/src/lib.rs b/scsys/src/lib.rs index e24b9c0e..531a9023 100644 --- a/scsys/src/lib.rs +++ b/scsys/src/lib.rs @@ -17,9 +17,6 @@ pub use scsys_derive::*; #[cfg(feature = "macros")] #[doc(inline)] pub use scsys_macros::*; -#[cfg(feature = "stores")] -#[doc(inline)] -pub use scsys_stores as stores; // #66 - Cleanup the prelude module(s) pub mod prelude { @@ -32,7 +29,4 @@ pub mod prelude { pub use scsys_derive::*; #[cfg(feature = "macros")] pub use scsys_macros::*; - #[cfg(feature = "stores")] - #[doc(inline)] - pub use scsys_stores::prelude::*; } diff --git a/scsys/tests/default.rs b/scsys/tests/default.rs index f7f43e25..6353d6be 100644 --- a/scsys/tests/default.rs +++ b/scsys/tests/default.rs @@ -2,11 +2,10 @@ Appellation: default Contrib: FL03 */ -#![cfg(test)] fn addition(a: A, b: B) -> C where - A: std::ops::Add, + A: core::ops::Add, { a + b } @@ -14,5 +13,5 @@ where #[test] fn compiles() { assert_eq!(addition(1, 2), 3); - assert_ne!(addition(1_f64, 0_f64), 3_f64); + assert_ne!(addition(1f64, 0f64), 3f64); } diff --git a/stores/Cargo.toml b/stores/Cargo.toml deleted file mode 100644 index 12427700..00000000 --- a/stores/Cargo.toml +++ /dev/null @@ -1,58 +0,0 @@ -[package] -authors.workspace = true -categories.workspace = true -description.workspace = true -edition.workspace = true -homepage.workspace = true -keywords.workspace = true -license.workspace = true -name = "scsys-stores" -readme.workspace = true -repository.workspace = true -version.workspace = true - -[features] -default = [ - "std", -] - -full = [ - "default", - "serde", -] - -serde = [ - "dep:serde", - "scsys-core/serde" -] - -std = [ - "scsys-core/std" -] - -[lib] -bench = false -crate-type = ["cdylib", "rlib"] -doctest = false -test = true - -[build-dependencies] - -[dependencies] -serde = { optional = true, features = ["derive"], version = "1" } -smart-default.workspace = true -strum.workspace = true - -[dependencies.scsys-core] -path = "../core" -version = "0.2.2" - -[dev-dependencies] - -[package.metadata.docs.rs] -all-features = true -rustc-args = ["--cfg", "docsrs"] - -[target.wasm32-unknown-unknown] - -[target.wasm32-wasi] \ No newline at end of file diff --git a/stores/src/actions/crud/mod.rs b/stores/src/actions/crud/mod.rs deleted file mode 100644 index d06f011c..00000000 --- a/stores/src/actions/crud/mod.rs +++ /dev/null @@ -1,10 +0,0 @@ -/* - Appellation: crud - Contrib: FL03 -*/ -pub use self::mode::*; - -pub(crate) mod mode; - -#[cfg(test)] -mod tests {} diff --git a/stores/src/actions/crud/mode.rs b/stores/src/actions/crud/mode.rs deleted file mode 100644 index 9b28b2ab..00000000 --- a/stores/src/actions/crud/mode.rs +++ /dev/null @@ -1,84 +0,0 @@ -/* - Appellation: mode - Contrib: FL03 -*/ -use strum::{ - AsRefStr, Display, EnumCount, EnumDiscriminants, EnumIs, EnumIter, EnumString, VariantNames, -}; - -/// The mode of a CRUD operation. -/// -#[derive( - AsRefStr, - Clone, - Copy, - Debug, - Display, - EnumCount, - EnumDiscriminants, - EnumIs, - Eq, - Hash, - Ord, - PartialEq, - PartialOrd, - VariantNames, -)] -#[cfg_attr( - feature = "serde", - derive(serde::Deserialize, serde::Serialize), - serde(rename_all = "lowercase", untagged) -)] -#[cfg_attr( - feature = "serde", - strum_discriminants( - derive(serde::Deserialize, serde::Serialize), - serde(rename_all = "lowercase", untagged) - ) -)] -#[strum(serialize_all = "lowercase")] -#[strum_discriminants( - name(CRUD), - derive( - AsRefStr, - Display, - EnumCount, - EnumIs, - EnumIter, - EnumString, - Hash, - Ord, - PartialOrd, - VariantNames - ), - strum(serialize_all = "lowercase") -)] -pub enum CRUDEvent { - Create(T), - Read(T), - Update(T), - Delete(T), -} - -macro_rules! crud_constructors { - ($($variant:ident.$call:ident),* $(,)?) => { - impl CRUDEvent { - $( - pub fn $call(data: T) -> Self { - Self::$variant(data) - } - )* - } - - impl CRUD { - $( - pub fn $call() -> Self { - Self::$variant - } - )* - } - }; - -} - -crud_constructors!(Create.create, Read.read, Update.update, Delete.delete,); diff --git a/stores/src/actions/mod.rs b/stores/src/actions/mod.rs deleted file mode 100644 index e6fa8567..00000000 --- a/stores/src/actions/mod.rs +++ /dev/null @@ -1,13 +0,0 @@ -/* - Appellation: actions - Contrib: FL03 -*/ - -pub mod crud; - -pub(crate) mod prelude { - pub use super::crud::CRUD; -} - -#[cfg(test)] -mod tests {} diff --git a/stores/src/caches/mod.rs b/stores/src/caches/mod.rs deleted file mode 100644 index 15d34c1f..00000000 --- a/stores/src/caches/mod.rs +++ /dev/null @@ -1,12 +0,0 @@ -/* - Appellation: caches - Contrib: FL03 -*/ -//! Caches -//! -//! - -pub trait CacheBackend {} - -#[cfg(test)] -mod tests {} diff --git a/stores/src/kv/mod.rs b/stores/src/kv/mod.rs deleted file mode 100644 index 41ea1bb7..00000000 --- a/stores/src/kv/mod.rs +++ /dev/null @@ -1,66 +0,0 @@ -/* - Appellation: kv - Contrib: FL03 -*/ -//! Key-Value Store - -pub trait KeyValue { - fn get(&self, key: &K) -> Option<&V>; - - fn insert(&mut self, key: K, value: V) -> Option; - - fn remove(&mut self, key: &K) -> Option; -} - -pub trait OrInsert { - fn or_insert(&mut self, key: K, value: V) -> &mut V; -} - -macro_rules! impl_kv { - ($t:ty, where $($preds:tt)* ) => { - - impl KeyValue for $t where $($preds)* { - fn get(&self, key: &K) -> Option<&V> { - <$t>::get(self, &key) - } - - fn insert(&mut self, key: K, value: V) -> Option { - <$t>::insert(self, key, value) - } - - fn remove(&mut self, key: &K) -> Option { - <$t>::remove(self, &key) - } - } - }; -} - -use std::collections::{BTreeMap, HashMap}; - -impl_kv!(BTreeMap, where K: std::cmp::Ord); -impl_kv!(HashMap, where K: std::cmp::Eq + std::hash::Hash); - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_kv() { - let mut map = HashMap::new(); - map.insert(1, "one"); - map.insert(2, "two"); - map.insert(3, "three"); - - assert_eq!(map.get(&1), Some(&"one")); - assert_eq!(map.get(&2), Some(&"two")); - assert_eq!(map.get(&3), Some(&"three")); - - assert_eq!(map.remove(&1), Some("one")); - assert_eq!(map.remove(&2), Some("two")); - assert_eq!(map.remove(&3), Some("three")); - - assert_eq!(map.get(&1), None); - assert_eq!(map.get(&2), None); - assert_eq!(map.get(&3), None); - } -} diff --git a/stores/src/lib.rs b/stores/src/lib.rs deleted file mode 100644 index e3060fea..00000000 --- a/stores/src/lib.rs +++ /dev/null @@ -1,21 +0,0 @@ -/* - Appellation: scsys-stores - Creator: FL03 -*/ -//! # Stores -//! -//! - -pub mod actions; -pub mod caches; -pub mod kv; -pub mod queues; -pub mod registries; -pub mod repos; -pub mod store; - -pub mod prelude { - pub use crate::actions::prelude::*; - - pub use crate::store::*; -} diff --git a/stores/src/queues/mod.rs b/stores/src/queues/mod.rs deleted file mode 100644 index e3a8e83f..00000000 --- a/stores/src/queues/mod.rs +++ /dev/null @@ -1,13 +0,0 @@ -/* - Appellation: queues - Contrib: FL03 -*/ -//! Queues -//! -//! -pub use self::queue::Queue; - -pub(crate) mod queue; - -#[cfg(test)] -mod tests {} diff --git a/stores/src/queues/queue.rs b/stores/src/queues/queue.rs deleted file mode 100644 index 7ce38e1d..00000000 --- a/stores/src/queues/queue.rs +++ /dev/null @@ -1,6 +0,0 @@ -/* - Appellation: queue - Contrib: FL03 -*/ - -pub struct Queue; diff --git a/stores/src/registries/mod.rs b/stores/src/registries/mod.rs deleted file mode 100644 index 7db14253..00000000 --- a/stores/src/registries/mod.rs +++ /dev/null @@ -1,15 +0,0 @@ -/* - Appellation: registries - Contrib: FL03 -*/ -//! Registries -//! -//! -pub use self::registry::*; - -pub(crate) mod registry; - -pub trait Register {} - -#[cfg(test)] -mod tests {} diff --git a/stores/src/registries/registry.rs b/stores/src/registries/registry.rs deleted file mode 100644 index 178a2962..00000000 --- a/stores/src/registries/registry.rs +++ /dev/null @@ -1,6 +0,0 @@ -/* - Appellation: registry - Contrib: FL03 -*/ - -pub struct Registry {} diff --git a/stores/src/repos/mod.rs b/stores/src/repos/mod.rs deleted file mode 100644 index 5e5db385..00000000 --- a/stores/src/repos/mod.rs +++ /dev/null @@ -1,12 +0,0 @@ -/* - Appellation: repos - Contrib: FL03 -*/ -//! Repos -//! -//! - -pub trait Repo {} - -#[cfg(test)] -mod tests {} diff --git a/stores/src/store.rs b/stores/src/store.rs deleted file mode 100644 index cc21fd9b..00000000 --- a/stores/src/store.rs +++ /dev/null @@ -1,6 +0,0 @@ -/* - Appellation: store - Contrib: FL03 -*/ - -pub trait Store {} diff --git a/stores/tests/default.rs b/stores/tests/default.rs deleted file mode 100644 index f7f43e25..00000000 --- a/stores/tests/default.rs +++ /dev/null @@ -1,18 +0,0 @@ -/* - Appellation: default - Contrib: FL03 -*/ -#![cfg(test)] - -fn addition(a: A, b: B) -> C -where - A: std::ops::Add, -{ - a + b -} - -#[test] -fn compiles() { - assert_eq!(addition(1, 2), 3); - assert_ne!(addition(1_f64, 0_f64), 3_f64); -} From fe96789066f600024273d754e4a74125b8de42dc Mon Sep 17 00:00:00 2001 From: Joe McCain III Date: Mon, 6 May 2024 10:11:56 -0500 Subject: [PATCH 07/10] update Signed-off-by: Joe McCain III --- actors/src/actor.rs | 1 - actors/src/actor/engine.rs | 2 -- actors/src/power/mod.rs | 1 - core/src/lib.rs | 1 - core/src/stores/{store.rs => kv.rs} | 6 +----- core/src/stores/mod.rs | 12 ++++++++---- core/src/types/mod.rs | 2 +- core/src/utils.rs | 4 +--- core/tests/errors.rs | 1 - scsys/Cargo.toml | 2 +- 10 files changed, 12 insertions(+), 20 deletions(-) rename core/src/stores/{store.rs => kv.rs} (94%) diff --git a/actors/src/actor.rs b/actors/src/actor.rs index 4ec88281..79a34936 100644 --- a/actors/src/actor.rs +++ b/actors/src/actor.rs @@ -8,5 +8,4 @@ pub mod engine; pub trait Actor { type Ctx; type Engine; - } diff --git a/actors/src/actor/engine.rs b/actors/src/actor/engine.rs index 6dce6463..d28fbb2e 100644 --- a/actors/src/actor/engine.rs +++ b/actors/src/actor/engine.rs @@ -2,5 +2,3 @@ Appellation: engine Creator: FL03 */ - - diff --git a/actors/src/power/mod.rs b/actors/src/power/mod.rs index b50329c5..d397486d 100644 --- a/actors/src/power/mod.rs +++ b/actors/src/power/mod.rs @@ -9,7 +9,6 @@ pub use self::state::Power; pub(crate) mod state; - pub mod shutdown; #[cfg(test)] diff --git a/core/src/lib.rs b/core/src/lib.rs index 6b287be7..ae0e2018 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -28,7 +28,6 @@ pub mod time; pub mod traits; pub mod types; - pub mod prelude { pub use crate::errors::*; pub use crate::hkt::prelude::*; diff --git a/core/src/stores/store.rs b/core/src/stores/kv.rs similarity index 94% rename from core/src/stores/store.rs rename to core/src/stores/kv.rs index c0ded27f..40b0c498 100644 --- a/core/src/stores/store.rs +++ b/core/src/stores/kv.rs @@ -16,10 +16,6 @@ pub trait Entry<'a> { fn or_insert(self, default: Self::Value) -> &'a mut Self::Value; } -pub trait OrInsert { - fn or_insert(&mut self, key: K, value: V) -> &mut V; -} - pub trait Store { fn get(&self, key: &K) -> Option<&V>; @@ -31,7 +27,7 @@ pub trait Store { } /* - ********* Implementations ********* + ********* Implementations ********* */ macro_rules! entry { ($($prefix:ident)::* -> $call:ident($($arg:tt),*)) => { diff --git a/core/src/stores/mod.rs b/core/src/stores/mod.rs index 1bdaf105..56422bd4 100644 --- a/core/src/stores/mod.rs +++ b/core/src/stores/mod.rs @@ -2,10 +2,14 @@ Appellation: stores Contrib: FL03 */ -pub use self::store::*; -pub(crate) mod store; +pub mod kv; + +pub trait OrInsert { + fn or_insert(&mut self, key: K, value: V) -> &mut V; +} pub(crate) mod prelude { - pub use super::store::*; -} \ No newline at end of file + pub use super::kv::Store as KeyValue; + pub use super::OrInsert; +} diff --git a/core/src/types/mod.rs b/core/src/types/mod.rs index 115bd1b0..2b2de35c 100644 --- a/core/src/types/mod.rs +++ b/core/src/types/mod.rs @@ -55,11 +55,11 @@ pub(crate) mod utils { } pub(crate) mod prelude { - pub use super::{BoxAny, Result}; pub use super::direction::Direction; #[cfg(feature = "std")] pub use super::std_types::*; pub use super::utils::*; + pub use super::{BoxAny, Result}; } #[cfg(test)] diff --git a/core/src/utils.rs b/core/src/utils.rs index d568ce18..383940f3 100644 --- a/core/src/utils.rs +++ b/core/src/utils.rs @@ -58,8 +58,6 @@ pub fn snakecase(name: impl ToString) -> String { buffer } - - #[cfg(not(no_std))] mod std_utils { pub use self::fs::*; @@ -95,4 +93,4 @@ mod std_utils { Ok(file_reader.lines().filter_map(Result::ok).collect()) } } -} \ No newline at end of file +} diff --git a/core/tests/errors.rs b/core/tests/errors.rs index 2b88e170..b3b6cfaf 100644 --- a/core/tests/errors.rs +++ b/core/tests/errors.rs @@ -21,4 +21,3 @@ fn test_error_serde() { let err2: Error = serde_json::from_value(json).unwrap(); assert_eq!(err, err2); } - diff --git a/scsys/Cargo.toml b/scsys/Cargo.toml index b4a0d92b..82c874e4 100644 --- a/scsys/Cargo.toml +++ b/scsys/Cargo.toml @@ -13,12 +13,12 @@ version.workspace = true [features] default = [ - "actors", "std", ] full = [ "default", + "actors", "derive", "rand", "serde", From 1fa488f41a7561b47c299062443c3d6655ea7a1a Mon Sep 17 00:00:00 2001 From: Joe McCain III Date: Sat, 11 May 2024 14:24:21 -0500 Subject: [PATCH 08/10] update Signed-off-by: Joe McCain III --- actors/Cargo.toml | 47 ++++++++++++++++++++++++++++++-------- core/Cargo.toml | 36 ++++++++++++++++++++++++++--- core/build.rs | 8 +++++++ core/src/lib.rs | 2 +- core/src/time/timestamp.rs | 1 + core/src/traits/mod.rs | 18 +-------------- core/src/utils.rs | 4 ++-- scsys/Cargo.toml | 27 ++++++++++++++++++---- 8 files changed, 106 insertions(+), 37 deletions(-) create mode 100644 core/build.rs diff --git a/actors/Cargo.toml b/actors/Cargo.toml index 55177a11..e48e90ea 100644 --- a/actors/Cargo.toml +++ b/actors/Cargo.toml @@ -22,25 +22,42 @@ full = [ "tokio" ] +# *** [FF] Dependencies *** + +alloc = [ + "scsys-core/alloc", + "serde?/alloc", +] + serde = [ "dep:serde", "scsys-core/serde", ] +tokio = [ + "dep:tokio", + "tokio-ext", +] + +tokio-ext = [ + "tokio/sync", +] + +# *** [FF] Environments *** + std = [ "futures/std", "scsys-core/std", - "serde/std", + "serde?/std", "strum/std", ] -tokio = [ - "dep:tokio", - "tokio-ext", +wasi = [ + "scsys-core/wasi", ] -tokio-ext = [ - "tokio/sync", +wasm = [ + "scsys-core/wasm", ] [lib] @@ -51,14 +68,14 @@ test = true [dependencies] async-trait = "0.1" -futures = { default-features = false, features = [], version = "0.3"} glob = "0.3" paste.workspace = true -serde = { default-features = false, optional = true, features = ["derive"], version = "1" } -# serde_json = { optional = true, version = "1" } smart-default.workspace = true strum.workspace = true -tokio = { optional = true, version = "1" } + +[dependencies.futures] +default-features = false +version = "0.3" [dependencies.scsys-core] default-features = false @@ -66,6 +83,16 @@ path = "../core" version = "0.2.2" # version = "0.2.2-nightly" +[dependencies.serde] +default-features = false +features = ["derive"] +optional = true +version = "1" + +[dependencies.tokio] +optional = true +version = "1" + [dev-dependencies] [package.metadata.docs.rs] diff --git a/core/Cargo.toml b/core/Cargo.toml index f2ba649d..d3d9fee1 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,5 +1,6 @@ [package] authors.workspace = true +build = "build.rs" categories.workspace = true description.workspace = true edition.workspace = true @@ -23,19 +24,39 @@ full = [ "serde", ] + + +# *** [FF] Dependencies *** +alloc = [ + "rand?/alloc", + "serde?/alloc", +] + rand = [ "dep:rand", ] serde = [ "dep:serde", + "serde-ext", +] + +serde-ext = [ + "rand?/serde1", ] +# *** [FF] Environment(s) *** std = [ - "serde/std", + "rand?/std", + "rand?/std_rng", + "serde?/std", "strum/std", ] +wasi = [] + +wasm = [] + [lib] bench = false crate-type = ["cdylib", "rlib"] @@ -46,11 +67,20 @@ test = true [dependencies] glob = "0.3" -rand = { optional = true, version = "0.8" } -serde = { default-features = false, optional = true, features = ["derive"], version = "1" } smart-default.workspace = true strum.workspace = true +[dependencies.rand] +default-features = false +optional = true +version = "0.8" + +[dependencies.serde] +default-features = false +features = ["derive"] +optional = true +version = "1" + [dev-dependencies] anyhow = "1" serde_json = "1" diff --git a/core/build.rs b/core/build.rs new file mode 100644 index 00000000..940a4ce4 --- /dev/null +++ b/core/build.rs @@ -0,0 +1,8 @@ +/* + Appellation: build + Contrib: FL03 +*/ + +fn main() { + println!("cargo::rustc-check-cfg=cfg(no_std)"); +} diff --git a/core/src/lib.rs b/core/src/lib.rs index ae0e2018..f7c7a65b 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -7,7 +7,7 @@ //! #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(no_std)] +#[cfg(feature = "alloc")] extern crate alloc; #[doc(inline)] diff --git a/core/src/time/timestamp.rs b/core/src/time/timestamp.rs index 8dc9826f..a1235b03 100644 --- a/core/src/time/timestamp.rs +++ b/core/src/time/timestamp.rs @@ -17,6 +17,7 @@ impl Timestamp { } /// Create a new timestamp + #[cfg(feature = "std")] pub fn now() -> Self { Self(crate::time::systime()) } diff --git a/core/src/traits/mod.rs b/core/src/traits/mod.rs index 11c00901..a25ed7f0 100644 --- a/core/src/traits/mod.rs +++ b/core/src/traits/mod.rs @@ -19,23 +19,7 @@ pub mod ext { } } -/// Interface for data-structures that can be compared for equality -pub trait Contain -where - T: PartialEq, -{ - /// [Contain::contains] returns true if the given element is in the [Contain] instance - fn contains(&self, elem: &T) -> bool; - /// [Contain::contains_all] returns true if all elements in the given iterator are in the [Contain] instance - fn contains_all(&self, iter: impl IntoIterator) -> bool { - iter.into_iter().all(|i| self.contains(&i)) - } - /// [Contain::contains_some] returns true if any element in the given iterator is in the [Contain] instance - fn contains_some(&self, iter: impl IntoIterator) -> bool { - iter.into_iter().any(|i| self.contains(&i)) - } -} - +/// [IntoInner] is typically used for basic structures that wrap a single value. pub trait IntoInner { type Inner; diff --git a/core/src/utils.rs b/core/src/utils.rs index 383940f3..e940e9fd 100644 --- a/core/src/utils.rs +++ b/core/src/utils.rs @@ -2,7 +2,7 @@ Appellation: utils Contrib: FL03 */ -#[cfg(not(no_std))] +#[cfg(feature = "std")] pub use self::std_utils::*; /// Remove the first and last charecters of a string @@ -58,7 +58,7 @@ pub fn snakecase(name: impl ToString) -> String { buffer } -#[cfg(not(no_std))] +#[cfg(feature = "std")] mod std_utils { pub use self::fs::*; diff --git a/scsys/Cargo.toml b/scsys/Cargo.toml index 82c874e4..8b3a6b4d 100644 --- a/scsys/Cargo.toml +++ b/scsys/Cargo.toml @@ -25,6 +25,8 @@ full = [ "tokio", ] +# *** [FF] Crates *** + actors = [ "dep:scsys-actors", ] @@ -38,24 +40,41 @@ macros = [ "dep:scsys-macros", ] +# *** [FF] Dependencies *** +alloc = [ + "scsys-actors?/alloc", + "scsys-core/alloc", +] rand = [ "scsys-core/rand", ] serde = [ - "scsys-actors/serde", + "scsys-actors?/serde", "scsys-core/serde", ] +tokio = [ + "scsys-actors?/tokio", +] +# *** [FF] Environments *** + std = [ - "scsys-actors/std", + "scsys-actors?/std", "scsys-core/std", ] -tokio = [ - "scsys-actors/tokio", +wasi = [ + "scsys-actors?/wasi", + "scsys-core/wasi", +] + +wasm = [ + "scsys-actors?/wasm", + "scsys-core/wasm", ] + [lib] bench = true crate-type = ["cdylib", "rlib"] From 406e96e47bd2e03e12d773b5e4eb094495bd91e7 Mon Sep 17 00:00:00 2001 From: Joe McCain III Date: Sat, 11 May 2024 14:57:30 -0500 Subject: [PATCH 09/10] update Signed-off-by: Joe McCain III --- .github/ISSUE_TEMPLATE/SCIP.md | 12 +++++++----- .github/dependabot.yml | 14 +++++++------- actors/Cargo.toml | 1 + actors/build.rs | 8 ++++++++ actors/src/lib.rs | 2 +- core/src/hkt/applicative.rs | 24 ++++++++++-------------- core/src/hkt/functor.rs | 7 ++----- core/src/hkt/mod.rs | 20 +++++++++++++++----- core/src/hkt/monad.rs | 6 +----- core/src/traits/mod.rs | 2 +- scsys/Cargo.toml | 24 ++++++++++++++++++------ scsys/benches/default.rs | 13 ++++++------- scsys/src/lib.rs | 3 ++- 13 files changed, 79 insertions(+), 57 deletions(-) create mode 100644 actors/build.rs diff --git a/.github/ISSUE_TEMPLATE/SCIP.md b/.github/ISSUE_TEMPLATE/SCIP.md index 1a277a95..eebafdbc 100644 --- a/.github/ISSUE_TEMPLATE/SCIP.md +++ b/.github/ISSUE_TEMPLATE/SCIP.md @@ -1,10 +1,10 @@ --- -name: Improvement Proposal -about: This template aides in the creation of ecosystem improvement proposals indicated by the prefix SCIP- +about: A template outlining the structure of a formal proposal for a project improvement. +assignees: + - 'FL03 (https://github.com/FL03)' +name: Project Improvement Proposals +labels: ['scip'] title: 'SCIP-' -labels: '' -assignees: '' - --- **Abstract** @@ -18,3 +18,5 @@ A clear and concise description of any alternative solutions or features you've **Discussion** Add any other context or screenshots about the feature request here. + +### Additional Resources \ No newline at end of file diff --git a/.github/dependabot.yml b/.github/dependabot.yml index b682a5f4..0456ea2f 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -3,28 +3,28 @@ updates: - package-ecosystem: cargo directory: / schedule: - interval: daily + interval: weekly - package-ecosystem: github-actions directory: / schedule: - interval: daily + interval: weekly - package-ecosystem: cargo directory: /actors schedule: - interval: daily + interval: weekly - package-ecosystem: cargo directory: /core schedule: - interval: daily + interval: weekly - package-ecosystem: cargo directory: /derive schedule: - interval: daily + interval: weekly - package-ecosystem: cargo directory: /macros schedule: - interval: daily + interval: weekly - package-ecosystem: cargo directory: /scsys schedule: - interval: daily + interval: weekly diff --git a/actors/Cargo.toml b/actors/Cargo.toml index e48e90ea..8f92755f 100644 --- a/actors/Cargo.toml +++ b/actors/Cargo.toml @@ -1,5 +1,6 @@ [package] authors.workspace = true +build = "build.rs" categories.workspace = true description.workspace = true edition.workspace = true diff --git a/actors/build.rs b/actors/build.rs new file mode 100644 index 00000000..940a4ce4 --- /dev/null +++ b/actors/build.rs @@ -0,0 +1,8 @@ +/* + Appellation: build + Contrib: FL03 +*/ + +fn main() { + println!("cargo::rustc-check-cfg=cfg(no_std)"); +} diff --git a/actors/src/lib.rs b/actors/src/lib.rs index 9fa3017c..d8607992 100644 --- a/actors/src/lib.rs +++ b/actors/src/lib.rs @@ -7,7 +7,7 @@ //! This library seeks to provide a suite of tools for creating and managing actors in Rust. #![cfg_attr(not(feature = "std"), no_std)] -#[cfg(no_std)] +#[cfg(feature = "alloc")] extern crate alloc; extern crate scsys_core as scsys; diff --git a/core/src/hkt/applicative.rs b/core/src/hkt/applicative.rs index 5a3fa5e8..7fe265c3 100644 --- a/core/src/hkt/applicative.rs +++ b/core/src/hkt/applicative.rs @@ -8,11 +8,7 @@ use super::functor::Functor; use super::HKT; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, rc::Rc, sync::Arc, vec::Vec}; - -#[cfg(feature = "std")] -use std::{rc::Rc, sync::Arc}; +use super::containers::*; pub trait Applicative: Functor { fn pure_(value: U) -> Self::T @@ -25,15 +21,15 @@ pub trait Applicative: Functor { } macro_rules! applicative { - ($($t:ident($e:expr)),* $(,)?) => { + ($($t:ident),* $(,)?) => { $( - applicative!(@impl $t($e)); + applicative!(@impl $t); )* }; - (@impl $t:ident($e:expr)) => { + (@impl $t:ident) => { impl Applicative for $t { fn pure_(value: U) -> Self::T { - $e(value) + $t::new(value) } fn seq(&self, fs: >::T) -> $t @@ -41,20 +37,20 @@ macro_rules! applicative { F: Fn(&>::C) -> U, { let v = fs(self); - $e(v) + $t::new(v) } } }; } +#[cfg(any(feature = "std", all(feature = "alloc", no_std)))] +applicative!(Arc, Box, Rc); -applicative!(Arc(Arc::new), Box(Box::new), Rc(Rc::new)); - -impl Applicative for core::option::Option { +impl Applicative for Option { fn pure_(value: U) -> Self::T { Some(value) } - fn seq(&self, fs: >::T) -> core::option::Option + fn seq(&self, fs: >::T) -> Option where F: Fn(&T) -> U, { diff --git a/core/src/hkt/functor.rs b/core/src/hkt/functor.rs index 7011f9aa..721ea691 100644 --- a/core/src/hkt/functor.rs +++ b/core/src/hkt/functor.rs @@ -6,12 +6,8 @@ //! //! A functor is a type that when mapped over, preserves the structure of the type while applying a function to the values within the type. //! Functors are useful for modeling the functional effects on values of parameterized data types. +use super::containers::*; use super::HKT; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, rc::Rc, sync::Arc, vec::Vec}; - -#[cfg(feature = "std")] -use std::{rc::Rc, sync::Arc}; pub trait Functor: HKT { fn fmap(&self, f: F) -> Self::T @@ -37,6 +33,7 @@ macro_rules! functor { }; } +#[cfg(any(feature = "std", all(feature = "alloc", no_std)))] functor!(Arc, Box, Rc); impl Functor for Option { diff --git a/core/src/hkt/mod.rs b/core/src/hkt/mod.rs index 43fa24bf..30185cbb 100644 --- a/core/src/hkt/mod.rs +++ b/core/src/hkt/mod.rs @@ -11,11 +11,15 @@ pub mod applicative; pub mod functor; pub mod monad; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, rc::Rc, sync::Arc, vec::Vec}; +pub(crate) mod containers { + pub(crate) use core::option::Option; -#[cfg(feature = "std")] -use std::{rc::Rc, sync::Arc}; + #[cfg(all(feature = "alloc", no_std))] + pub(crate) use alloc::{boxed::Box, rc::Rc, sync::Arc, vec::Vec}; + + #[cfg(feature = "std")] + pub(crate) use std::{boxed::Box, rc::Rc, sync::Arc, vec::Vec}; +} pub trait HKT { type C; // Current Type @@ -37,7 +41,13 @@ macro_rules! hkt { }; } -hkt!(Arc, Box, core::option::Option, Rc, Vec); +hkt!( + containers::Arc, + containers::Box, + containers::Option, + containers::Rc, + containers::Vec +); pub(crate) mod prelude { pub use super::applicative::Applicative; diff --git a/core/src/hkt/monad.rs b/core/src/hkt/monad.rs index f78d05e2..95fe7523 100644 --- a/core/src/hkt/monad.rs +++ b/core/src/hkt/monad.rs @@ -5,11 +5,7 @@ use super::Applicative; use super::HKT; -#[cfg(not(feature = "std"))] -use alloc::{boxed::Box, rc::Rc, sync::Arc, vec::Vec}; - -#[cfg(feature = "std")] -use std::{rc::Rc, sync::Arc}; +use super::containers::*; pub trait Monad: Applicative { fn return_(x: U) -> Self::T diff --git a/core/src/traits/mod.rs b/core/src/traits/mod.rs index a25ed7f0..a0a7ce7d 100644 --- a/core/src/traits/mod.rs +++ b/core/src/traits/mod.rs @@ -39,5 +39,5 @@ pub(crate) mod prelude { pub use super::appellation::*; pub use super::classify::*; pub use super::ext::prelude::*; - pub use super::{Contain, Name}; + pub use super::{IntoInner, Name}; } diff --git a/scsys/Cargo.toml b/scsys/Cargo.toml index 8b3a6b4d..1d03a37e 100644 --- a/scsys/Cargo.toml +++ b/scsys/Cargo.toml @@ -95,12 +95,24 @@ required-features = ["derive"] [build-dependencies] -[dependencies] -scsys-core = { path = "../core", version = "0.2.2" } - -scsys-actors = { optional = true, path = "../actors", version = "0.2.2" } -scsys-derive = { optional = true, path = "../derive", version = "0.2.2" } -scsys-macros = { optional = true, path = "../macros", version = "0.2.2" } +[dependencies.scsys-actors] +optional = true +path = "../actors" +version = "0.2.2" + +[dependencies.scsys-core] +path = "../core" +version = "0.2.2" + +[dependencies.scsys-derive] +optional = true +path = "../derive" +version = "0.2.2" + +[dependencies.scsys-macros] +optional = true +path = "../macros" +version = "0.2.2" [dev-dependencies] serde = { features = ["derive"], version = "1" } diff --git a/scsys/benches/default.rs b/scsys/benches/default.rs index fae8377c..e405867e 100644 --- a/scsys/benches/default.rs +++ b/scsys/benches/default.rs @@ -2,7 +2,7 @@ Appellation: default Contrib: FL03 */ -#![cfg(bench)] +#![feature(test)] extern crate test; use test::Bencher; @@ -26,7 +26,7 @@ fn iterative_fibonacci(b: &mut Bencher) { pub mod fib { // recursive fibonacci - fn fibonacci(n: usize) -> u32 { + pub fn fibonacci(n: usize) -> u32 { if n < 2 { 1 } else { @@ -64,12 +64,11 @@ pub mod fib { type Item = u32; fn next(&mut self) -> Option { - use std::mem::replace; + use core::mem::replace; + let next = self.curr + self.next; + let curr = replace(&mut self.next, next); - let new_next = self.curr + self.next; - let new_curr = replace(&mut self.next, new_next); - - Some(replace(&mut self.curr, new_curr)) + Some(replace(&mut self.curr, curr)) } } } diff --git a/scsys/src/lib.rs b/scsys/src/lib.rs index 531a9023..df9cfcdd 100644 --- a/scsys/src/lib.rs +++ b/scsys/src/lib.rs @@ -4,7 +4,8 @@ */ //! # scsys //! -//! +//! Welcome to `scsys`, home to various primitives and utilities used throughout the [scsys](https://scattered-systems.com) ecosystem. +//! The sdk is heavily feature gated, reducing its footprint and allowing for a more modular approach to development. #[doc(inline)] pub use scsys_core::*; From 08a29d363a804eb08ced788cccf8f164a6741bdc Mon Sep 17 00:00:00 2001 From: Joe McCain III Date: Sat, 11 May 2024 15:06:00 -0500 Subject: [PATCH 10/10] update Signed-off-by: Joe McCain III --- .github/workflows/rust.yml | 20 +++++++------------- actors/src/states/mod.rs | 1 + actors/tests/states.rs | 0 3 files changed, 8 insertions(+), 13 deletions(-) create mode 100644 actors/tests/states.rs diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index a754a5fe..325eb456 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -42,29 +42,23 @@ jobs: target/release key: ${{ matrix.toolchain }}-${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} test: - name: Test + name: Test (workspace) needs: [ builder ] strategy: matrix: + flags: [ --no-default-features, --all-features ] toolchain: [ stable, nightly ] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: setup (langspace) - run: | - rustup update - rustup default ${{ matrix.toolchain }} - - name: Test - run: cargo test --all -F full --release -v + - run: rustup default ${{ matrix.toolchain }} && rustup update + - name: ${{ matrix.flags }} + run: cargo test ${{ matrix.flags }} -r -v --workspace bench: name: Benchmark needs: [ builder ] runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - - name: setup (langspace) - run: | - rustup update - rustup default nightly - - name: Bench - run: cargo bench --all -F full -v + - run: rustup default nightly && rustup update + - run: cargo bench --all-features -v --workspace diff --git a/actors/src/states/mod.rs b/actors/src/states/mod.rs index b4243d6f..07177d3c 100644 --- a/actors/src/states/mod.rs +++ b/actors/src/states/mod.rs @@ -41,6 +41,7 @@ mod tests { } #[test] + #[cfg(feature = "std")] fn test_states_iter() { let a: Vec = BinaryState::iter().collect(); assert_eq!(a.len(), 2); diff --git a/actors/tests/states.rs b/actors/tests/states.rs new file mode 100644 index 00000000..e69de29b