diff --git a/.rustfmt.toml b/.rustfmt.toml index 09ccb97..1900537 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -3,9 +3,5 @@ reorder_imports = true # nightly only -# unstable_features = true -# format_strings = false -# comment_width = 100 -# wrap_comments = true # group_imports = "StdExternalCrate" # imports_granularity = "Module" \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 5273a13..8a48f4b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,14 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "cgp" +version = "0.1.0" +dependencies = [ + "cgp-core", + "cgp-extra", +] + [[package]] name = "cgp-async" version = "0.1.0" @@ -54,7 +62,6 @@ dependencies = [ "cgp-error", "cgp-field", "cgp-inner", - "cgp-run", ] [[package]] @@ -80,6 +87,13 @@ dependencies = [ "cgp-core", ] +[[package]] +name = "cgp-extra" +version = "0.1.0" +dependencies = [ + "cgp-run", +] + [[package]] name = "cgp-field" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index ec19578..c1bbbba 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,9 @@ resolver = "2" members = [ + "crates/cgp", + "crates/cgp-core", + "crates/cgp-extra", "crates/cgp-async", "crates/cgp-async-macro", "crates/cgp-sync", @@ -15,20 +18,21 @@ members = [ "crates/cgp-error", "crates/cgp-error-eyre", "crates/cgp-error-std", - "crates/cgp-core", "crates/cgp-run", "crates/cgp-inner", ] [workspace.package] -rust-version = "1.75" +rust-version = "1.79" edition = "2021" license = "Apache-2.0" -repository = "https://github.com/informalsystems/cgp" +repository = "https://github.com/contextgeneric/cgp" authors = ["Informal Systems ", "Soares Chen "] [patch.crates-io] +cgp = { path = "./crates/cgp" } cgp-core = { path = "./crates/cgp-core" } +cgp-extra = { path = "./crates/cgp-extra" } cgp-async = { path = "./crates/cgp-async" } cgp-async-macro = { path = "./crates/cgp-async-macro" } cgp-sync = { path = "./crates/cgp-sync" } diff --git a/README.md b/README.md index e7b79b9..c2af8a2 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,37 @@ -# Context-generic programming \ No newline at end of file +# `cgp` - Context-Generic Programming Libraries in Rust + +[![Apache 2.0 Licensed](https://img.shields.io/badge/license-Apache_2.0-blue.svg)](https://github.com/informalsystems/cgp/blob/master/LICENSE) +![Rust Stable](https://img.shields.io/badge/rustc-stable-blue.svg) +![Rust 1.79+](https://img.shields.io/badge/rustc-1.79+-blue.svg) + +## Overview + +The `cgp` project contains a collection of micro Rust crates that empowers +_context-generic programming_ (CGP), a new programming paradigm in Rust. +To learn more about context-generic programming, check out the book +[Context-Generic Programming Patterns](https://patterns.contextgeneric.dev/). + +## Crates Organization + +The CGP core constructs are organized as many child crates that are intended +to be minimal and stable. Having each construct defined in separate crate +helps us avoid introducing breaking changes in semantic versioning, in case +an unrelated construct is updated. + +We also offers meta-crates that aggregate the dependencies from many CGP +child crates into one place, so that users can use CGP by specifying only one +dependency: + +- [`cgp`](./crates/cgp/) - The main crate that includes all child crates defined in this project. +- [`cgp-core`](./crates/cgp-core) - Meta crate that includes core CGP crates that +- [`cgp-extra`](./crates/cgp-extra) - Meta crate that includes additional CGP crates that may be non-essential or unstable. + +The following library crates are provided: + +- [`cgp-component`](./crates/cgp-component) - Defines the core CGP component traits and macros. +- [`cgp-async`](./crates/cgp-async/) - Defines the `Async` trait as an alias for async-safe types. +- [`cgp-error`](./crates/cgp-error/) - Defines the `HasErrorType` component and error handling constructs. +- [`cgp-field`](./crates/cgp-field/) - Defines the `HasField` trait to enable the use of data-generic programming with CGP. +- [`cgp-inner`](./crates/cgp-inner/) - Defines the `HasInner` component which enables composition-based implementation in CGP. +- [`cgp-run`](./crates/cgp-run) - Defines the `CanRun` component for implementing async runners. \ No newline at end of file diff --git a/crates/cgp-async-macro/Cargo.toml b/crates/cgp-async-macro/Cargo.toml index d54d6e5..c576792 100644 --- a/crates/cgp-async-macro/Cargo.toml +++ b/crates/cgp-async-macro/Cargo.toml @@ -6,15 +6,11 @@ repository = { workspace = true } authors = { workspace = true } rust-version = { workspace = true } version = "0.1.0" -readme = "README.md" keywords = ["context-generic programming"] description = """ - Context-generic programming core macros + Context-generic programming async macros """ -[package.metadata.docs.rs] -all-features = true - [lib] proc-macro = true diff --git a/crates/cgp-async-macro/src/lib.rs b/crates/cgp-async-macro/src/lib.rs index d0c8769..66d49f8 100644 --- a/crates/cgp-async-macro/src/lib.rs +++ b/crates/cgp-async-macro/src/lib.rs @@ -1,3 +1,7 @@ +/*! + This library provides helper macros for using async functions in traits. +*/ + extern crate proc_macro; use proc_macro::TokenStream; @@ -5,6 +9,11 @@ use proc_macro::TokenStream; mod impl_async; mod strip_async; +/** + This macro can be used in place of the [`macro@native_async`] macro + to strip away all use of `async` and `.await` syntax. This helps emulate + async-generic by turnining async functions into sync functions. +*/ #[proc_macro_attribute] pub fn strip_async(_attr: TokenStream, stream: TokenStream) -> TokenStream { strip_async::strip_async(stream.into()).into() diff --git a/crates/cgp-async/Cargo.toml b/crates/cgp-async/Cargo.toml index 2b47670..0caf26d 100644 --- a/crates/cgp-async/Cargo.toml +++ b/crates/cgp-async/Cargo.toml @@ -6,7 +6,6 @@ license = { workspace = true } repository = { workspace = true } authors = { workspace = true } rust-version = { workspace = true } -readme = "README.md" keywords = ["context-generic programming"] description = """ Async-generic primitives to support both sync/async in Context-generic programming diff --git a/crates/cgp-component-macro-lib/Cargo.toml b/crates/cgp-component-macro-lib/Cargo.toml index 3299e89..a07e57b 100644 --- a/crates/cgp-component-macro-lib/Cargo.toml +++ b/crates/cgp-component-macro-lib/Cargo.toml @@ -6,15 +6,11 @@ license = { workspace = true } repository = { workspace = true } authors = { workspace = true } rust-version = { workspace = true } -readme = "README.md" keywords = ["context-generic programming"] description = """ - Context-generic programming core macros + Context-generic programming core component macros implemented as a library. """ -[package.metadata.docs.rs] -all-features = true - [dependencies] syn = { version = "2.0.37", features = [ "full" ] } quote = "1.0.33" diff --git a/crates/cgp-component-macro-lib/src/lib.rs b/crates/cgp-component-macro-lib/src/lib.rs index 2a3d2bb..90a9735 100644 --- a/crates/cgp-component-macro-lib/src/lib.rs +++ b/crates/cgp-component-macro-lib/src/lib.rs @@ -1,3 +1,10 @@ +/*! + This is an internal crate used by the `cgp-component-macro` crate. We implement the + proc macros for `cgp-component` as a library, so that it can be more easily tested. + The constructs are then re-exported as proc macros in the `cgp-component-macro` crate, + which is defined as a proc macro crate. +*/ + pub mod delegate_components; pub mod derive_component; diff --git a/crates/cgp-component-macro/Cargo.toml b/crates/cgp-component-macro/Cargo.toml index 05694ab..16fcaad 100644 --- a/crates/cgp-component-macro/Cargo.toml +++ b/crates/cgp-component-macro/Cargo.toml @@ -6,15 +6,11 @@ license = { workspace = true } repository = { workspace = true } authors = { workspace = true } rust-version = { workspace = true } -readme = "README.md" keywords = ["context-generic programming"] description = """ - Context-generic programming core macros + Context-generic programming core component macros """ -[package.metadata.docs.rs] -all-features = true - [lib] proc-macro = true diff --git a/crates/cgp-component-macro/src/lib.rs b/crates/cgp-component-macro/src/lib.rs index 65e82f6..a1bef67 100644 --- a/crates/cgp-component-macro/src/lib.rs +++ b/crates/cgp-component-macro/src/lib.rs @@ -1,3 +1,7 @@ +/*! + This crate provides the proc macros used for defining CGP components. +*/ + extern crate proc_macro; use proc_macro::TokenStream; diff --git a/crates/cgp-component/Cargo.toml b/crates/cgp-component/Cargo.toml index f2d05b8..a43d028 100644 --- a/crates/cgp-component/Cargo.toml +++ b/crates/cgp-component/Cargo.toml @@ -6,15 +6,11 @@ license = { workspace = true } repository = { workspace = true } authors = { workspace = true } rust-version = { workspace = true } -readme = "README.md" keywords = ["context-generic programming"] description = """ - Context-generic programming core traits + Context-generic programming core component traits """ -[package.metadata.docs.rs] -all-features = true - [dependencies] cgp-async = { version = "0.1.0" } cgp-component-macro = { version = "0.1.0" } diff --git a/crates/cgp-component/src/lib.rs b/crates/cgp-component/src/lib.rs index ce732f2..abbcad0 100644 --- a/crates/cgp-component/src/lib.rs +++ b/crates/cgp-component/src/lib.rs @@ -1,5 +1,10 @@ #![no_std] +/*! + This crate defines the core CGP traits, [`DelegateComponent`] and [`HasComponents`]. + It also re-export component macros provided by [`cgp_component_macro`]. +*/ + pub mod traits; pub use cgp_component_macro::{define_components, delegate_components, derive_component}; diff --git a/crates/cgp-core/Cargo.toml b/crates/cgp-core/Cargo.toml index 7c36c52..11da0a0 100644 --- a/crates/cgp-core/Cargo.toml +++ b/crates/cgp-core/Cargo.toml @@ -6,19 +6,14 @@ license = { workspace = true } repository = { workspace = true } authors = { workspace = true } rust-version = { workspace = true } -readme = "README.md" keywords = ["context-generic programming"] description = """ Context-generic programming core traits """ -[package.metadata.docs.rs] -all-features = true - [dependencies] cgp-async = { version = "0.1.0" } cgp-component = { version = "0.1.0" } cgp-error = { version = "0.1.0" } cgp-field = { version = "0.1.0" } -cgp-run = { version = "0.1.0" } cgp-inner = { version = "0.1.0" } \ No newline at end of file diff --git a/crates/cgp-core/src/lib.rs b/crates/cgp-core/src/lib.rs index cd4fa23..fef9448 100644 --- a/crates/cgp-core/src/lib.rs +++ b/crates/cgp-core/src/lib.rs @@ -3,7 +3,7 @@ pub mod prelude; pub use cgp_async::{async_trait, Async}; -pub use { - cgp_component as component, cgp_error as error, cgp_field as field, cgp_inner as inner, - cgp_run as run, -}; +pub use cgp_component as component; +pub use cgp_error as error; +pub use cgp_field as field; +pub use cgp_inner as inner; diff --git a/crates/cgp-error-eyre/Cargo.toml b/crates/cgp-error-eyre/Cargo.toml index 35447da..4e9a2cb 100644 --- a/crates/cgp-error-eyre/Cargo.toml +++ b/crates/cgp-error-eyre/Cargo.toml @@ -6,10 +6,9 @@ license = { workspace = true } repository = { workspace = true } authors = { workspace = true } rust-version = { workspace = true } -readme = "README.md" keywords = ["context-generic programming"] description = """ - Context-generic programming core traits + Context-generic programming error handlers implemented using eyre """ [dependencies] diff --git a/crates/cgp-error-std/Cargo.toml b/crates/cgp-error-std/Cargo.toml index e284ac0..d024031 100644 --- a/crates/cgp-error-std/Cargo.toml +++ b/crates/cgp-error-std/Cargo.toml @@ -6,10 +6,9 @@ license = { workspace = true } repository = { workspace = true } authors = { workspace = true } rust-version = { workspace = true } -readme = "README.md" keywords = ["context-generic programming"] description = """ - Context-generic programming core traits + Context-generic programming error handlers implemented using `std::error::Error` """ [dependencies] diff --git a/crates/cgp-error/Cargo.toml b/crates/cgp-error/Cargo.toml index 2d8d5b2..383b46b 100644 --- a/crates/cgp-error/Cargo.toml +++ b/crates/cgp-error/Cargo.toml @@ -6,10 +6,9 @@ license = { workspace = true } repository = { workspace = true } authors = { workspace = true } rust-version = { workspace = true } -readme = "README.md" keywords = ["context-generic programming"] description = """ - Context-generic programming core traits + Context-generic programming error components """ [dependencies] diff --git a/crates/cgp-extra/Cargo.toml b/crates/cgp-extra/Cargo.toml new file mode 100644 index 0000000..6b55c2b --- /dev/null +++ b/crates/cgp-extra/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "cgp-extra" +version = "0.1.0" +edition = { workspace = true } +license = { workspace = true } +repository = { workspace = true } +authors = { workspace = true } +rust-version = { workspace = true } +keywords = ["context-generic programming"] +description = """ + Context-generic programming extra meta-crate +""" + +[dependencies] +cgp-run = { version = "0.1.0" } diff --git a/crates/cgp-extra/src/lib.rs b/crates/cgp-extra/src/lib.rs new file mode 100644 index 0000000..d3f186b --- /dev/null +++ b/crates/cgp-extra/src/lib.rs @@ -0,0 +1 @@ +pub use cgp_run as run; diff --git a/crates/cgp-field-macro-lib/Cargo.toml b/crates/cgp-field-macro-lib/Cargo.toml index e0fc317..0ee0e34 100644 --- a/crates/cgp-field-macro-lib/Cargo.toml +++ b/crates/cgp-field-macro-lib/Cargo.toml @@ -6,15 +6,11 @@ license = { workspace = true } repository = { workspace = true } authors = { workspace = true } rust-version = { workspace = true } -readme = "README.md" keywords = ["context-generic programming"] description = """ - Context-generic programming core macros + Context-generic programming field macros as a library """ -[package.metadata.docs.rs] -all-features = true - [dependencies] syn = { version = "2.0.37", features = [ "full" ] } quote = "1.0.33" diff --git a/crates/cgp-field-macro-lib/src/lib.rs b/crates/cgp-field-macro-lib/src/lib.rs index 1439e39..8a4e1cf 100644 --- a/crates/cgp-field-macro-lib/src/lib.rs +++ b/crates/cgp-field-macro-lib/src/lib.rs @@ -1,3 +1,10 @@ +/*! + This is an internal crate used by the `cgp-field-macro` crate. We implement the + proc macros for `cgp-field` as a library, so that it can be more easily tested. + The constructs are then re-exported as proc macros in the `cgp-field-macro` crate, + which is defined as a proc macro crate. +*/ + pub mod field; pub mod symbol; diff --git a/crates/cgp-field-macro/Cargo.toml b/crates/cgp-field-macro/Cargo.toml index 100b0c8..2a045bc 100644 --- a/crates/cgp-field-macro/Cargo.toml +++ b/crates/cgp-field-macro/Cargo.toml @@ -6,15 +6,11 @@ license = { workspace = true } repository = { workspace = true } authors = { workspace = true } rust-version = { workspace = true } -readme = "README.md" keywords = ["context-generic programming"] description = """ - Context-generic programming core macros + Context-generic programming field macros """ -[package.metadata.docs.rs] -all-features = true - [lib] proc-macro = true diff --git a/crates/cgp-field/Cargo.toml b/crates/cgp-field/Cargo.toml index ff88a44..0dea869 100644 --- a/crates/cgp-field/Cargo.toml +++ b/crates/cgp-field/Cargo.toml @@ -6,14 +6,10 @@ license = { workspace = true } repository = { workspace = true } authors = { workspace = true } rust-version = { workspace = true } -readme = "README.md" keywords = ["context-generic programming"] description = """ - Context-generic programming core traits + Context-generic programming field traits """ -[package.metadata.docs.rs] -all-features = true - [dependencies] cgp-field-macro = { version = "0.1.0" } diff --git a/crates/cgp-inner/Cargo.toml b/crates/cgp-inner/Cargo.toml index 4f7fe7a..93e362a 100644 --- a/crates/cgp-inner/Cargo.toml +++ b/crates/cgp-inner/Cargo.toml @@ -6,15 +6,11 @@ license = { workspace = true } repository = { workspace = true } authors = { workspace = true } rust-version = { workspace = true } -readme = "README.md" keywords = ["context-generic programming"] description = """ - Context-generic programming core traits + Context-generic programming inner component """ -[package.metadata.docs.rs] -all-features = true - [dependencies] cgp-async = { version = "0.1.0" } cgp-component = { version = "0.1.0" } \ No newline at end of file diff --git a/crates/cgp-run/Cargo.toml b/crates/cgp-run/Cargo.toml index 861cda9..83b8dc2 100644 --- a/crates/cgp-run/Cargo.toml +++ b/crates/cgp-run/Cargo.toml @@ -6,15 +6,11 @@ license = { workspace = true } repository = { workspace = true } authors = { workspace = true } rust-version = { workspace = true } -readme = "README.md" keywords = ["context-generic programming"] description = """ - Context-generic programming core traits + Context-generic programming runner component """ -[package.metadata.docs.rs] -all-features = true - [dependencies] cgp-async = { version = "0.1.0" } cgp-error = { version = "0.1.0" } diff --git a/crates/cgp-sync/Cargo.toml b/crates/cgp-sync/Cargo.toml index dcc777e..d98c954 100644 --- a/crates/cgp-sync/Cargo.toml +++ b/crates/cgp-sync/Cargo.toml @@ -6,7 +6,6 @@ license = { workspace = true } repository = { workspace = true } authors = { workspace = true } rust-version = { workspace = true } -readme = "README.md" keywords = ["context-generic programming"] description = """ Async-generic primitives to support both sync/async in Context-generic programming diff --git a/crates/cgp/Cargo.toml b/crates/cgp/Cargo.toml new file mode 100644 index 0000000..8a4c07e --- /dev/null +++ b/crates/cgp/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "cgp" +version = "0.1.0" +edition = { workspace = true } +license = { workspace = true } +repository = { workspace = true } +authors = { workspace = true } +rust-version = { workspace = true } +keywords = ["context-generic programming"] +description = """ + Context-generic programming meta crate +""" + +[dependencies] +cgp-core = { version = "0.1.0" } +cgp-extra = { version = "0.1.0" } \ No newline at end of file diff --git a/crates/cgp/src/lib.rs b/crates/cgp/src/lib.rs new file mode 100644 index 0000000..f57f97a --- /dev/null +++ b/crates/cgp/src/lib.rs @@ -0,0 +1,3 @@ +pub use cgp_core as core; +pub use cgp_core::prelude; +pub use cgp_extra as extra; diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..39235a1 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "1.79" +profile = "default"