From 55ee30b60d2cf8bbb71726d48d36b7055d4f7069 Mon Sep 17 00:00:00 2001 From: Soares Chen Date: Mon, 16 Nov 2026 23:16:40 +0100 Subject: [PATCH 1/4] Show each main crate's construct in its README and make it the crate doc The READMEs of the 14 crates a reader may land on directly (the core and extra layers, their component crates, and the macro crates) now open with what CGP is, show a short program using the crate's main construct through the cgp crate, and keep the reference-page links their lib.rs docs listed. Each README is now its crate's documentation through include_str!, so docs.rs and crates.io show one text. The examples are marked rust,ignore, as the error backends' are: each uses the cgp crate, which the crate itself cannot depend on. Each example compiled and ran against this tree before the change. Co-Authored-By: Claude Opus 5.5 --- crates/core/cgp-base-types/README.md | 41 +++++++++++--- crates/core/cgp-base-types/src/lib.rs | 4 +- crates/core/cgp-component/README.md | 54 +++++++++++++++--- crates/core/cgp-component/src/lib.rs | 5 +- crates/core/cgp-error/README.md | 49 +++++++++++++--- crates/core/cgp-error/src/lib.rs | 4 +- crates/core/cgp-field/README.md | 41 +++++++++++--- crates/core/cgp-field/src/lib.rs | 5 +- crates/core/cgp-type/README.md | 38 ++++++++++--- crates/core/cgp-type/src/lib.rs | 4 +- crates/extra/cgp-dispatch/README.md | 72 +++++++++++++++++++++--- crates/extra/cgp-dispatch/src/lib.rs | 5 +- crates/extra/cgp-error-extra/README.md | 56 +++++++++++++++--- crates/extra/cgp-error-extra/src/lib.rs | 6 +- crates/extra/cgp-field-extra/README.md | 46 ++++++++++++--- crates/extra/cgp-field-extra/src/lib.rs | 4 +- crates/extra/cgp-handler/README.md | 45 ++++++++++++--- crates/extra/cgp-handler/src/lib.rs | 5 +- crates/macros/cgp-async-macro/README.md | 39 ++++++++++--- crates/macros/cgp-async-macro/src/lib.rs | 5 +- crates/macros/cgp-macro-extra/README.md | 60 +++++++++++++++++--- crates/macros/cgp-macro-extra/src/lib.rs | 5 +- crates/macros/cgp-macro/README.md | 51 ++++++++++++++--- crates/macros/cgp-macro/src/lib.rs | 5 +- crates/main/cgp-core/README.md | 41 +++++++++++--- crates/main/cgp-core/src/lib.rs | 5 +- crates/main/cgp-extra/README.md | 55 +++++++++++++++--- crates/main/cgp-extra/src/lib.rs | 6 +- 28 files changed, 593 insertions(+), 163 deletions(-) diff --git a/crates/core/cgp-base-types/README.md b/crates/core/cgp-base-types/README.md index e3231a17..8e080d16 100644 --- a/crates/core/cgp-base-types/README.md +++ b/crates/core/cgp-base-types/README.md @@ -1,13 +1,38 @@ # cgp-base-types -`cgp-base-types` provides the type-level primitives of Context-Generic Programming (CGP): the +[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait +implementations, chosen at compile time. `cgp-base-types` provides CGP's type-level primitives: the symbols that name fields, the lists and sums that describe a type's fields and variants, and the -paths that namespaces route along. +paths that namespaces route along. A `Product!` list, for example, is a chain of `Cons` cells closed +by `Nil`: -The `cgp` crate re-exports these types under `cgp::core::base`, and the macros that build them, such -as `Symbol!` and `Product!`, under `cgp::prelude`. Most projects therefore depend on -[`cgp`](https://crates.io/crates/cgp) alone, without adding this crate to their manifest. +```rust,ignore +use cgp::core::field::types::{Cons, Nil}; +use cgp::prelude::*; -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +// `Product![u8, String]` is the list `Cons>`. +fn as_cells(list: Product![u8, String]) -> Cons> { + list +} + +fn main() { + let Cons(first, Cons(second, Nil)) = as_cells(product![1, "one".to_owned()]); + assert_eq!((first, second.as_str()), (1, "one")); +} +``` + +Its main items are [`Symbol!`](https://contextgeneric.dev/docs/reference/macros/symbol), +[`Cons`](https://contextgeneric.dev/docs/reference/types/cons), +[`Nil`](https://contextgeneric.dev/docs/reference/types/nil), +[`Chars`](https://contextgeneric.dev/docs/reference/types/chars), +[`PathCons`](https://contextgeneric.dev/docs/reference/types/path_cons), +[`StaticFormat`](https://contextgeneric.dev/docs/reference/traits/formatting/static_format), and +[`ConcatPath`](https://contextgeneric.dev/docs/reference/traits/formatting/concat_path), each linked +to its reference page on the website. + +The `cgp` crate re-exports these types under `cgp::core::base`, and the macros that build them under +`cgp::prelude`, so a project depends on [`cgp`](https://crates.io/crates/cgp) alone, as the example +does. + +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. diff --git a/crates/core/cgp-base-types/src/lib.rs b/crates/core/cgp-base-types/src/lib.rs index 25df6979..72930919 100644 --- a/crates/core/cgp-base-types/src/lib.rs +++ b/crates/core/cgp-base-types/src/lib.rs @@ -1,6 +1,4 @@ -//! This crate provides CGP's type-level primitives: symbols, lists, sums, and paths. -//! -//! See [`Symbol!`](https://contextgeneric.dev/docs/reference/macros/symbol), [`Cons`](https://contextgeneric.dev/docs/reference/types/cons), [`Nil`](https://contextgeneric.dev/docs/reference/types/nil), [`Chars`](https://contextgeneric.dev/docs/reference/types/chars), [`PathCons`](https://contextgeneric.dev/docs/reference/types/path_cons), [`StaticFormat`](https://contextgeneric.dev/docs/reference/traits/formatting/static_format), and [`ConcatPath`](https://contextgeneric.dev/docs/reference/traits/formatting/concat_path). +#![doc = include_str!("../README.md")] #![no_std] #![warn(missing_docs)] diff --git a/crates/core/cgp-component/README.md b/crates/core/cgp-component/README.md index 48184bfe..129625e6 100644 --- a/crates/core/cgp-component/README.md +++ b/crates/core/cgp-component/README.md @@ -1,12 +1,50 @@ # cgp-component -`cgp-component` provides the component machinery of Context-Generic Programming (CGP): the -delegation traits that let a context choose a provider for each component, the lookup that finds -that provider, and the providers CGP ships with. +[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait +implementations, chosen at compile time. `cgp-component` provides CGP's component machinery: the +delegation traits that let a context choose a provider for each component, the lookup that finds it, +and the providers CGP ships with. Wiring a context writes a type-level table, which the lookup +reads: -The `cgp` crate re-exports it as `cgp::core::component`. Most projects therefore depend on -[`cgp`](https://crates.io/crates/cgp) alone, without adding this crate to their manifest. +```rust,ignore +use cgp::core::component::DelegateComponent; +use cgp::prelude::*; -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +#[cgp_component(Greeter)] +pub trait CanGreet { + fn greet(&self) -> String; +} + +#[cgp_impl(new GreetHello)] +impl Greeter { + fn greet(&self) -> String { + "Hello!".to_owned() + } +} + +pub struct Person; + +delegate_components! { Person { GreeterComponent: GreetHello } } + +fn main() { + // The wiring is a type-level table: this entry names `GreetHello`. + let _provider: >::Delegate = GreetHello; + assert_eq!(Person.greet(), "Hello!"); +} +``` + +Its main items are +[`DelegateComponent`](https://contextgeneric.dev/docs/reference/traits/wiring/delegate_component), +[`IsProviderFor`](https://contextgeneric.dev/docs/reference/traits/wiring/is_provider_for), +[`CanUseComponent`](https://contextgeneric.dev/docs/reference/traits/wiring/can_use_component), +[`UseContext`](https://contextgeneric.dev/docs/reference/providers/use_context), +[`UseDefault`](https://contextgeneric.dev/docs/reference/providers/use_default), +[`UseDelegate`](https://contextgeneric.dev/docs/reference/providers/use_delegate), and +[`RedirectLookup`](https://contextgeneric.dev/docs/reference/providers/redirect_lookup), each linked +to its reference page on the website. + +The `cgp` crate re-exports it as `cgp::core::component`, so a project depends on +[`cgp`](https://crates.io/crates/cgp) alone, as the example does. + +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. diff --git a/crates/core/cgp-component/src/lib.rs b/crates/core/cgp-component/src/lib.rs index 21743b0c..2cce7a8e 100644 --- a/crates/core/cgp-component/src/lib.rs +++ b/crates/core/cgp-component/src/lib.rs @@ -1,8 +1,5 @@ +#![doc = include_str!("../README.md")] #![no_std] -//! This crate provides CGP's component machinery: delegation, provider lookup, and the built-in -//! providers. -//! -//! See [`DelegateComponent`](https://contextgeneric.dev/docs/reference/traits/wiring/delegate_component), [`IsProviderFor`](https://contextgeneric.dev/docs/reference/traits/wiring/is_provider_for), [`CanUseComponent`](https://contextgeneric.dev/docs/reference/traits/wiring/can_use_component), [`UseContext`](https://contextgeneric.dev/docs/reference/providers/use_context), [`UseDefault`](https://contextgeneric.dev/docs/reference/providers/use_default), [`UseDelegate`](https://contextgeneric.dev/docs/reference/providers/use_delegate), and [`RedirectLookup`](https://contextgeneric.dev/docs/reference/providers/redirect_lookup). #![warn(missing_docs)] /// Re-exports the component machinery that the macros expand to. diff --git a/crates/core/cgp-error/README.md b/crates/core/cgp-error/README.md index 515e5068..0b15dd50 100644 --- a/crates/core/cgp-error/README.md +++ b/crates/core/cgp-error/README.md @@ -1,12 +1,47 @@ # cgp-error -`cgp-error` provides the error components of Context-Generic Programming (CGP): an error type that +[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait +implementations, chosen at compile time. `cgp-error` provides CGP's error components: an error type each context chooses, and the components that raise errors into it and wrap them with detail. +Generic code raises an error without knowing its type, and each context decides what it becomes: -The `cgp` crate re-exports it as `cgp::core::error`, and its traits `HasErrorType`, `CanRaiseError`, -and `CanWrapError` under `cgp::prelude`. Most projects therefore depend on -[`cgp`](https://crates.io/crates/cgp) alone, without adding this crate to their manifest. +```rust,ignore +use cgp::core::error::{ErrorRaiserComponent, ErrorTypeProviderComponent}; +use cgp::extra::error::RaiseFrom; +use cgp::prelude::*; -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +pub fn parse_port(input: &str) -> Result +where + Context: CanRaiseError, +{ + input.parse().map_err(|_| Context::raise_error(format!("not a port: {input}"))) +} + +pub struct App; + +delegate_components! { + App { + open ErrorRaiserComponent; + + ErrorTypeProviderComponent: UseType, + @ErrorRaiserComponent.String: RaiseFrom, + } +} + +fn main() { + assert_eq!(parse_port::("80"), Ok(80)); + assert_eq!(parse_port::("http"), Err("not a port: http".to_owned())); +} +``` + +Its main items are +[`HasErrorType`](https://contextgeneric.dev/docs/reference/components/has_error_type), +[`CanRaiseError`](https://contextgeneric.dev/docs/reference/components/can_raise_error), and +[`CanWrapError`](https://contextgeneric.dev/docs/reference/components/can_wrap_error), each linked +to its reference page on the website. + +The `cgp` crate re-exports it as `cgp::core::error`, so a project depends on +[`cgp`](https://crates.io/crates/cgp) alone, as the example does. + +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. diff --git a/crates/core/cgp-error/src/lib.rs b/crates/core/cgp-error/src/lib.rs index 7304fd50..f866138d 100644 --- a/crates/core/cgp-error/src/lib.rs +++ b/crates/core/cgp-error/src/lib.rs @@ -1,7 +1,5 @@ +#![doc = include_str!("../README.md")] #![no_std] -//! This crate provides CGP's error components: the abstract error type, raising, and wrapping. -//! -//! See [`HasErrorType`](https://contextgeneric.dev/docs/reference/components/has_error_type), [`CanRaiseError`](https://contextgeneric.dev/docs/reference/components/can_raise_error), and [`CanWrapError`](https://contextgeneric.dev/docs/reference/components/can_wrap_error). #![warn(missing_docs)] mod contexts; diff --git a/crates/core/cgp-field/README.md b/crates/core/cgp-field/README.md index cce45538..bb365b88 100644 --- a/crates/core/cgp-field/README.md +++ b/crates/core/cgp-field/README.md @@ -1,13 +1,36 @@ # cgp-field -`cgp-field` provides the field access of Context-Generic Programming (CGP): the traits that read and -build a type's fields by name, the tags that name them, and the structural casts between records and -between enums. +[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait +implementations, chosen at compile time. `cgp-field` provides CGP's field access: the traits that +read and build a type's fields by name, the tags that name them, and the structural casts between +records and between enums. `#[derive(HasField)]` gives each field a tag, and the field can then be +read by name: -The `cgp` crate re-exports it as `cgp::core::field`, and the derives that implement its traits under -`cgp::prelude`. Most projects therefore depend on [`cgp`](https://crates.io/crates/cgp) alone, -without adding this crate to their manifest. +```rust,ignore +use cgp::core::field::traits::HasField; +use cgp::prelude::*; -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +#[derive(HasField)] +pub struct Person { + pub name: String, + pub age: u8, +} + +fn main() { + let person = Person { name: "Alice".to_owned(), age: 30 }; + assert_eq!(person.get_field(PhantomData::), &30); +} +``` + +Its main items are +[`HasField`](https://contextgeneric.dev/docs/reference/traits/field-access/has_field), +[`Index`](https://contextgeneric.dev/docs/reference/types/index_type), +[`MRef`](https://contextgeneric.dev/docs/reference/types/mref), and the +[casts](https://contextgeneric.dev/docs/reference/traits/casting/), each linked to its reference +page on the website. + +The `cgp` crate re-exports it as `cgp::core::field`, so a project depends on +[`cgp`](https://crates.io/crates/cgp) alone, as the example does. + +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. diff --git a/crates/core/cgp-field/src/lib.rs b/crates/core/cgp-field/src/lib.rs index 7e3dad28..cd65b4ec 100644 --- a/crates/core/cgp-field/src/lib.rs +++ b/crates/core/cgp-field/src/lib.rs @@ -1,8 +1,5 @@ +#![doc = include_str!("../README.md")] #![no_std] -//! This crate provides CGP's field access: the field traits, the field tags, the type-level lists, -//! and the structural casts. -//! -//! See [`HasField`](https://contextgeneric.dev/docs/reference/traits/field-access/has_field), [`Index`](https://contextgeneric.dev/docs/reference/types/index_type), [`MRef`](https://contextgeneric.dev/docs/reference/types/mref), and the [casts](https://contextgeneric.dev/docs/reference/traits/casting/). #![warn(missing_docs)] /// The field traits' implementations and the built-in providers. diff --git a/crates/core/cgp-type/README.md b/crates/core/cgp-type/README.md index e5c6eee0..aa83f367 100644 --- a/crates/core/cgp-type/README.md +++ b/crates/core/cgp-type/README.md @@ -1,11 +1,35 @@ # cgp-type -`cgp-type` provides the abstract types of Context-Generic Programming (CGP), which let each context -choose a type that generic code names only through a trait. +[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait +implementations, chosen at compile time. `cgp-type` provides CGP's abstract types, which let each +context choose a type that generic code names only through a trait. A context picks its type in its +wiring: -The `cgp` crate re-exports it as `cgp::core::types`. Most projects therefore depend on -[`cgp`](https://crates.io/crates/cgp) alone, without adding this crate to their manifest. +```rust,ignore +use cgp::prelude::*; -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +#[cgp_type] +pub trait HasNameType { + type Name; +} + +pub struct App; + +delegate_components! { App { NameTypeProviderComponent: UseType } } + +fn main() { + let name: ::Name = String::from("app"); + assert_eq!(name, "app"); +} +``` + +Its main items are [`HasType`](https://contextgeneric.dev/docs/reference/components/has_type), +[`UseType`](https://contextgeneric.dev/docs/reference/providers/use_type), and +[`UseDelegatedType`](https://contextgeneric.dev/docs/reference/providers/use_delegated_type), each +linked to its reference page on the website. + +The `cgp` crate re-exports it as `cgp::core::types`, so a project depends on +[`cgp`](https://crates.io/crates/cgp) alone, as the example does. + +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. diff --git a/crates/core/cgp-type/src/lib.rs b/crates/core/cgp-type/src/lib.rs index fd135862..f7e8080e 100644 --- a/crates/core/cgp-type/src/lib.rs +++ b/crates/core/cgp-type/src/lib.rs @@ -1,7 +1,5 @@ +#![doc = include_str!("../README.md")] #![no_std] -//! This crate provides CGP's abstract types: a type the context chooses behind a trait. -//! -//! See [`HasType`](https://contextgeneric.dev/docs/reference/components/has_type), [`UseType`](https://contextgeneric.dev/docs/reference/providers/use_type), and [`UseDelegatedType`](https://contextgeneric.dev/docs/reference/providers/use_delegated_type). #![warn(missing_docs)] mod impls; diff --git a/crates/extra/cgp-dispatch/README.md b/crates/extra/cgp-dispatch/README.md index 8b915ad7..7d6b587d 100644 --- a/crates/extra/cgp-dispatch/README.md +++ b/crates/extra/cgp-dispatch/README.md @@ -1,12 +1,68 @@ # cgp-dispatch -`cgp-dispatch` provides the dispatch combinators of Context-Generic Programming (CGP), which split a -value between handlers. They match an enum's variants or extract a record's fields and pass each one -to its own handler, or build a record from what the handlers return. +[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait +implementations, chosen at compile time. `cgp-dispatch` provides CGP's dispatch combinators, which +split a value between handlers: they match an enum's variants or extract a record's fields and pass +each one to its own handler, or build a record from what the handlers return. Here each variant of +an enum gets its own area computation: -The `cgp` crate re-exports it as `cgp::extra::dispatch`. Most projects therefore depend on -[`cgp`](https://crates.io/crates/cgp) alone, without adding this crate to their manifest. +```rust,ignore +use cgp::extra::dispatch::MatchWithValueHandlers; +use cgp::extra::handler::{CanCompute, Computer, ComputerComponent}; +use cgp::prelude::*; -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +pub struct Circle { + pub radius: f64, +} + +pub struct Rectangle { + pub width: f64, + pub height: f64, +} + +#[derive(CgpData)] +pub enum Shape { + Circle(Circle), + Rectangle(Rectangle), +} + +#[cgp_new_provider] +impl Computer for ComputeArea { + type Output = f64; + + fn compute(_context: &Context, _code: PhantomData, circle: Circle) -> f64 { + 3.0 * circle.radius * circle.radius + } +} + +#[cgp_provider] +impl Computer for ComputeArea { + type Output = f64; + + fn compute(_context: &Context, _code: PhantomData, rectangle: Rectangle) -> f64 { + rectangle.width * rectangle.height + } +} + +pub struct App; + +delegate_components! { App { ComputerComponent: MatchWithValueHandlers } } + +fn main() { + let shape = Shape::Rectangle(Rectangle { width: 2.0, height: 3.0 }); + assert_eq!(App.compute(PhantomData::<()>, shape), 6.0); +} +``` + +Its main items are +[`MatchWithHandlers`](https://contextgeneric.dev/docs/reference/providers/dispatch/match_with_handlers), +[`MatchWithValueHandlers`](https://contextgeneric.dev/docs/reference/providers/dispatch/match_with_value_handlers), +and +[`ExtractFieldAndHandle`](https://contextgeneric.dev/docs/reference/providers/dispatch/extract_field_and_handle), +each linked to its reference page on the website. + +The `cgp` crate re-exports it as `cgp::extra::dispatch`, so a project depends on +[`cgp`](https://crates.io/crates/cgp) alone, as the example does. + +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. diff --git a/crates/extra/cgp-dispatch/src/lib.rs b/crates/extra/cgp-dispatch/src/lib.rs index 7db2541e..18f84dd8 100644 --- a/crates/extra/cgp-dispatch/src/lib.rs +++ b/crates/extra/cgp-dispatch/src/lib.rs @@ -1,9 +1,6 @@ +#![doc = include_str!("../README.md")] #![no_std] #![allow(clippy::needless_lifetimes)] -//! This crate provides CGP's dispatch providers, which match, extract, and build a value on the way -//! to a handler. -//! -//! See [`MatchWithHandlers`](https://contextgeneric.dev/docs/reference/providers/dispatch/match_with_handlers), [`MatchWithValueHandlers`](https://contextgeneric.dev/docs/reference/providers/dispatch/match_with_value_handlers), and [`ExtractFieldAndHandle`](https://contextgeneric.dev/docs/reference/providers/dispatch/extract_field_and_handle). #![warn(missing_docs)] mod providers; diff --git a/crates/extra/cgp-error-extra/README.md b/crates/extra/cgp-error-extra/README.md index 7dc8d03a..e7e5878e 100644 --- a/crates/extra/cgp-error-extra/README.md +++ b/crates/extra/cgp-error-extra/README.md @@ -1,13 +1,51 @@ # cgp-error-extra -`cgp-error-extra` provides the generic error providers of Context-Generic Programming (CGP), which -raise an error by conversion, return it unchanged, discard a detail, or format it into a message. -The `DebugError` and `DisplayError` providers need an allocator, so they sit behind the `alloc` -feature. +[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait +implementations, chosen at compile time. `cgp-error-extra` provides CGP's generic error providers, +which raise an error by conversion, return it unchanged, discard a detail, or format it into a +message. A context routes each source error to one of them: -The `cgp` crate re-exports it as `cgp::extra::error`. Most projects therefore depend on -[`cgp`](https://crates.io/crates/cgp) alone, without adding this crate to their manifest. +```rust,ignore +use core::num::ParseIntError; -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +use cgp::core::error::{ErrorRaiserComponent, ErrorTypeProviderComponent}; +use cgp::extra::error::{DebugError, RaiseFrom}; +use cgp::prelude::*; + +pub struct App; + +delegate_components! { + App { + open ErrorRaiserComponent; + + ErrorTypeProviderComponent: UseType, + @ErrorRaiserComponent.String: RaiseFrom, + @ErrorRaiserComponent.ParseIntError: DebugError, + } +} + +fn main() { + let error = "http".parse::().map_err(App::raise_error).unwrap_err(); + assert!(error.contains("InvalidDigit")); +} +``` + +`DebugError` and `DisplayError` format an error into a `String`, so they need an allocator and the +`alloc` feature, which this example turns on with +`cgp = { version = "0.8.0", features = ["alloc"] }`. + +Its main items are +[`RaiseFrom`](https://contextgeneric.dev/docs/reference/providers/error/raise_from), +[`ReturnError`](https://contextgeneric.dev/docs/reference/providers/error/return_error), +[`RaiseInfallible`](https://contextgeneric.dev/docs/reference/providers/error/raise_infallible), +[`PanicOnError`](https://contextgeneric.dev/docs/reference/providers/error/panic_on_error), +[`DiscardDetail`](https://contextgeneric.dev/docs/reference/providers/error/discard_detail), +[`DebugError`](https://contextgeneric.dev/docs/reference/providers/error/debug_error), and +[`DisplayError`](https://contextgeneric.dev/docs/reference/providers/error/display_error), each +linked to its reference page on the website. + +The `cgp` crate re-exports it as `cgp::extra::error`, so a project depends on +[`cgp`](https://crates.io/crates/cgp) alone, as the example does. + +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. diff --git a/crates/extra/cgp-error-extra/src/lib.rs b/crates/extra/cgp-error-extra/src/lib.rs index 1c05b414..e4605570 100644 --- a/crates/extra/cgp-error-extra/src/lib.rs +++ b/crates/extra/cgp-error-extra/src/lib.rs @@ -1,9 +1,5 @@ +#![doc = include_str!("../README.md")] #![no_std] -//! This crate provides CGP's generic error providers, which raise, return, discard, and format an -//! error. The `DebugError` and `DisplayError` providers need an allocator, so they are behind the -//! `alloc` feature. -//! -//! See [`RaiseFrom`](https://contextgeneric.dev/docs/reference/providers/error/raise_from), [`ReturnError`](https://contextgeneric.dev/docs/reference/providers/error/return_error), [`RaiseInfallible`](https://contextgeneric.dev/docs/reference/providers/error/raise_infallible), [`PanicOnError`](https://contextgeneric.dev/docs/reference/providers/error/panic_on_error), [`DiscardDetail`](https://contextgeneric.dev/docs/reference/providers/error/discard_detail), [`DebugError`](https://contextgeneric.dev/docs/reference/providers/error/debug_error), and [`DisplayError`](https://contextgeneric.dev/docs/reference/providers/error/display_error). #![warn(missing_docs)] #[cfg(feature = "alloc")] diff --git a/crates/extra/cgp-field-extra/README.md b/crates/extra/cgp-field-extra/README.md index 0bb4645d..43b7919e 100644 --- a/crates/extra/cgp-field-extra/README.md +++ b/crates/extra/cgp-field-extra/README.md @@ -1,12 +1,42 @@ # cgp-field-extra -`cgp-field-extra` provides the optional-field layer of Context-Generic Programming (CGP), which -builds a value from fields set in any order. The builder finishes once every field is set, or fills -the missing ones from their defaults. +[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait +implementations, chosen at compile time. `cgp-field-extra` provides CGP's optional-field layer, +which builds a value from fields set in any order, then finishes once every field is set, or fills +the missing ones from their defaults. A record can be widened into a larger one this way: -The `cgp` crate re-exports it as `cgp::extra::field`. Most projects therefore depend on -[`cgp`](https://crates.io/crates/cgp) alone, without adding this crate to their manifest. +```rust,ignore +use cgp::extra::field::impls::CanBuildWithDefault; +use cgp::prelude::*; -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +#[derive(Debug, PartialEq, CgpData)] +pub struct Point2d { + pub x: u64, + pub y: u64, +} + +#[derive(Debug, PartialEq, CgpData)] +pub struct Point3d { + pub x: u64, + pub y: u64, + pub z: u64, +} + +fn main() { + let point = Point3d::build_with_default(Point2d { x: 1, y: 2 }); + assert_eq!(point, Point3d { x: 1, y: 2, z: 0 }); +} +``` + +Its main items are +[`HasOptionalBuilder`](https://contextgeneric.dev/docs/reference/traits/optional/has_optional_builder), +[`ToOptional`](https://contextgeneric.dev/docs/reference/traits/optional/to_optional), +[`SetOptional`](https://contextgeneric.dev/docs/reference/traits/optional/set_optional), and +[`FinalizeOptional`](https://contextgeneric.dev/docs/reference/traits/optional/finalize_optional), +each linked to its reference page on the website. + +The `cgp` crate re-exports it as `cgp::extra::field`, so a project depends on +[`cgp`](https://crates.io/crates/cgp) alone, as the example does. + +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. diff --git a/crates/extra/cgp-field-extra/src/lib.rs b/crates/extra/cgp-field-extra/src/lib.rs index dcf6604a..69c01d90 100644 --- a/crates/extra/cgp-field-extra/src/lib.rs +++ b/crates/extra/cgp-field-extra/src/lib.rs @@ -1,7 +1,5 @@ +#![doc = include_str!("../README.md")] #![no_std] -//! This crate provides CGP's optional-field layer, for a builder whose fields are set in any order. -//! -//! See [`HasOptionalBuilder`](https://contextgeneric.dev/docs/reference/traits/optional/has_optional_builder), [`ToOptional`](https://contextgeneric.dev/docs/reference/traits/optional/to_optional), [`SetOptional`](https://contextgeneric.dev/docs/reference/traits/optional/set_optional), and [`FinalizeOptional`](https://contextgeneric.dev/docs/reference/traits/optional/finalize_optional). #![warn(missing_docs)] /// The optional-field traits' implementations. diff --git a/crates/extra/cgp-handler/README.md b/crates/extra/cgp-handler/README.md index adc3ab1b..13ebc9e8 100644 --- a/crates/extra/cgp-handler/README.md +++ b/crates/extra/cgp-handler/README.md @@ -1,12 +1,41 @@ # cgp-handler -`cgp-handler` provides the handler family of Context-Generic Programming (CGP): the components that -model a computation, whether synchronous or async and fallible or not, and the combinators that -chain, nest, and promote them. +[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait +implementations, chosen at compile time. `cgp-handler` provides CGP's handler family: the components +that model a computation, synchronous or async and fallible or not, and the combinators that chain, +nest, and promote them. A provider of `Computer` computes an output from an input: -The `cgp` crate re-exports it as `cgp::extra::handler`. Most projects therefore depend on -[`cgp`](https://crates.io/crates/cgp) alone, without adding this crate to their manifest. +```rust,ignore +use cgp::extra::handler::{CanCompute, Computer, ComputerComponent}; +use cgp::prelude::*; -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +#[cgp_impl(new Double)] +impl Computer { + type Output = u64; + + fn compute(&self, _code: PhantomData, input: u64) -> u64 { + input * 2 + } +} + +pub struct App; + +delegate_components! { App { ComputerComponent: Double } } + +fn main() { + assert_eq!(App.compute(PhantomData::<()>, 21), 42); +} +``` + +Its main items are +[`CanCompute`](https://contextgeneric.dev/docs/reference/components/handler/computer), +[`CanHandle`](https://contextgeneric.dev/docs/reference/components/handler/handler), +[`PipeHandlers`](https://contextgeneric.dev/docs/reference/providers/handler/pipe_handlers), and +[`Promote`](https://contextgeneric.dev/docs/reference/providers/handler/promote), each linked to its +reference page on the website. + +The `cgp` crate re-exports it as `cgp::extra::handler`, so a project depends on +[`cgp`](https://crates.io/crates/cgp) alone, as the example does. + +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. diff --git a/crates/extra/cgp-handler/src/lib.rs b/crates/extra/cgp-handler/src/lib.rs index a0b36473..66b7bc89 100644 --- a/crates/extra/cgp-handler/src/lib.rs +++ b/crates/extra/cgp-handler/src/lib.rs @@ -1,8 +1,5 @@ +#![doc = include_str!("../README.md")] #![no_std] -//! This crate provides CGP's handler family: the computation components and the combinators that -//! compose them. -//! -//! See [`CanCompute`](https://contextgeneric.dev/docs/reference/components/handler/computer), [`CanHandle`](https://contextgeneric.dev/docs/reference/components/handler/handler), [`PipeHandlers`](https://contextgeneric.dev/docs/reference/providers/handler/pipe_handlers), and [`Promote`](https://contextgeneric.dev/docs/reference/providers/handler/promote). #![warn(missing_docs)] mod components; diff --git a/crates/macros/cgp-async-macro/README.md b/crates/macros/cgp-async-macro/README.md index 8b2db696..33890a02 100644 --- a/crates/macros/cgp-async-macro/README.md +++ b/crates/macros/cgp-async-macro/README.md @@ -1,11 +1,36 @@ # cgp-async-macro -`cgp-async-macro` provides the `#[async_trait]` macro of Context-Generic Programming (CGP), which -rewrites each `async fn` in a trait to return `impl Future`, without boxing the future. +[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait +implementations, chosen at compile time. `cgp-async-macro` provides CGP's `#[async_trait]` macro, +which rewrites each `async fn` in a trait to return `impl Future`, without boxing the future: -The `cgp` crate re-exports the macro under `cgp::prelude`. Most projects therefore depend on -[`cgp`](https://crates.io/crates/cgp) alone, without adding this crate to their manifest. +```rust,ignore +use cgp::prelude::*; -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +#[async_trait] +pub trait CanFetch { + async fn fetch(&self, key: &str) -> String; +} + +pub struct Store; + +impl CanFetch for Store { + async fn fetch(&self, key: &str) -> String { + format!("value of {key}") + } +} + +fn main() { + // `fetch` returns `impl Future`, which any executor can run. + let _future = Store.fetch("port"); +} +``` + +Its reference page on the website is +[`#[async_trait]`](https://contextgeneric.dev/docs/reference/macros/async_trait). + +The `cgp` crate gathers its macro in `cgp::prelude`, so a project depends on +[`cgp`](https://crates.io/crates/cgp) alone, as the example does. + +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. diff --git a/crates/macros/cgp-async-macro/src/lib.rs b/crates/macros/cgp-async-macro/src/lib.rs index 8fe73621..2077f243 100644 --- a/crates/macros/cgp-async-macro/src/lib.rs +++ b/crates/macros/cgp-async-macro/src/lib.rs @@ -1,8 +1,5 @@ +#![doc = include_str!("../README.md")] #![no_std] -//! This crate provides CGP's `#[async_trait]` macro, which rewrites a trait's `async fn` to return -//! `impl Future`. -//! -//! See [`#[async_trait]`](https://contextgeneric.dev/docs/reference/macros/async_trait). #![warn(missing_docs)] extern crate alloc; diff --git a/crates/macros/cgp-macro-extra/README.md b/crates/macros/cgp-macro-extra/README.md index 164c4b17..650f479d 100644 --- a/crates/macros/cgp-macro-extra/README.md +++ b/crates/macros/cgp-macro-extra/README.md @@ -1,12 +1,58 @@ # cgp-macro-extra -`cgp-macro-extra` provides the extra procedural macros of Context-Generic Programming (CGP): +[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait +implementations, chosen at compile time. `cgp-macro-extra` provides CGP's extra procedural macros: `#[cgp_computer]` and `#[cgp_producer]`, which define a handler provider from a function, and -`#[cgp_auto_dispatch]`, which implements a trait for an enum by dispatching to its variants. +`#[cgp_auto_dispatch]`, which implements a trait for an enum by dispatching to its variants, as +here: -The `cgp` crate re-exports these macros under `cgp::prelude`. Most projects therefore depend on -[`cgp`](https://crates.io/crates/cgp) alone, without adding this crate to their manifest. +```rust,ignore +use cgp::prelude::*; -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +#[cgp_auto_dispatch] +pub trait HasArea { + fn area(&self) -> f64; +} + +pub struct Circle { + pub radius: f64, +} + +impl HasArea for Circle { + fn area(&self) -> f64 { + 3.0 * self.radius * self.radius + } +} + +pub struct Square { + pub side: f64, +} + +impl HasArea for Square { + fn area(&self) -> f64 { + self.side * self.side + } +} + +#[derive(CgpData)] +pub enum Shape { + Circle(Circle), + Square(Square), +} + +fn main() { + assert_eq!(Shape::Square(Square { side: 2.0 }).area(), 4.0); +} +``` + +Its main items are +[`#[cgp_computer]`](https://contextgeneric.dev/docs/reference/macros/cgp_computer), +[`#[cgp_producer]`](https://contextgeneric.dev/docs/reference/macros/cgp_producer), and +[`#[cgp_auto_dispatch]`](https://contextgeneric.dev/docs/reference/macros/cgp_auto_dispatch), each +linked to its reference page on the website. + +The `cgp` crate gathers its macros in `cgp::prelude`, so a project depends on +[`cgp`](https://crates.io/crates/cgp) alone, as the example does. + +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. diff --git a/crates/macros/cgp-macro-extra/src/lib.rs b/crates/macros/cgp-macro-extra/src/lib.rs index ecc67c3e..923ee9a9 100644 --- a/crates/macros/cgp-macro-extra/src/lib.rs +++ b/crates/macros/cgp-macro-extra/src/lib.rs @@ -1,8 +1,5 @@ +#![doc = include_str!("../README.md")] #![no_std] -//! This crate provides CGP's extra procedural macros, which define handler providers from functions -//! and dispatch a trait over an enum. -//! -//! See [`#[cgp_computer]`](https://contextgeneric.dev/docs/reference/macros/cgp_computer), [`#[cgp_producer]`](https://contextgeneric.dev/docs/reference/macros/cgp_producer), and [`#[cgp_auto_dispatch]`](https://contextgeneric.dev/docs/reference/macros/cgp_auto_dispatch). #![warn(missing_docs)] use proc_macro::TokenStream; diff --git a/crates/macros/cgp-macro/README.md b/crates/macros/cgp-macro/README.md index b6691f65..a41bbce1 100644 --- a/crates/macros/cgp-macro/README.md +++ b/crates/macros/cgp-macro/README.md @@ -1,12 +1,49 @@ # cgp-macro -`cgp-macro` provides the procedural macros of Context-Generic Programming (CGP), from +[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait +implementations, chosen at compile time. `cgp-macro` provides CGP's procedural macros, from `#[cgp_component]`, which defines a component, and `#[cgp_impl]`, which writes a provider, to -`delegate_components!` and `check_components!`, which wire and check a context. +`delegate_components!` and `check_components!`, which wire a context and check the wiring at compile +time. This greeting uses all four: -The `cgp` crate re-exports these macros under `cgp::prelude`. Most projects therefore depend on -[`cgp`](https://crates.io/crates/cgp) alone, without adding this crate to their manifest. +```rust,ignore +use cgp::prelude::*; -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +#[cgp_component(Greeter)] +pub trait CanGreet { + fn greet(&self) -> String; +} + +#[cgp_impl(new GreetHello)] +impl Greeter { + fn greet(&self, #[implicit] name: &str) -> String { + format!("Hello, {name}!") + } +} + +#[derive(HasField)] +pub struct Person { + pub name: String, +} + +delegate_components! { Person { GreeterComponent: GreetHello } } +check_components! { Person { GreeterComponent } } + +fn main() { + let person = Person { name: "World".to_owned() }; + assert_eq!(person.greet(), "Hello, World!"); +} +``` + +Its main items are +[`#[cgp_component]`](https://contextgeneric.dev/docs/reference/macros/cgp_component), +[`#[cgp_impl]`](https://contextgeneric.dev/docs/reference/macros/cgp_impl), +[`delegate_components!`](https://contextgeneric.dev/docs/reference/macros/delegate_components), and +[`check_components!`](https://contextgeneric.dev/docs/reference/macros/check_components), each +linked to its reference page on the website. + +The `cgp` crate gathers its macros in `cgp::prelude`, so a project depends on +[`cgp`](https://crates.io/crates/cgp) alone, as the example does. + +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. diff --git a/crates/macros/cgp-macro/src/lib.rs b/crates/macros/cgp-macro/src/lib.rs index 9fb333cd..c452926c 100644 --- a/crates/macros/cgp-macro/src/lib.rs +++ b/crates/macros/cgp-macro/src/lib.rs @@ -1,8 +1,5 @@ +#![doc = include_str!("../README.md")] #![no_std] -//! This crate provides CGP's procedural macros, from defining a component to wiring and checking a -//! context. -//! -//! See [`#[cgp_component]`](https://contextgeneric.dev/docs/reference/macros/cgp_component), [`#[cgp_impl]`](https://contextgeneric.dev/docs/reference/macros/cgp_impl), [`delegate_components!`](https://contextgeneric.dev/docs/reference/macros/delegate_components), and [`check_components!`](https://contextgeneric.dev/docs/reference/macros/check_components). #![warn(missing_docs)] use proc_macro::TokenStream; diff --git a/crates/main/cgp-core/README.md b/crates/main/cgp-core/README.md index 4a0047e3..c5c1cb70 100644 --- a/crates/main/cgp-core/README.md +++ b/crates/main/cgp-core/README.md @@ -1,11 +1,38 @@ # cgp-core -`cgp-core` gathers the core of Context-Generic Programming (CGP): the base layer and the procedural -macros, the `#[async_trait]` macro, and the error, field, and abstract-type components. +[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait +implementations, chosen at compile time. `cgp-core` gathers CGP's core: the base layer and the +procedural macros, the `#[async_trait]` macro, and the error, field, and abstract-type components. A +`#[cgp_fn]` function, for example, reads its arguments from the context's fields: -The `cgp` crate re-exports it as `cgp::core`. Most projects therefore depend on -[`cgp`](https://crates.io/crates/cgp) alone, without adding this crate to their manifest. +```rust,ignore +use cgp::prelude::*; -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +#[cgp_fn] +fn rectangle_area(&self, #[implicit] width: f64, #[implicit] height: f64) -> f64 { + width * height +} + +#[derive(HasField)] +pub struct Rectangle { + pub width: f64, + pub height: f64, +} + +fn main() { + let rectangle = Rectangle { width: 2.0, height: 3.0 }; + assert_eq!(rectangle.rectangle_area(), 6.0); +} +``` + +Its main items are +[`#[cgp_component]`](https://contextgeneric.dev/docs/reference/macros/cgp_component), +[`HasField`](https://contextgeneric.dev/docs/reference/traits/field-access/has_field), and +[`HasErrorType`](https://contextgeneric.dev/docs/reference/components/has_error_type), each linked +to its reference page on the website. + +The `cgp` crate re-exports it as `cgp::core`, so a project depends on +[`cgp`](https://crates.io/crates/cgp) alone, as the example does. + +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. diff --git a/crates/main/cgp-core/src/lib.rs b/crates/main/cgp-core/src/lib.rs index 792d518d..e4252a00 100644 --- a/crates/main/cgp-core/src/lib.rs +++ b/crates/main/cgp-core/src/lib.rs @@ -1,9 +1,6 @@ +#![doc = include_str!("../README.md")] #![no_std] #![allow(mixed_script_confusables)] -//! This crate re-exports CGP's core layer through `cgp::core`: the base layer, the macros, the -//! async trait macro, and the error, field, and type components. -//! -//! See [`#[cgp_component]`](https://contextgeneric.dev/docs/reference/macros/cgp_component), [`HasField`](https://contextgeneric.dev/docs/reference/traits/field-access/has_field), and [`HasErrorType`](https://contextgeneric.dev/docs/reference/components/has_error_type). #![warn(missing_docs)] /// The core names users write, re-exported through `cgp::prelude`. diff --git a/crates/main/cgp-extra/README.md b/crates/main/cgp-extra/README.md index b13c7b8d..0fecd705 100644 --- a/crates/main/cgp-extra/README.md +++ b/crates/main/cgp-extra/README.md @@ -1,13 +1,50 @@ # cgp-extra -`cgp-extra` gathers the extra features of Context-Generic Programming (CGP): the handlers that model -computations, the dispatch and monadic combinators that compose them, task runners and the runtime -abstraction, the optional-field builders, and the generic error providers. Its `alloc` feature turns -on the providers that need an allocator. +[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait +implementations, chosen at compile time. `cgp-extra` gathers CGP's extra features: the handlers and +the dispatch and monadic combinators that compose them, task runners and the runtime abstraction, +the optional-field builders, and the generic error providers. Its `alloc` feature turns on the +providers that need an allocator. A handler pipeline, for example, runs one computer after another: -The `cgp` crate re-exports it as `cgp::extra`. Most projects therefore depend on -[`cgp`](https://crates.io/crates/cgp) alone, without adding this crate to their manifest. +```rust,ignore +use cgp::extra::handler::{CanCompute, Computer, ComputerComponent, PipeHandlers}; +use cgp::prelude::*; -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +#[cgp_impl(new Double)] +impl Computer { + type Output = u64; + + fn compute(&self, _code: PhantomData, input: u64) -> u64 { + input * 2 + } +} + +#[cgp_impl(new Increment)] +impl Computer { + type Output = u64; + + fn compute(&self, _code: PhantomData, input: u64) -> u64 { + input + 1 + } +} + +pub struct App; + +delegate_components! { App { ComputerComponent: PipeHandlers } } + +fn main() { + assert_eq!(App.compute(PhantomData::<()>, 20), 41); +} +``` + +Its main items are +[`CanHandle`](https://contextgeneric.dev/docs/reference/components/handler/handler), +[`PipeHandlers`](https://contextgeneric.dev/docs/reference/providers/handler/pipe_handlers), and +[`RaiseFrom`](https://contextgeneric.dev/docs/reference/providers/error/raise_from), each linked to +its reference page on the website. + +The `cgp` crate re-exports it as `cgp::extra`, so a project depends on +[`cgp`](https://crates.io/crates/cgp) alone, as the example does. + +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. diff --git a/crates/main/cgp-extra/src/lib.rs b/crates/main/cgp-extra/src/lib.rs index 52905e69..21cac623 100644 --- a/crates/main/cgp-extra/src/lib.rs +++ b/crates/main/cgp-extra/src/lib.rs @@ -1,9 +1,5 @@ +#![doc = include_str!("../README.md")] #![no_std] -//! This crate re-exports CGP's extra layer through `cgp::extra`: handlers, monads, dispatch, -//! runtime, runners, the optional-field layer, and the generic error providers. The `alloc` feature -//! turns on the providers that need an allocator. -//! -//! See [`CanHandle`](https://contextgeneric.dev/docs/reference/components/handler/handler), [`PipeHandlers`](https://contextgeneric.dev/docs/reference/providers/handler/pipe_handlers), and [`RaiseFrom`](https://contextgeneric.dev/docs/reference/providers/error/raise_from). #![warn(missing_docs)] /// The extra names users write, re-exported through `cgp::prelude`. From b132e502dc23537a0b751503822f4bef434ffceb Mon Sep 17 00:00:00 2001 From: Soares Chen Date: Mon, 16 Nov 2026 23:20:40 +0100 Subject: [PATCH 2/4] Revise the writing of the crate READMEs The READMEs with an example relate CGP's tag line to the crate's own part rather than repeating one opening sentence, and introduce their reference links as what the website's reference covers. Every README closes on the same pointer to the website and the cgp crate's API. The error backends name Context-Generic Programming in full, drop their License sections as the other crates' READMEs do, and split two semicolon-joined sentences; cgp-macro-test-util's README loses its bold emphasis and jargon. Co-Authored-By: Claude Opus 5.5 --- crates/core/cgp-base-types/README.md | 13 ++++----- crates/core/cgp-component/README.md | 15 +++++------ crates/core/cgp-error/README.md | 14 +++++----- crates/core/cgp-field/README.md | 15 +++++------ crates/core/cgp-type/README.md | 14 +++++----- crates/extra/cgp-dispatch/README.md | 15 +++++------ crates/extra/cgp-error-extra/README.md | 14 +++++----- crates/extra/cgp-field-extra/README.md | 14 +++++----- crates/extra/cgp-handler/README.md | 14 +++++----- crates/extra/cgp-monad/README.md | 5 ++-- crates/extra/cgp-run/README.md | 5 ++-- crates/extra/cgp-runtime/README.md | 5 ++-- crates/macros/cgp-async-macro/README.md | 7 ++--- crates/macros/cgp-macro-core/README.md | 5 ++-- crates/macros/cgp-macro-extra-core/README.md | 5 ++-- crates/macros/cgp-macro-extra-lib/README.md | 5 ++-- crates/macros/cgp-macro-extra/README.md | 15 +++++------ crates/macros/cgp-macro-lib/README.md | 5 ++-- .../macros/cgp-macro-test-util-lib/README.md | 5 ++-- crates/macros/cgp-macro-test-util/README.md | 27 +++++++++---------- crates/macros/cgp-macro/README.md | 15 +++++------ crates/main/cgp-base-extra/README.md | 5 ++-- crates/main/cgp-base/README.md | 5 ++-- crates/main/cgp-core/README.md | 13 +++++---- crates/main/cgp-extra/README.md | 16 +++++------ .../error/cgp-error-anyhow/README.md | 9 +++---- .../standalone/error/cgp-error-eyre/README.md | 11 +++----- .../standalone/error/cgp-error-std/README.md | 9 +++---- 28 files changed, 138 insertions(+), 162 deletions(-) diff --git a/crates/core/cgp-base-types/README.md b/crates/core/cgp-base-types/README.md index 8e080d16..f395ccb7 100644 --- a/crates/core/cgp-base-types/README.md +++ b/crates/core/cgp-base-types/README.md @@ -1,8 +1,9 @@ # cgp-base-types [Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. `cgp-base-types` provides CGP's type-level primitives: the -symbols that name fields, the lists and sums that describe a type's fields and variants, and the +implementations, chosen at compile time. CGP names the parts it plugs together with types: a field +by a type-level string, a list of fields by a type-level list. `cgp-base-types` provides those +primitives: the symbols, the lists and sums that describe a type's fields and variants, and the paths that namespaces route along. A `Product!` list, for example, is a chain of `Cons` cells closed by `Nil`: @@ -21,18 +22,18 @@ fn main() { } ``` -Its main items are [`Symbol!`](https://contextgeneric.dev/docs/reference/macros/symbol), +The website's reference covers its main items: +[`Symbol!`](https://contextgeneric.dev/docs/reference/macros/symbol), [`Cons`](https://contextgeneric.dev/docs/reference/types/cons), [`Nil`](https://contextgeneric.dev/docs/reference/types/nil), [`Chars`](https://contextgeneric.dev/docs/reference/types/chars), [`PathCons`](https://contextgeneric.dev/docs/reference/types/path_cons), [`StaticFormat`](https://contextgeneric.dev/docs/reference/traits/formatting/static_format), and -[`ConcatPath`](https://contextgeneric.dev/docs/reference/traits/formatting/concat_path), each linked -to its reference page on the website. +[`ConcatPath`](https://contextgeneric.dev/docs/reference/traits/formatting/concat_path). The `cgp` crate re-exports these types under `cgp::core::base`, and the macros that build them under `cgp::prelude`, so a project depends on [`cgp`](https://crates.io/crates/cgp) alone, as the example does. The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/core/cgp-component/README.md b/crates/core/cgp-component/README.md index 129625e6..af331bb1 100644 --- a/crates/core/cgp-component/README.md +++ b/crates/core/cgp-component/README.md @@ -1,10 +1,10 @@ # cgp-component [Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. `cgp-component` provides CGP's component machinery: the -delegation traits that let a context choose a provider for each component, the lookup that finds it, -and the providers CGP ships with. Wiring a context writes a type-level table, which the lookup -reads: +implementations, chosen at compile time. A context makes that choice through wiring, and +`cgp-component` provides the machinery behind it: the delegation traits that record which provider a +context chose for each component, the lookup that reads the choice, and the providers CGP ships +with. The wiring is a type-level table, which the lookup reads: ```rust,ignore use cgp::core::component::DelegateComponent; @@ -33,18 +33,17 @@ fn main() { } ``` -Its main items are +The website's reference covers its main items: [`DelegateComponent`](https://contextgeneric.dev/docs/reference/traits/wiring/delegate_component), [`IsProviderFor`](https://contextgeneric.dev/docs/reference/traits/wiring/is_provider_for), [`CanUseComponent`](https://contextgeneric.dev/docs/reference/traits/wiring/can_use_component), [`UseContext`](https://contextgeneric.dev/docs/reference/providers/use_context), [`UseDefault`](https://contextgeneric.dev/docs/reference/providers/use_default), [`UseDelegate`](https://contextgeneric.dev/docs/reference/providers/use_delegate), and -[`RedirectLookup`](https://contextgeneric.dev/docs/reference/providers/redirect_lookup), each linked -to its reference page on the website. +[`RedirectLookup`](https://contextgeneric.dev/docs/reference/providers/redirect_lookup). The `cgp` crate re-exports it as `cgp::core::component`, so a project depends on [`cgp`](https://crates.io/crates/cgp) alone, as the example does. The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/core/cgp-error/README.md b/crates/core/cgp-error/README.md index 0b15dd50..50a4e187 100644 --- a/crates/core/cgp-error/README.md +++ b/crates/core/cgp-error/README.md @@ -1,9 +1,10 @@ # cgp-error [Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. `cgp-error` provides CGP's error components: an error type -each context chooses, and the components that raise errors into it and wrap them with detail. -Generic code raises an error without knowing its type, and each context decides what it becomes: +implementations, chosen at compile time. Its error handling follows the same idea: each context +chooses its error type. `cgp-error` provides the components behind it, the abstract error type and +the components that raise errors into it and wrap them with detail. Generic code raises an error +without knowing its type, and each context decides what it becomes: ```rust,ignore use cgp::core::error::{ErrorRaiserComponent, ErrorTypeProviderComponent}; @@ -34,14 +35,13 @@ fn main() { } ``` -Its main items are +The website's reference covers its main items: [`HasErrorType`](https://contextgeneric.dev/docs/reference/components/has_error_type), [`CanRaiseError`](https://contextgeneric.dev/docs/reference/components/can_raise_error), and -[`CanWrapError`](https://contextgeneric.dev/docs/reference/components/can_wrap_error), each linked -to its reference page on the website. +[`CanWrapError`](https://contextgeneric.dev/docs/reference/components/can_wrap_error). The `cgp` crate re-exports it as `cgp::core::error`, so a project depends on [`cgp`](https://crates.io/crates/cgp) alone, as the example does. The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/core/cgp-field/README.md b/crates/core/cgp-field/README.md index bb365b88..64a6a81c 100644 --- a/crates/core/cgp-field/README.md +++ b/crates/core/cgp-field/README.md @@ -1,10 +1,10 @@ # cgp-field [Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. `cgp-field` provides CGP's field access: the traits that -read and build a type's fields by name, the tags that name them, and the structural casts between -records and between enums. `#[derive(HasField)]` gives each field a tag, and the field can then be -read by name: +implementations, chosen at compile time. Its providers read a context's fields by name rather than +by type, through the field access `cgp-field` provides: the traits that read and build a type's +fields by name, the tags that name them, and the structural casts between records and between enums. +`#[derive(HasField)]` gives each field a tag, and the field can then be read by name: ```rust,ignore use cgp::core::field::traits::HasField; @@ -22,15 +22,14 @@ fn main() { } ``` -Its main items are +The website's reference covers its main items: [`HasField`](https://contextgeneric.dev/docs/reference/traits/field-access/has_field), [`Index`](https://contextgeneric.dev/docs/reference/types/index_type), [`MRef`](https://contextgeneric.dev/docs/reference/types/mref), and the -[casts](https://contextgeneric.dev/docs/reference/traits/casting/), each linked to its reference -page on the website. +[casts](https://contextgeneric.dev/docs/reference/traits/casting/). The `cgp` crate re-exports it as `cgp::core::field`, so a project depends on [`cgp`](https://crates.io/crates/cgp) alone, as the example does. The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/core/cgp-type/README.md b/crates/core/cgp-type/README.md index aa83f367..bbb4014e 100644 --- a/crates/core/cgp-type/README.md +++ b/crates/core/cgp-type/README.md @@ -1,9 +1,9 @@ # cgp-type [Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. `cgp-type` provides CGP's abstract types, which let each -context choose a type that generic code names only through a trait. A context picks its type in its -wiring: +implementations, chosen at compile time. A context can choose a type the same way, and `cgp-type` +provides these abstract types, which generic code names only through a trait. A context picks its +type in its wiring: ```rust,ignore use cgp::prelude::*; @@ -23,13 +23,13 @@ fn main() { } ``` -Its main items are [`HasType`](https://contextgeneric.dev/docs/reference/components/has_type), +The website's reference covers its main items: +[`HasType`](https://contextgeneric.dev/docs/reference/components/has_type), [`UseType`](https://contextgeneric.dev/docs/reference/providers/use_type), and -[`UseDelegatedType`](https://contextgeneric.dev/docs/reference/providers/use_delegated_type), each -linked to its reference page on the website. +[`UseDelegatedType`](https://contextgeneric.dev/docs/reference/providers/use_delegated_type). The `cgp` crate re-exports it as `cgp::core::types`, so a project depends on [`cgp`](https://crates.io/crates/cgp) alone, as the example does. The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/extra/cgp-dispatch/README.md b/crates/extra/cgp-dispatch/README.md index 7d6b587d..5e421cc3 100644 --- a/crates/extra/cgp-dispatch/README.md +++ b/crates/extra/cgp-dispatch/README.md @@ -1,10 +1,10 @@ # cgp-dispatch [Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. `cgp-dispatch` provides CGP's dispatch combinators, which -split a value between handlers: they match an enum's variants or extract a record's fields and pass -each one to its own handler, or build a record from what the handlers return. Here each variant of -an enum gets its own area computation: +implementations, chosen at compile time. Its handlers compose into larger computations, and +`cgp-dispatch` provides the combinators that split a value between them: they match an enum's +variants or extract a record's fields and pass each part to its own handler, or build a record from +what the handlers return. Here each variant of an enum gets its own area computation: ```rust,ignore use cgp::extra::dispatch::MatchWithValueHandlers; @@ -54,15 +54,14 @@ fn main() { } ``` -Its main items are +The website's reference covers its main items: [`MatchWithHandlers`](https://contextgeneric.dev/docs/reference/providers/dispatch/match_with_handlers), [`MatchWithValueHandlers`](https://contextgeneric.dev/docs/reference/providers/dispatch/match_with_value_handlers), and -[`ExtractFieldAndHandle`](https://contextgeneric.dev/docs/reference/providers/dispatch/extract_field_and_handle), -each linked to its reference page on the website. +[`ExtractFieldAndHandle`](https://contextgeneric.dev/docs/reference/providers/dispatch/extract_field_and_handle). The `cgp` crate re-exports it as `cgp::extra::dispatch`, so a project depends on [`cgp`](https://crates.io/crates/cgp) alone, as the example does. The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/extra/cgp-error-extra/README.md b/crates/extra/cgp-error-extra/README.md index e7e5878e..2e855a90 100644 --- a/crates/extra/cgp-error-extra/README.md +++ b/crates/extra/cgp-error-extra/README.md @@ -1,9 +1,10 @@ # cgp-error-extra [Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. `cgp-error-extra` provides CGP's generic error providers, -which raise an error by conversion, return it unchanged, discard a detail, or format it into a -message. A context routes each source error to one of them: +implementations, chosen at compile time. A context chooses, the same way, how each kind of error +becomes its own error type, and `cgp-error-extra` provides generic providers for that choice. They +raise an error by conversion, return it unchanged, discard a detail, or format it into a message, +and a context routes each source error to one of them: ```rust,ignore use core::num::ParseIntError; @@ -34,18 +35,17 @@ fn main() { `alloc` feature, which this example turns on with `cgp = { version = "0.8.0", features = ["alloc"] }`. -Its main items are +The website's reference covers its main items: [`RaiseFrom`](https://contextgeneric.dev/docs/reference/providers/error/raise_from), [`ReturnError`](https://contextgeneric.dev/docs/reference/providers/error/return_error), [`RaiseInfallible`](https://contextgeneric.dev/docs/reference/providers/error/raise_infallible), [`PanicOnError`](https://contextgeneric.dev/docs/reference/providers/error/panic_on_error), [`DiscardDetail`](https://contextgeneric.dev/docs/reference/providers/error/discard_detail), [`DebugError`](https://contextgeneric.dev/docs/reference/providers/error/debug_error), and -[`DisplayError`](https://contextgeneric.dev/docs/reference/providers/error/display_error), each -linked to its reference page on the website. +[`DisplayError`](https://contextgeneric.dev/docs/reference/providers/error/display_error). The `cgp` crate re-exports it as `cgp::extra::error`, so a project depends on [`cgp`](https://crates.io/crates/cgp) alone, as the example does. The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/extra/cgp-field-extra/README.md b/crates/extra/cgp-field-extra/README.md index 43b7919e..c2888c8f 100644 --- a/crates/extra/cgp-field-extra/README.md +++ b/crates/extra/cgp-field-extra/README.md @@ -1,9 +1,10 @@ # cgp-field-extra [Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. `cgp-field-extra` provides CGP's optional-field layer, -which builds a value from fields set in any order, then finishes once every field is set, or fills -the missing ones from their defaults. A record can be widened into a larger one this way: +implementations, chosen at compile time. Its records can be built field by field, and +`cgp-field-extra` provides the optional-field layer for that: it builds a value from fields set in +any order, then finishes once every field is set, or fills the missing ones from their defaults. A +record can be widened into a larger one this way: ```rust,ignore use cgp::extra::field::impls::CanBuildWithDefault; @@ -28,15 +29,14 @@ fn main() { } ``` -Its main items are +The website's reference covers its main items: [`HasOptionalBuilder`](https://contextgeneric.dev/docs/reference/traits/optional/has_optional_builder), [`ToOptional`](https://contextgeneric.dev/docs/reference/traits/optional/to_optional), [`SetOptional`](https://contextgeneric.dev/docs/reference/traits/optional/set_optional), and -[`FinalizeOptional`](https://contextgeneric.dev/docs/reference/traits/optional/finalize_optional), -each linked to its reference page on the website. +[`FinalizeOptional`](https://contextgeneric.dev/docs/reference/traits/optional/finalize_optional). The `cgp` crate re-exports it as `cgp::extra::field`, so a project depends on [`cgp`](https://crates.io/crates/cgp) alone, as the example does. The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/extra/cgp-handler/README.md b/crates/extra/cgp-handler/README.md index 13ebc9e8..d79af2f3 100644 --- a/crates/extra/cgp-handler/README.md +++ b/crates/extra/cgp-handler/README.md @@ -1,9 +1,10 @@ # cgp-handler [Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. `cgp-handler` provides CGP's handler family: the components -that model a computation, synchronous or async and fallible or not, and the combinators that chain, -nest, and promote them. A provider of `Computer` computes an output from an input: +implementations, chosen at compile time. A computation can be a component too, which a context wires +like any other, and `cgp-handler` provides that handler family: components for computations +synchronous or async and fallible or not, and the combinators that chain, nest, and promote them. A +provider of `Computer` computes an output from an input: ```rust,ignore use cgp::extra::handler::{CanCompute, Computer, ComputerComponent}; @@ -27,15 +28,14 @@ fn main() { } ``` -Its main items are +The website's reference covers its main items: [`CanCompute`](https://contextgeneric.dev/docs/reference/components/handler/computer), [`CanHandle`](https://contextgeneric.dev/docs/reference/components/handler/handler), [`PipeHandlers`](https://contextgeneric.dev/docs/reference/providers/handler/pipe_handlers), and -[`Promote`](https://contextgeneric.dev/docs/reference/providers/handler/promote), each linked to its -reference page on the website. +[`Promote`](https://contextgeneric.dev/docs/reference/providers/handler/promote). The `cgp` crate re-exports it as `cgp::extra::handler`, so a project depends on [`cgp`](https://crates.io/crates/cgp) alone, as the example does. The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/extra/cgp-monad/README.md b/crates/extra/cgp-monad/README.md index 1e6d1033..701b69c7 100644 --- a/crates/extra/cgp-monad/README.md +++ b/crates/extra/cgp-monad/README.md @@ -7,6 +7,5 @@ its first error. The `cgp` crate re-exports it as `cgp::extra::monad`. Most projects therefore depend on [`cgp`](https://crates.io/crates/cgp) alone, without adding this crate to their manifest. -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/extra/cgp-run/README.md b/crates/extra/cgp-run/README.md index da870f42..a4e524f6 100644 --- a/crates/extra/cgp-run/README.md +++ b/crates/extra/cgp-run/README.md @@ -6,6 +6,5 @@ task named by a type-level code. The `cgp` crate re-exports it as `cgp::extra::run`. Most projects therefore depend on [`cgp`](https://crates.io/crates/cgp) alone, without adding this crate to their manifest. -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/extra/cgp-runtime/README.md b/crates/extra/cgp-runtime/README.md index 950982c3..49b0956e 100644 --- a/crates/extra/cgp-runtime/README.md +++ b/crates/extra/cgp-runtime/README.md @@ -6,6 +6,5 @@ context choose its async runtime while generic code reaches it through a trait. The `cgp` crate re-exports it as `cgp::extra::runtime`. Most projects therefore depend on [`cgp`](https://crates.io/crates/cgp) alone, without adding this crate to their manifest. -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/macros/cgp-async-macro/README.md b/crates/macros/cgp-async-macro/README.md index 33890a02..c11c2503 100644 --- a/crates/macros/cgp-async-macro/README.md +++ b/crates/macros/cgp-async-macro/README.md @@ -1,8 +1,9 @@ # cgp-async-macro [Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. `cgp-async-macro` provides CGP's `#[async_trait]` macro, -which rewrites each `async fn` in a trait to return `impl Future`, without boxing the future: +implementations, chosen at compile time. Many of those traits are async, and `cgp-async-macro` +provides the `#[async_trait]` macro for them, which rewrites each `async fn` in a trait to return +`impl Future` without boxing the future: ```rust,ignore use cgp::prelude::*; @@ -33,4 +34,4 @@ The `cgp` crate gathers its macro in `cgp::prelude`, so a project depends on [`cgp`](https://crates.io/crates/cgp) alone, as the example does. The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/macros/cgp-macro-core/README.md b/crates/macros/cgp-macro-core/README.md index c79404cf..0dc50f56 100644 --- a/crates/macros/cgp-macro-core/README.md +++ b/crates/macros/cgp-macro-core/README.md @@ -6,6 +6,5 @@ on. Projects use the macros through `cgp::prelude` and have no reason to depend on this crate. -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/macros/cgp-macro-extra-core/README.md b/crates/macros/cgp-macro-extra-core/README.md index 7ddd2f35..b9be0543 100644 --- a/crates/macros/cgp-macro-extra-core/README.md +++ b/crates/macros/cgp-macro-extra-core/README.md @@ -6,6 +6,5 @@ Programming (CGP): the syntax trees, parsers, and visitors behind `#[cgp_compute Projects use the macros through `cgp::prelude` and have no reason to depend on this crate. -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/macros/cgp-macro-extra-lib/README.md b/crates/macros/cgp-macro-extra-lib/README.md index 1a80bfc1..1358d2f6 100644 --- a/crates/macros/cgp-macro-extra-lib/README.md +++ b/crates/macros/cgp-macro-extra-lib/README.md @@ -5,6 +5,5 @@ that `cgp-macro-extra` exports: `#[cgp_computer]`, `#[cgp_producer]`, and `#[cgp Projects use the macros through `cgp::prelude` and have no reason to depend on this crate. -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/macros/cgp-macro-extra/README.md b/crates/macros/cgp-macro-extra/README.md index 650f479d..7882953f 100644 --- a/crates/macros/cgp-macro-extra/README.md +++ b/crates/macros/cgp-macro-extra/README.md @@ -1,10 +1,10 @@ # cgp-macro-extra [Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. `cgp-macro-extra` provides CGP's extra procedural macros: -`#[cgp_computer]` and `#[cgp_producer]`, which define a handler provider from a function, and -`#[cgp_auto_dispatch]`, which implements a trait for an enum by dispatching to its variants, as -here: +implementations, chosen at compile time. Some providers follow a common pattern, and +`cgp-macro-extra` writes them for you: `#[cgp_computer]` and `#[cgp_producer]` define a handler +provider from a function, and `#[cgp_auto_dispatch]` implements a trait for an enum by dispatching +to its variants, as here: ```rust,ignore use cgp::prelude::*; @@ -45,14 +45,13 @@ fn main() { } ``` -Its main items are +The website's reference covers its main items: [`#[cgp_computer]`](https://contextgeneric.dev/docs/reference/macros/cgp_computer), [`#[cgp_producer]`](https://contextgeneric.dev/docs/reference/macros/cgp_producer), and -[`#[cgp_auto_dispatch]`](https://contextgeneric.dev/docs/reference/macros/cgp_auto_dispatch), each -linked to its reference page on the website. +[`#[cgp_auto_dispatch]`](https://contextgeneric.dev/docs/reference/macros/cgp_auto_dispatch). The `cgp` crate gathers its macros in `cgp::prelude`, so a project depends on [`cgp`](https://crates.io/crates/cgp) alone, as the example does. The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/macros/cgp-macro-lib/README.md b/crates/macros/cgp-macro-lib/README.md index ccff7f6e..c3933783 100644 --- a/crates/macros/cgp-macro-lib/README.md +++ b/crates/macros/cgp-macro-lib/README.md @@ -5,6 +5,5 @@ per macro. The `cgp-macro` crate exports them. Projects use the macros through `cgp::prelude` and have no reason to depend on this crate. -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/macros/cgp-macro-test-util-lib/README.md b/crates/macros/cgp-macro-test-util-lib/README.md index 6bed6e4d..49901ada 100644 --- a/crates/macros/cgp-macro-test-util-lib/README.md +++ b/crates/macros/cgp-macro-test-util-lib/README.md @@ -6,6 +6,5 @@ generates and pin it as an inline snapshot. Projects that use CGP have no reason to depend on this crate. -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/macros/cgp-macro-test-util/README.md b/crates/macros/cgp-macro-test-util/README.md index 250f5e87..b1554dec 100644 --- a/crates/macros/cgp-macro-test-util/README.md +++ b/crates/macros/cgp-macro-test-util/README.md @@ -4,21 +4,20 @@ **[Website](https://contextgeneric.dev/) · [Reference](https://contextgeneric.dev/docs/reference/) · [Implementation record](https://github.com/contextgeneric/cgp-knowledge-base/blob/main/cgp/implementation/entrypoints/snapshot_macros.md)** -This crate exposes a family of `snapshot_*!` procedural macros that pin the code the -core CGP macros generate. Each one does **two** things at once: it emits the real -generated code into the surrounding module, exactly as the underlying CGP macro -would, so the traits, structs, and impls stay live and the rest of the module can -still wire them up and assert their runtime behavior, and it generates a `#[test]` -that asserts a pretty-printed string of that same code against an inline -[`insta`](https://insta.rs) snapshot. Adding or removing a snapshot therefore -changes only the golden assertion, never the compile-time or runtime coverage. - -Two documents carry what this README does not. The +This crate provides a family of `snapshot_*!` procedural macros that pin the code the core CGP +macros generate. Each one does two things at once: it emits the real generated code into the +surrounding module, exactly as the underlying CGP macro would, so the traits, structs, and impls +stay live and the rest of the module can still wire them up and assert their runtime behavior, and +it generates a `#[test]` that asserts a pretty-printed string of that same code against an inline +[`insta`](https://insta.rs) snapshot. Adding or removing a snapshot therefore changes only that +comparison, never what compiles or runs. + +Two documents cover what this README leaves out. The [implementation document](https://github.com/contextgeneric/cgp-knowledge-base/blob/main/cgp/implementation/entrypoints/snapshot_macros.md) -in the knowledge base explains how the macros are built and what an invocation -expands to; the [test suite's rules](https://github.com/contextgeneric/cgp/blob/main/crates/tests/README.md#snapshots) set the convention for -*when* to snapshot: a macro's expansion is pinned only in the concept target that -owns that macro's feature, and written plainly everywhere else. +in the knowledge base explains how the macros are built and what an invocation expands to; the +[test suite's rules](https://github.com/contextgeneric/cgp/blob/main/crates/tests/README.md#snapshots) +set the convention for *when* to snapshot: a macro's expansion is pinned only in the concept target +that owns that macro's feature, and written plainly everywhere else. ## Crate layout diff --git a/crates/macros/cgp-macro/README.md b/crates/macros/cgp-macro/README.md index a41bbce1..8ee7ce0d 100644 --- a/crates/macros/cgp-macro/README.md +++ b/crates/macros/cgp-macro/README.md @@ -1,10 +1,10 @@ # cgp-macro [Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. `cgp-macro` provides CGP's procedural macros, from -`#[cgp_component]`, which defines a component, and `#[cgp_impl]`, which writes a provider, to -`delegate_components!` and `check_components!`, which wire a context and check the wiring at compile -time. This greeting uses all four: +implementations, chosen at compile time. Its macros write the traits and impls behind that choice. +`cgp-macro` provides them, from `#[cgp_component]`, which defines a component, and `#[cgp_impl]`, +which writes a provider, to `delegate_components!` and `check_components!`, which wire a context and +check the wiring. This greeting uses all four: ```rust,ignore use cgp::prelude::*; @@ -35,15 +35,14 @@ fn main() { } ``` -Its main items are +The website's reference covers its main items: [`#[cgp_component]`](https://contextgeneric.dev/docs/reference/macros/cgp_component), [`#[cgp_impl]`](https://contextgeneric.dev/docs/reference/macros/cgp_impl), [`delegate_components!`](https://contextgeneric.dev/docs/reference/macros/delegate_components), and -[`check_components!`](https://contextgeneric.dev/docs/reference/macros/check_components), each -linked to its reference page on the website. +[`check_components!`](https://contextgeneric.dev/docs/reference/macros/check_components). The `cgp` crate gathers its macros in `cgp::prelude`, so a project depends on [`cgp`](https://crates.io/crates/cgp) alone, as the example does. The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/main/cgp-base-extra/README.md b/crates/main/cgp-base-extra/README.md index b6c4e838..eb0705e2 100644 --- a/crates/main/cgp-base-extra/README.md +++ b/crates/main/cgp-base-extra/README.md @@ -7,6 +7,5 @@ It is an internal layer of the `cgp` crate, which re-exports everything it holds Most projects therefore depend on [`cgp`](https://crates.io/crates/cgp) alone, without adding this crate to their manifest. -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/main/cgp-base/README.md b/crates/main/cgp-base/README.md index a4c8d6f0..4fe32da7 100644 --- a/crates/main/cgp-base/README.md +++ b/crates/main/cgp-base/README.md @@ -6,6 +6,5 @@ the component machinery, and the procedural macros, which CGP's higher layers bu The `cgp` crate re-exports it as `cgp::core::base`. Most projects therefore depend on [`cgp`](https://crates.io/crates/cgp) alone, without adding this crate to their manifest. -To learn more, read the [`cgp` crate's documentation](https://docs.rs/cgp) and the -[CGP website](https://contextgeneric.dev/), which covers everything from a first program to the -reference for each construct. +The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/main/cgp-core/README.md b/crates/main/cgp-core/README.md index c5c1cb70..67d48793 100644 --- a/crates/main/cgp-core/README.md +++ b/crates/main/cgp-core/README.md @@ -1,9 +1,9 @@ # cgp-core [Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. `cgp-core` gathers CGP's core: the base layer and the -procedural macros, the `#[async_trait]` macro, and the error, field, and abstract-type components. A -`#[cgp_fn]` function, for example, reads its arguments from the context's fields: +implementations, chosen at compile time. `cgp-core` gathers what that rests on: the base layer and +the procedural macros, the `#[async_trait]` macro, and the error, field, and abstract-type +components. A `#[cgp_fn]` function, for example, reads its arguments from the context's fields: ```rust,ignore use cgp::prelude::*; @@ -25,14 +25,13 @@ fn main() { } ``` -Its main items are +The website's reference covers its main items: [`#[cgp_component]`](https://contextgeneric.dev/docs/reference/macros/cgp_component), [`HasField`](https://contextgeneric.dev/docs/reference/traits/field-access/has_field), and -[`HasErrorType`](https://contextgeneric.dev/docs/reference/components/has_error_type), each linked -to its reference page on the website. +[`HasErrorType`](https://contextgeneric.dev/docs/reference/components/has_error_type). The `cgp` crate re-exports it as `cgp::core`, so a project depends on [`cgp`](https://crates.io/crates/cgp) alone, as the example does. The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/main/cgp-extra/README.md b/crates/main/cgp-extra/README.md index 0fecd705..f197b286 100644 --- a/crates/main/cgp-extra/README.md +++ b/crates/main/cgp-extra/README.md @@ -1,10 +1,11 @@ # cgp-extra [Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. `cgp-extra` gathers CGP's extra features: the handlers and -the dispatch and monadic combinators that compose them, task runners and the runtime abstraction, -the optional-field builders, and the generic error providers. Its `alloc` feature turns on the -providers that need an allocator. A handler pipeline, for example, runs one computer after another: +implementations, chosen at compile time. `cgp-extra` gathers the features built on top: the handlers +and the dispatch and monadic combinators that compose them, task runners and the runtime +abstraction, the optional-field builders, and the generic error providers. Its `alloc` feature turns +on the providers that need an allocator. A handler pipeline, for example, runs one computer after +another: ```rust,ignore use cgp::extra::handler::{CanCompute, Computer, ComputerComponent, PipeHandlers}; @@ -37,14 +38,13 @@ fn main() { } ``` -Its main items are +The website's reference covers its main items: [`CanHandle`](https://contextgeneric.dev/docs/reference/components/handler/handler), [`PipeHandlers`](https://contextgeneric.dev/docs/reference/providers/handler/pipe_handlers), and -[`RaiseFrom`](https://contextgeneric.dev/docs/reference/providers/error/raise_from), each linked to -its reference page on the website. +[`RaiseFrom`](https://contextgeneric.dev/docs/reference/providers/error/raise_from). The `cgp` crate re-exports it as `cgp::extra`, so a project depends on [`cgp`](https://crates.io/crates/cgp) alone, as the example does. The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers its API. +each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file diff --git a/crates/standalone/error/cgp-error-anyhow/README.md b/crates/standalone/error/cgp-error-anyhow/README.md index 835f0552..7551525b 100644 --- a/crates/standalone/error/cgp-error-anyhow/README.md +++ b/crates/standalone/error/cgp-error-anyhow/README.md @@ -5,9 +5,9 @@ # cgp-error-anyhow: anyhow as a context's error type `cgp-error-anyhow` makes [`anyhow::Error`](https://docs.rs/anyhow) the abstract error type of a -[CGP](https://contextgeneric.dev) context, and supplies the providers that raise errors into it and -add context to it. Code written against `HasErrorType`, `CanRaiseError`, and `CanWrapError` stays -generic; only the context's wiring names anyhow. +[Context-Generic Programming (CGP)](https://contextgeneric.dev) context, and supplies the providers +that raise errors into it and add context to it. Code written against `HasErrorType`, +`CanRaiseError`, and `CanWrapError` stays generic, and only the context's wiring names anyhow. **[Website](https://contextgeneric.dev/) · [Modular error handling](https://contextgeneric.dev/docs/concepts/modular-error-handling) · [The error components](https://contextgeneric.dev/docs/reference/components/has_error_type)** @@ -50,6 +50,3 @@ need `std`, such as backtrace capture. The crate re-exports `anyhow::Error` as `cgp_error_anyhow::Error`. -## License - -Licensed under the [Apache License, Version 2.0](https://github.com/contextgeneric/cgp/blob/main/LICENSE). diff --git a/crates/standalone/error/cgp-error-eyre/README.md b/crates/standalone/error/cgp-error-eyre/README.md index e501689e..f1d8b89e 100644 --- a/crates/standalone/error/cgp-error-eyre/README.md +++ b/crates/standalone/error/cgp-error-eyre/README.md @@ -5,9 +5,9 @@ # cgp-error-eyre: eyre as a context's error type `cgp-error-eyre` makes [`eyre::Report`](https://docs.rs/eyre) the abstract error type of a -[CGP](https://contextgeneric.dev) context, and supplies the providers that raise errors into it and -add context to it. Code written against `HasErrorType`, `CanRaiseError`, and `CanWrapError` stays -generic; only the context's wiring names eyre. +[Context-Generic Programming (CGP)](https://contextgeneric.dev) context, and supplies the providers +that raise errors into it and add context to it. Code written against `HasErrorType`, +`CanRaiseError`, and `CanWrapError` stays generic, and only the context's wiring names eyre. **[Website](https://contextgeneric.dev/) · [Modular error handling](https://contextgeneric.dev/docs/concepts/modular-error-handling) · [The error components](https://contextgeneric.dev/docs/reference/components/has_error_type)** @@ -48,13 +48,10 @@ A `String` needs `DisplayEyreError` or `DebugEyreError`, because it is not a sta The crate enables eyre's `auto-install` feature, so eyre's default report handler is installed the first time a report is built. To use another handler, such as `color-eyre`, install it with -`eyre::set_hook` before the first error is raised; once a report exists, `set_hook` returns an +`eyre::set_hook` before the first error is raised, since once a report exists, `set_hook` returns an error. The crate also enables eyre's `track-caller` feature, and CGP's `raise_error` is `#[track_caller]`, so a report's `Location:` names the line that called `raise_error`. eyre requires `std`, so this crate does too. The crate re-exports `eyre::Error`, eyre's alias for `Report`, as `cgp_error_eyre::Error`. -## License - -Licensed under the [Apache License, Version 2.0](https://github.com/contextgeneric/cgp/blob/main/LICENSE). diff --git a/crates/standalone/error/cgp-error-std/README.md b/crates/standalone/error/cgp-error-std/README.md index cd4ed28d..3831ecd4 100644 --- a/crates/standalone/error/cgp-error-std/README.md +++ b/crates/standalone/error/cgp-error-std/README.md @@ -5,9 +5,9 @@ # cgp-error-std: a boxed standard error as a context's error type `cgp-error-std` makes a boxed standard error, `Box`, the -abstract error type of a [CGP](https://contextgeneric.dev) context, and supplies the providers that -raise errors into it and add context to it. It depends only on `cgp` and `alloc`, so it suits a -`no_std` context that still wants an open-ended error type. +abstract error type of a [Context-Generic Programming (CGP)](https://contextgeneric.dev) context, +and supplies the providers that raise errors into it and add context to it. It depends only on `cgp` +and `alloc`, so it suits a `no_std` context that still wants an open-ended error type. **[Website](https://contextgeneric.dev/) · [Modular error handling](https://contextgeneric.dev/docs/concepts/modular-error-handling) · [The error components](https://contextgeneric.dev/docs/reference/components/has_error_type)** @@ -52,6 +52,3 @@ message once, and prints the whole chain with `{:#}` or `{:?}`. A `String` needs `DisplayBoxedStdError` or `DebugBoxedStdError`, because it is not a standard error, and `DebugBoxedStdError` prints it with quotes. -## License - -Licensed under the [Apache License, Version 2.0](https://github.com/contextgeneric/cgp/blob/main/LICENSE). From 4d8ec57bcee47dc4bf282c45f1a885fa0d3fbe7d Mon Sep 17 00:00:00 2001 From: Soares Chen Date: Mon, 16 Nov 2026 23:39:39 +0100 Subject: [PATCH 3/4] Relate each crate README's opening to its crate, and run the backend examples as written The crate READMEs opened with one sentence pasted onto fourteen of them. Each opening now names Context-Generic Programming in a sentence about what that crate does, relating the idea of pluggable trait implementations to it, or leaving it out where it does not fit, as with the async trait macro. The error backends' examples ran their statements at the top level, which is not Rust a reader can copy; they now sit in `fn main()`, and the test crate's build script takes the body of `main` as the test it generates from each README. The `cgp` README quotes the checker's qualification as the other documents do, and the snapshot-test macros' README names CGP, splits its long opening sentence, labels its layout block as text, and wraps its prose at 100 columns. Co-Authored-By: Claude Opus 5.5 --- crates/core/cgp-base-types/README.md | 11 ++-- crates/core/cgp-component/README.md | 10 +-- crates/core/cgp-error/README.md | 10 +-- crates/core/cgp-field/README.md | 10 +-- crates/core/cgp-type/README.md | 6 +- crates/extra/cgp-dispatch/README.md | 10 +-- crates/extra/cgp-error-extra/README.md | 9 ++- crates/extra/cgp-field-extra/README.md | 10 +-- crates/extra/cgp-handler/README.md | 9 ++- crates/macros/cgp-async-macro/README.md | 7 +-- crates/macros/cgp-macro-extra/README.md | 9 ++- crates/macros/cgp-macro-test-util/README.md | 63 +++++++++---------- crates/macros/cgp-macro/README.md | 8 +-- crates/main/cgp-core/README.md | 4 +- crates/main/cgp-extra/README.md | 11 ++-- crates/main/cgp/README.md | 4 +- .../error/cgp-error-anyhow/README.md | 8 ++- .../standalone/error/cgp-error-eyre/README.md | 8 ++- .../standalone/error/cgp-error-std/README.md | 10 +-- crates/tests/cgp-tests/build.rs | 23 ++++--- 20 files changed, 121 insertions(+), 119 deletions(-) diff --git a/crates/core/cgp-base-types/README.md b/crates/core/cgp-base-types/README.md index f395ccb7..693eb24f 100644 --- a/crates/core/cgp-base-types/README.md +++ b/crates/core/cgp-base-types/README.md @@ -1,11 +1,10 @@ # cgp-base-types -[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. CGP names the parts it plugs together with types: a field -by a type-level string, a list of fields by a type-level list. `cgp-base-types` provides those -primitives: the symbols, the lists and sums that describe a type's fields and variants, and the -paths that namespaces route along. A `Product!` list, for example, is a chain of `Cons` cells closed -by `Nil`: +[Context-Generic Programming (CGP)](https://contextgeneric.dev/) selects trait implementations at +compile time through types, so the names it works with are types too: a field's name is a type-level +string, and a list of fields is a type-level list. `cgp-base-types` provides those primitives: the +symbols, the lists and sums that describe a type's fields and variants, and the paths that +namespaces route along. A `Product!` list, for example, is a chain of `Cons` cells closed by `Nil`: ```rust,ignore use cgp::core::field::types::{Cons, Nil}; diff --git a/crates/core/cgp-component/README.md b/crates/core/cgp-component/README.md index af331bb1..233c59dc 100644 --- a/crates/core/cgp-component/README.md +++ b/crates/core/cgp-component/README.md @@ -1,10 +1,10 @@ # cgp-component -[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. A context makes that choice through wiring, and -`cgp-component` provides the machinery behind it: the delegation traits that record which provider a -context chose for each component, the lookup that reads the choice, and the providers CGP ships -with. The wiring is a type-level table, which the lookup reads: +In [Context-Generic Programming (CGP)](https://contextgeneric.dev/), each context chooses, at +compile time, which implementation of a trait it uses. `cgp-component` provides the machinery behind +that choice: the delegation traits that record which provider a context chose for each component, +the lookup that reads the choice, and the providers CGP ships with. The choice is recorded in a +type-level table, which the lookup reads: ```rust,ignore use cgp::core::component::DelegateComponent; diff --git a/crates/core/cgp-error/README.md b/crates/core/cgp-error/README.md index 50a4e187..bcb6d7ed 100644 --- a/crates/core/cgp-error/README.md +++ b/crates/core/cgp-error/README.md @@ -1,10 +1,10 @@ # cgp-error -[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. Its error handling follows the same idea: each context -chooses its error type. `cgp-error` provides the components behind it, the abstract error type and -the components that raise errors into it and wrap them with detail. Generic code raises an error -without knowing its type, and each context decides what it becomes: +[Context-Generic Programming (CGP)](https://contextgeneric.dev/) lets each context choose how a +trait is implemented, and its error handling extends that choice to the error type itself. +`cgp-error` provides the components behind it: the abstract error type, and the components that +raise errors into it and wrap them with detail. Generic code raises an error without knowing its +type, and each context decides what it becomes: ```rust,ignore use cgp::core::error::{ErrorRaiserComponent, ErrorTypeProviderComponent}; diff --git a/crates/core/cgp-field/README.md b/crates/core/cgp-field/README.md index 64a6a81c..df74f7c7 100644 --- a/crates/core/cgp-field/README.md +++ b/crates/core/cgp-field/README.md @@ -1,10 +1,10 @@ # cgp-field -[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. Its providers read a context's fields by name rather than -by type, through the field access `cgp-field` provides: the traits that read and build a type's -fields by name, the tags that name them, and the structural casts between records and between enums. -`#[derive(HasField)]` gives each field a tag, and the field can then be read by name: +A [Context-Generic Programming (CGP)](https://contextgeneric.dev/) provider reads the values it +needs from its context's fields by name, so it fits any context that has those fields. `cgp-field` +provides that field access: the traits that read and build a type's fields by name, the tags that +name them, and the structural casts between records and between enums. `#[derive(HasField)]` gives +each field a tag, and the field can then be read by name: ```rust,ignore use cgp::core::field::traits::HasField; diff --git a/crates/core/cgp-type/README.md b/crates/core/cgp-type/README.md index bbb4014e..4a3ac27d 100644 --- a/crates/core/cgp-type/README.md +++ b/crates/core/cgp-type/README.md @@ -1,8 +1,8 @@ # cgp-type -[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. A context can choose a type the same way, and `cgp-type` -provides these abstract types, which generic code names only through a trait. A context picks its +[Context-Generic Programming (CGP)](https://contextgeneric.dev/) lets each context choose a trait's +implementation at compile time, and it can choose a type the same way. `cgp-type` provides these +abstract types, which generic code names only through a trait while each context picks the concrete type in its wiring: ```rust,ignore diff --git a/crates/extra/cgp-dispatch/README.md b/crates/extra/cgp-dispatch/README.md index 5e421cc3..d8cf4c24 100644 --- a/crates/extra/cgp-dispatch/README.md +++ b/crates/extra/cgp-dispatch/README.md @@ -1,10 +1,10 @@ # cgp-dispatch -[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. Its handlers compose into larger computations, and -`cgp-dispatch` provides the combinators that split a value between them: they match an enum's -variants or extract a record's fields and pass each part to its own handler, or build a record from -what the handlers return. Here each variant of an enum gets its own area computation: +In [Context-Generic Programming (CGP)](https://contextgeneric.dev/), a computation can be a +component like any other, and `cgp-dispatch` provides the combinators that split a value between +several of them: they match an enum's variants or extract a record's fields and pass each part to +its own handler, or build a record from what the handlers return. Here each variant of an enum gets +its own area computation: ```rust,ignore use cgp::extra::dispatch::MatchWithValueHandlers; diff --git a/crates/extra/cgp-error-extra/README.md b/crates/extra/cgp-error-extra/README.md index 2e855a90..0bf2fec9 100644 --- a/crates/extra/cgp-error-extra/README.md +++ b/crates/extra/cgp-error-extra/README.md @@ -1,10 +1,9 @@ # cgp-error-extra -[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. A context chooses, the same way, how each kind of error -becomes its own error type, and `cgp-error-extra` provides generic providers for that choice. They -raise an error by conversion, return it unchanged, discard a detail, or format it into a message, -and a context routes each source error to one of them: +[Context-Generic Programming (CGP)](https://contextgeneric.dev/) lets each context choose its error +type, and how each kind of error is raised into it. `cgp-error-extra` provides generic providers for +that choice: they raise an error by conversion, return it unchanged, discard a detail, or format it +into a message, and a context routes each source error to one of them: ```rust,ignore use core::num::ParseIntError; diff --git a/crates/extra/cgp-field-extra/README.md b/crates/extra/cgp-field-extra/README.md index c2888c8f..7d69ad9c 100644 --- a/crates/extra/cgp-field-extra/README.md +++ b/crates/extra/cgp-field-extra/README.md @@ -1,10 +1,10 @@ # cgp-field-extra -[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. Its records can be built field by field, and -`cgp-field-extra` provides the optional-field layer for that: it builds a value from fields set in -any order, then finishes once every field is set, or fills the missing ones from their defaults. A -record can be widened into a larger one this way: +[Context-Generic Programming (CGP)](https://contextgeneric.dev/) can build a record field by field, +so separate pieces of code can each supply part of a value. `cgp-field-extra` provides the +optional-field layer for that: it builds a value from fields set in any order, then finishes once +every field is set, or fills the missing ones from their defaults. A record can be widened into a +larger one this way: ```rust,ignore use cgp::extra::field::impls::CanBuildWithDefault; diff --git a/crates/extra/cgp-handler/README.md b/crates/extra/cgp-handler/README.md index d79af2f3..487fdd51 100644 --- a/crates/extra/cgp-handler/README.md +++ b/crates/extra/cgp-handler/README.md @@ -1,10 +1,9 @@ # cgp-handler -[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. A computation can be a component too, which a context wires -like any other, and `cgp-handler` provides that handler family: components for computations -synchronous or async and fallible or not, and the combinators that chain, nest, and promote them. A -provider of `Computer` computes an output from an input: +In [Context-Generic Programming (CGP)](https://contextgeneric.dev/), a computation can be a +component too, which each context wires like any other. `cgp-handler` provides that handler family: +components for computations synchronous or async and fallible or not, and the combinators that +chain, nest, and promote them. A provider of `Computer` computes an output from an input: ```rust,ignore use cgp::extra::handler::{CanCompute, Computer, ComputerComponent}; diff --git a/crates/macros/cgp-async-macro/README.md b/crates/macros/cgp-async-macro/README.md index c11c2503..6cefec54 100644 --- a/crates/macros/cgp-async-macro/README.md +++ b/crates/macros/cgp-async-macro/README.md @@ -1,9 +1,8 @@ # cgp-async-macro -[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. Many of those traits are async, and `cgp-async-macro` -provides the `#[async_trait]` macro for them, which rewrites each `async fn` in a trait to return -`impl Future` without boxing the future: +Many traits in [Context-Generic Programming (CGP)](https://contextgeneric.dev/) are async, and +`cgp-async-macro` provides the `#[async_trait]` macro for them, which rewrites each `async fn` in a +trait to return `impl Future` without boxing the future: ```rust,ignore use cgp::prelude::*; diff --git a/crates/macros/cgp-macro-extra/README.md b/crates/macros/cgp-macro-extra/README.md index 7882953f..b931c771 100644 --- a/crates/macros/cgp-macro-extra/README.md +++ b/crates/macros/cgp-macro-extra/README.md @@ -1,10 +1,9 @@ # cgp-macro-extra -[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. Some providers follow a common pattern, and -`cgp-macro-extra` writes them for you: `#[cgp_computer]` and `#[cgp_producer]` define a handler -provider from a function, and `#[cgp_auto_dispatch]` implements a trait for an enum by dispatching -to its variants, as here: +In [Context-Generic Programming (CGP)](https://contextgeneric.dev/), each pluggable implementation +of a trait is a provider, and some providers follow a common pattern that `cgp-macro-extra` writes +for you: `#[cgp_computer]` and `#[cgp_producer]` define a handler provider from a function, and +`#[cgp_auto_dispatch]` implements a trait for an enum by dispatching to its variants, as here: ```rust,ignore use cgp::prelude::*; diff --git a/crates/macros/cgp-macro-test-util/README.md b/crates/macros/cgp-macro-test-util/README.md index b1554dec..524b063e 100644 --- a/crates/macros/cgp-macro-test-util/README.md +++ b/crates/macros/cgp-macro-test-util/README.md @@ -4,28 +4,29 @@ **[Website](https://contextgeneric.dev/) · [Reference](https://contextgeneric.dev/docs/reference/) · [Implementation record](https://github.com/contextgeneric/cgp-knowledge-base/blob/main/cgp/implementation/entrypoints/snapshot_macros.md)** -This crate provides a family of `snapshot_*!` procedural macros that pin the code the core CGP -macros generate. Each one does two things at once: it emits the real generated code into the -surrounding module, exactly as the underlying CGP macro would, so the traits, structs, and impls -stay live and the rest of the module can still wire them up and assert their runtime behavior, and -it generates a `#[test]` that asserts a pretty-printed string of that same code against an inline -[`insta`](https://insta.rs) snapshot. Adding or removing a snapshot therefore changes only that -comparison, never what compiles or runs. +The procedural macros of [Context-Generic Programming (CGP)](https://contextgeneric.dev/) generate +the traits and impls behind its pluggable trait implementations, and CGP's own test suite pins that +generated code with the `snapshot_*!` macros this crate provides. Each one emits the real generated +code into the surrounding module, exactly as the underlying CGP macro would, so the traits, structs, +and impls stay live and the rest of the module can still wire them and assert their behavior at run +time. It also generates a `#[test]` that compares a pretty-printed copy of the same code with an +inline [`insta`](https://insta.rs) snapshot. Adding or removing a snapshot therefore changes only +that comparison, never what compiles or runs. Two documents cover what this README leaves out. The [implementation document](https://github.com/contextgeneric/cgp-knowledge-base/blob/main/cgp/implementation/entrypoints/snapshot_macros.md) -in the knowledge base explains how the macros are built and what an invocation expands to; the +in the knowledge base explains how the macros are built and what an invocation expands to. The [test suite's rules](https://github.com/contextgeneric/cgp/blob/main/crates/tests/README.md#snapshots) -set the convention for *when* to snapshot: a macro's expansion is pinned only in the concept target -that owns that macro's feature, and written plainly everywhere else. +say *when* to snapshot: a macro's expansion is pinned only in the concept target that owns that +macro's feature, and written plainly everywhere else. ## Crate layout This is the proc-macro crate, a thin shell: every macro forwards to -[`cgp-macro-test-util-lib`](https://crates.io/crates/cgp-macro-test-util-lib), a normal library crate so -the logic can be unit-tested without the `proc-macro = true` restriction. +[`cgp-macro-test-util-lib`](https://crates.io/crates/cgp-macro-test-util-lib), a normal library +crate, so the logic can be unit-tested without the `proc-macro = true` restriction. -``` +```text cgp-macro-test-util/ # proc-macro entry points (#[proc_macro] fns) └── cgp-macro-test-util-lib/ # the actual implementation ├── entrypoints/ # one function per macro @@ -33,9 +34,8 @@ cgp-macro-test-util/ # proc-macro entry points (#[proc_macro] fns) └── functions/ # parse_attribute, pretty_format ``` -The implementation calls the real macro logic in `cgp-macro-lib` and -`cgp-macro-extra-lib`, not a copy of it, -so a snapshot is guaranteed to show what the production macros generate. +The implementation calls the real macro logic in `cgp-macro-lib` and `cgp-macro-extra-lib`, not a +copy of it, so a snapshot shows what the production macros generate. ## Available macros @@ -64,15 +64,15 @@ so a snapshot is guaranteed to show what the production macros generate. | `snapshot_cgp_producer!` | `#[cgp_producer]` | | `snapshot_cgp_auto_dispatch!` | `#[cgp_auto_dispatch]` | -Each accepts the same argument forms as the macro it wraps, because it drives the -production entry function; `snapshot_cgp_component!` takes both -`#[cgp_component(Greeter)]` and the brace form, for instance. +Each accepts the same argument forms as the macro it wraps, because it drives the production entry +function; `snapshot_cgp_component!` takes both `#[cgp_component(Greeter)]` and the brace form, for +instance. ## Anatomy of an invocation -Every snapshot macro takes the item under test, written exactly as you would write -the underlying macro invocation, followed by a test block naming the generated -`#[test]` and the identifier bound to the pretty-printed expansion: +Every snapshot macro takes the item under test, written exactly as you would write the underlying +macro invocation, followed by a test block naming the generated `#[test]` and the identifier bound +to the pretty-printed expansion: ```rust use cgp::prelude::*; @@ -91,16 +91,15 @@ snapshot_cgp_getter! { } ``` -That emits the real `#[cgp_getter]` expansion, which is the consumer trait and its -blanket impl, the provider trait, the marker struct, and the `UseField`/`UseFields`/ -`RedirectLookup` provider impls, and then a `fn expand_has_name()` holding the same -code as a string. The test-function name must be unique within its module, so give -each snapshot in a file a distinct one. +That emits the real `#[cgp_getter]` expansion, which is the consumer trait and its blanket impl, the +provider trait, the marker struct, and the `UseField`, `UseFields`, and `RedirectLookup` provider +impls, and then a `fn expand_has_name()` holding the same code as a string. The test-function name +must be unique within its module, so give each snapshot in a file a distinct one. ## Workflow with `insta` -Write the test with an **empty** inline snapshot first (`assert_snapshot!(output, @"")`), -then let `insta` fill it in: +Write the test with an **empty** inline snapshot first (`assert_snapshot!(output, @"")`), then let +`insta` fill it in: ```bash cargo insta test -p cgp-tests --test getter # then: cargo insta review @@ -108,9 +107,9 @@ cargo insta test -p cgp-tests --accept # accept everything non-interactiv INSTA_UPDATE=always cargo test -p cgp-tests # or via the env var ``` -After the first accept, the inline `@"..."` holds the pretty-printed generated code. -On later runs the test fails if that code changes, showing a diff to re-accept once -you have confirmed the change is intended. +After the first accept, the inline `@"..."` holds the pretty-printed generated code. On later runs +the test fails if that code changes, showing a diff to re-accept once you have confirmed the change +is intended. ## Notes and limitations diff --git a/crates/macros/cgp-macro/README.md b/crates/macros/cgp-macro/README.md index 8ee7ce0d..b10170a8 100644 --- a/crates/macros/cgp-macro/README.md +++ b/crates/macros/cgp-macro/README.md @@ -1,10 +1,10 @@ # cgp-macro [Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. Its macros write the traits and impls behind that choice. -`cgp-macro` provides them, from `#[cgp_component]`, which defines a component, and `#[cgp_impl]`, -which writes a provider, to `delegate_components!` and `check_components!`, which wire a context and -check the wiring. This greeting uses all four: +implementations, chosen at compile time, and `cgp-macro` provides the macros that write the traits +and impls behind them: `#[cgp_component]` defines a component, `#[cgp_impl]` writes a provider, and +`delegate_components!` and `check_components!` wire a context and check the wiring. This greeting +uses all four: ```rust,ignore use cgp::prelude::*; diff --git a/crates/main/cgp-core/README.md b/crates/main/cgp-core/README.md index 67d48793..c00063f6 100644 --- a/crates/main/cgp-core/README.md +++ b/crates/main/cgp-core/README.md @@ -1,7 +1,7 @@ # cgp-core -[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. `cgp-core` gathers what that rests on: the base layer and +`cgp-core` gathers the core of [Context-Generic Programming (CGP)](https://contextgeneric.dev/), +which extends Rust with pluggable trait implementations chosen at compile time: the base layer and the procedural macros, the `#[async_trait]` macro, and the error, field, and abstract-type components. A `#[cgp_fn]` function, for example, reads its arguments from the context's fields: diff --git a/crates/main/cgp-extra/README.md b/crates/main/cgp-extra/README.md index f197b286..d9e1b8c7 100644 --- a/crates/main/cgp-extra/README.md +++ b/crates/main/cgp-extra/README.md @@ -1,11 +1,10 @@ # cgp-extra -[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait -implementations, chosen at compile time. `cgp-extra` gathers the features built on top: the handlers -and the dispatch and monadic combinators that compose them, task runners and the runtime -abstraction, the optional-field builders, and the generic error providers. Its `alloc` feature turns -on the providers that need an allocator. A handler pipeline, for example, runs one computer after -another: +`cgp-extra` gathers the features [Context-Generic Programming (CGP)](https://contextgeneric.dev/) +builds on its pluggable trait implementations: the handlers and the dispatch and monadic combinators +that compose them, task runners and the runtime abstraction, the optional-field builders, and the +generic error providers. Its `alloc` feature turns on the providers that need an allocator. A +handler pipeline, for example, runs one computer after another: ```rust,ignore use cgp::extra::handler::{CanCompute, Computer, ComputerComponent, PipeHandlers}; diff --git a/crates/main/cgp/README.md b/crates/main/cgp/README.md index 54624532..515b9ebc 100644 --- a/crates/main/cgp/README.md +++ b/crates/main/cgp/README.md @@ -78,8 +78,8 @@ cgp = { version = "0.8.0", features = ["alloc"] } Once you start writing CGP, install [`cargo-cgp`](https://github.com/contextgeneric/cargo-cgp) alongside it to help diagnose wiring mistakes, which otherwise show up as errors about generated -types. `cargo cgp check` leads with the root cause for the classes of error it recognizes, though -it does not yet reshape every class. +types. `cargo cgp check` leads with the root cause for the classes it recognizes, and the tool does +not yet reshape every class. ## Learn CGP diff --git a/crates/standalone/error/cgp-error-anyhow/README.md b/crates/standalone/error/cgp-error-anyhow/README.md index 7551525b..beda59b1 100644 --- a/crates/standalone/error/cgp-error-anyhow/README.md +++ b/crates/standalone/error/cgp-error-anyhow/README.md @@ -38,9 +38,11 @@ delegate_components! { } } -let error = App::raise_error(std::io::Error::other("disk full")); -let error = App::wrap_error(error, "while saving"); -assert_eq!(format!("{error:#}"), "while saving: disk full"); +fn main() { + let error = App::raise_error(std::io::Error::other("disk full")); + let error = App::wrap_error(error, "while saving"); + assert_eq!(format!("{error:#}"), "while saving: disk full"); +} ``` A `String` needs `DisplayAnyhowError` or `DebugAnyhowError`, because it is not a standard error. diff --git a/crates/standalone/error/cgp-error-eyre/README.md b/crates/standalone/error/cgp-error-eyre/README.md index f1d8b89e..56d3b917 100644 --- a/crates/standalone/error/cgp-error-eyre/README.md +++ b/crates/standalone/error/cgp-error-eyre/README.md @@ -38,9 +38,11 @@ delegate_components! { } } -let error = App::raise_error(std::io::Error::other("disk full")); -let error = App::wrap_error(error, "while saving"); -assert_eq!(format!("{error:#}"), "while saving: disk full"); +fn main() { + let error = App::raise_error(std::io::Error::other("disk full")); + let error = App::wrap_error(error, "while saving"); + assert_eq!(format!("{error:#}"), "while saving: disk full"); +} ``` A `String` needs `DisplayEyreError` or `DebugEyreError`, because it is not a standard error. diff --git a/crates/standalone/error/cgp-error-std/README.md b/crates/standalone/error/cgp-error-std/README.md index 3831ecd4..61446e5b 100644 --- a/crates/standalone/error/cgp-error-std/README.md +++ b/crates/standalone/error/cgp-error-std/README.md @@ -41,10 +41,12 @@ delegate_components! { } } -let error = App::raise_error(std::io::Error::other("disk full")); -let error = App::wrap_error(error, "while saving"); -assert_eq!(format!("{error}"), "while saving"); -assert_eq!(format!("{error:#}"), "while saving: disk full"); +fn main() { + let error = App::raise_error(std::io::Error::other("disk full")); + let error = App::wrap_error(error, "while saving"); + assert_eq!(format!("{error}"), "while saving"); + assert_eq!(format!("{error:#}"), "while saving: disk full"); +} ``` A `WrapError` prints its detail alone with `{}`, so a reporter that walks `source()` prints each diff --git a/crates/tests/cgp-tests/build.rs b/crates/tests/cgp-tests/build.rs index 9a0a5507..2818b2fb 100644 --- a/crates/tests/cgp-tests/build.rs +++ b/crates/tests/cgp-tests/build.rs @@ -1,9 +1,9 @@ //! Turns the wiring example in each error backend's README into a test module, so the //! `error_backends` target compiles and runs the README's own code instead of a copy of it. //! -//! Each README carries one `rust,ignore` block: `use` lines and items, then top-level statements -//! after the last item's closing brace. The block is split there, and the statements become the -//! body of a `#[test]` function, written to `$OUT_DIR/readme_.rs`. +//! Each README carries one `rust,ignore` block: `use` lines and items, then a `fn main()` that +//! runs the example. The block is split there, and the body of `main` becomes the body of a +//! `#[test]` function, written to `$OUT_DIR/readme_.rs`. use std::path::Path; use std::{env, fs}; @@ -42,19 +42,22 @@ fn readme_test(backend: &str, readme: &str) -> Result { .ok_or("no `rust,ignore` block")?; let lines: Vec<&str> = block.lines().collect(); - let split = lines + let main = lines .iter() - .rposition(|line| line.starts_with('}')) - .ok_or("the block has no top-level item")?; + .position(|line| *line == "fn main() {") + .ok_or("the block has no `fn main() {` line")?; + if lines.last() != Some(&"}") { + return Err("the block does not end with the closing brace of `main`"); + } - let items = lines[..=split].join("\n"); - let statements: Vec = lines[split + 1..] + let items = lines[..main].join("\n"); + let statements: Vec<&str> = lines[main + 1..lines.len() - 1] .iter() + .copied() .filter(|line| !line.trim().is_empty()) - .map(|line| format!(" {line}")) .collect(); if statements.is_empty() { - return Err("the block has no statements after its items"); + return Err("`main` has no statements"); } Ok(format!( From 1cc0c0918cb455a39f66e49102b7cdf55d588f5f Mon Sep 17 00:00:00 2001 From: Soares Chen Date: Mon, 16 Nov 2026 23:44:04 +0100 Subject: [PATCH 4/4] Rewrite the crate READMEs' closings as connected prose The READMEs of the crates `cgp` re-exports ended with three single-sentence paragraphs, on the reference pages, on reaching the crate through `cgp`, and on the website, each starting fresh. They now read as two connected paragraphs: how a project reaches the crate and which reference pages cover it, then where to learn CGP itself. The small internal crates' READMEs read the same way, `cgp-core` and `cgp-extra` open with sentences that lead into their examples, and the error backends introduce their provider tables and join the short sentences about `String` errors and `std` features. Co-Authored-By: Claude Opus 5.5 --- crates/core/cgp-base-types/README.md | 14 ++++++-------- crates/core/cgp-component/README.md | 11 +++++------ crates/core/cgp-error/README.md | 11 +++++------ crates/core/cgp-field/README.md | 11 +++++------ crates/core/cgp-type/README.md | 11 +++++------ crates/extra/cgp-dispatch/README.md | 11 +++++------ crates/extra/cgp-error-extra/README.md | 11 +++++------ crates/extra/cgp-field-extra/README.md | 11 +++++------ crates/extra/cgp-handler/README.md | 11 +++++------ crates/extra/cgp-monad/README.md | 13 ++++++------- crates/extra/cgp-run/README.md | 13 ++++++------- crates/extra/cgp-runtime/README.md | 11 +++++------ crates/macros/cgp-async-macro/README.md | 13 ++++++------- crates/macros/cgp-macro-core/README.md | 8 +++----- crates/macros/cgp-macro-extra-core/README.md | 9 ++++----- crates/macros/cgp-macro-extra-lib/README.md | 11 +++++------ crates/macros/cgp-macro-extra/README.md | 11 +++++------ crates/macros/cgp-macro-lib/README.md | 9 ++++----- crates/macros/cgp-macro-test-util-lib/README.md | 12 +++++------- crates/macros/cgp-macro/README.md | 11 +++++------ crates/main/cgp-base-extra/README.md | 14 ++++++-------- crates/main/cgp-base/README.md | 11 +++++------ crates/main/cgp-core/README.md | 17 ++++++++--------- crates/main/cgp-extra/README.md | 15 +++++++-------- .../standalone/error/cgp-error-anyhow/README.md | 10 ++++++---- .../standalone/error/cgp-error-eyre/README.md | 6 ++++-- crates/standalone/error/cgp-error-std/README.md | 10 ++++++---- 27 files changed, 142 insertions(+), 164 deletions(-) diff --git a/crates/core/cgp-base-types/README.md b/crates/core/cgp-base-types/README.md index 693eb24f..69d4aa3a 100644 --- a/crates/core/cgp-base-types/README.md +++ b/crates/core/cgp-base-types/README.md @@ -21,8 +21,10 @@ fn main() { } ``` -The website's reference covers its main items: -[`Symbol!`](https://contextgeneric.dev/docs/reference/macros/symbol), +Projects reach these types through the `cgp` crate, which re-exports them under `cgp::core::base` +and the macros that build them under `cgp::prelude`, so they depend on +[`cgp`](https://crates.io/crates/cgp) alone, as the example does. The website's reference has a page +for each of its main items: [`Symbol!`](https://contextgeneric.dev/docs/reference/macros/symbol), [`Cons`](https://contextgeneric.dev/docs/reference/types/cons), [`Nil`](https://contextgeneric.dev/docs/reference/types/nil), [`Chars`](https://contextgeneric.dev/docs/reference/types/chars), @@ -30,9 +32,5 @@ The website's reference covers its main items: [`StaticFormat`](https://contextgeneric.dev/docs/reference/traits/formatting/static_format), and [`ConcatPath`](https://contextgeneric.dev/docs/reference/traits/formatting/concat_path). -The `cgp` crate re-exports these types under `cgp::core::base`, and the macros that build them under -`cgp::prelude`, so a project depends on [`cgp`](https://crates.io/crates/cgp) alone, as the example -does. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/core/cgp-component/README.md b/crates/core/cgp-component/README.md index 233c59dc..c1d48f08 100644 --- a/crates/core/cgp-component/README.md +++ b/crates/core/cgp-component/README.md @@ -33,7 +33,9 @@ fn main() { } ``` -The website's reference covers its main items: +Projects reach this machinery through the `cgp` crate, which re-exports it as +`cgp::core::component`, so they depend on [`cgp`](https://crates.io/crates/cgp) alone, as the +example does. The website's reference has a page for each of its main items: [`DelegateComponent`](https://contextgeneric.dev/docs/reference/traits/wiring/delegate_component), [`IsProviderFor`](https://contextgeneric.dev/docs/reference/traits/wiring/is_provider_for), [`CanUseComponent`](https://contextgeneric.dev/docs/reference/traits/wiring/can_use_component), @@ -42,8 +44,5 @@ The website's reference covers its main items: [`UseDelegate`](https://contextgeneric.dev/docs/reference/providers/use_delegate), and [`RedirectLookup`](https://contextgeneric.dev/docs/reference/providers/redirect_lookup). -The `cgp` crate re-exports it as `cgp::core::component`, so a project depends on -[`cgp`](https://crates.io/crates/cgp) alone, as the example does. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/core/cgp-error/README.md b/crates/core/cgp-error/README.md index bcb6d7ed..cdd6c700 100644 --- a/crates/core/cgp-error/README.md +++ b/crates/core/cgp-error/README.md @@ -35,13 +35,12 @@ fn main() { } ``` -The website's reference covers its main items: +Projects reach these components through the `cgp` crate, which re-exports them as +`cgp::core::error`, so they depend on [`cgp`](https://crates.io/crates/cgp) alone, as the example +does. The website's reference has a page for each of its main items: [`HasErrorType`](https://contextgeneric.dev/docs/reference/components/has_error_type), [`CanRaiseError`](https://contextgeneric.dev/docs/reference/components/can_raise_error), and [`CanWrapError`](https://contextgeneric.dev/docs/reference/components/can_wrap_error). -The `cgp` crate re-exports it as `cgp::core::error`, so a project depends on -[`cgp`](https://crates.io/crates/cgp) alone, as the example does. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/core/cgp-field/README.md b/crates/core/cgp-field/README.md index df74f7c7..1512345f 100644 --- a/crates/core/cgp-field/README.md +++ b/crates/core/cgp-field/README.md @@ -22,14 +22,13 @@ fn main() { } ``` -The website's reference covers its main items: +Projects reach this field access through the `cgp` crate, which re-exports it as `cgp::core::field`, +so they depend on [`cgp`](https://crates.io/crates/cgp) alone, as the example does. The website's +reference has a page for each of its main items: [`HasField`](https://contextgeneric.dev/docs/reference/traits/field-access/has_field), [`Index`](https://contextgeneric.dev/docs/reference/types/index_type), [`MRef`](https://contextgeneric.dev/docs/reference/types/mref), and the [casts](https://contextgeneric.dev/docs/reference/traits/casting/). -The `cgp` crate re-exports it as `cgp::core::field`, so a project depends on -[`cgp`](https://crates.io/crates/cgp) alone, as the example does. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/core/cgp-type/README.md b/crates/core/cgp-type/README.md index 4a3ac27d..96f11929 100644 --- a/crates/core/cgp-type/README.md +++ b/crates/core/cgp-type/README.md @@ -23,13 +23,12 @@ fn main() { } ``` -The website's reference covers its main items: +Projects reach these types through the `cgp` crate, which re-exports them as `cgp::core::types`, so +they depend on [`cgp`](https://crates.io/crates/cgp) alone, as the example does. The website's +reference has a page for each of its main items: [`HasType`](https://contextgeneric.dev/docs/reference/components/has_type), [`UseType`](https://contextgeneric.dev/docs/reference/providers/use_type), and [`UseDelegatedType`](https://contextgeneric.dev/docs/reference/providers/use_delegated_type). -The `cgp` crate re-exports it as `cgp::core::types`, so a project depends on -[`cgp`](https://crates.io/crates/cgp) alone, as the example does. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/extra/cgp-dispatch/README.md b/crates/extra/cgp-dispatch/README.md index d8cf4c24..736a5fed 100644 --- a/crates/extra/cgp-dispatch/README.md +++ b/crates/extra/cgp-dispatch/README.md @@ -54,14 +54,13 @@ fn main() { } ``` -The website's reference covers its main items: +Projects reach these combinators through the `cgp` crate, which re-exports them as +`cgp::extra::dispatch`, so they depend on [`cgp`](https://crates.io/crates/cgp) alone, as the +example does. The website's reference has a page for each of its main items: [`MatchWithHandlers`](https://contextgeneric.dev/docs/reference/providers/dispatch/match_with_handlers), [`MatchWithValueHandlers`](https://contextgeneric.dev/docs/reference/providers/dispatch/match_with_value_handlers), and [`ExtractFieldAndHandle`](https://contextgeneric.dev/docs/reference/providers/dispatch/extract_field_and_handle). -The `cgp` crate re-exports it as `cgp::extra::dispatch`, so a project depends on -[`cgp`](https://crates.io/crates/cgp) alone, as the example does. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/extra/cgp-error-extra/README.md b/crates/extra/cgp-error-extra/README.md index 0bf2fec9..74e9f176 100644 --- a/crates/extra/cgp-error-extra/README.md +++ b/crates/extra/cgp-error-extra/README.md @@ -34,7 +34,9 @@ fn main() { `alloc` feature, which this example turns on with `cgp = { version = "0.8.0", features = ["alloc"] }`. -The website's reference covers its main items: +Projects reach these providers through the `cgp` crate, which re-exports them as +`cgp::extra::error`, so they depend on [`cgp`](https://crates.io/crates/cgp) alone, as the example +does. The website's reference has a page for each of its main items: [`RaiseFrom`](https://contextgeneric.dev/docs/reference/providers/error/raise_from), [`ReturnError`](https://contextgeneric.dev/docs/reference/providers/error/return_error), [`RaiseInfallible`](https://contextgeneric.dev/docs/reference/providers/error/raise_infallible), @@ -43,8 +45,5 @@ The website's reference covers its main items: [`DebugError`](https://contextgeneric.dev/docs/reference/providers/error/debug_error), and [`DisplayError`](https://contextgeneric.dev/docs/reference/providers/error/display_error). -The `cgp` crate re-exports it as `cgp::extra::error`, so a project depends on -[`cgp`](https://crates.io/crates/cgp) alone, as the example does. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/extra/cgp-field-extra/README.md b/crates/extra/cgp-field-extra/README.md index 7d69ad9c..9ffaf1ba 100644 --- a/crates/extra/cgp-field-extra/README.md +++ b/crates/extra/cgp-field-extra/README.md @@ -29,14 +29,13 @@ fn main() { } ``` -The website's reference covers its main items: +Projects reach this layer through the `cgp` crate, which re-exports it as `cgp::extra::field`, so +they depend on [`cgp`](https://crates.io/crates/cgp) alone, as the example does. The website's +reference has a page for each of its main items: [`HasOptionalBuilder`](https://contextgeneric.dev/docs/reference/traits/optional/has_optional_builder), [`ToOptional`](https://contextgeneric.dev/docs/reference/traits/optional/to_optional), [`SetOptional`](https://contextgeneric.dev/docs/reference/traits/optional/set_optional), and [`FinalizeOptional`](https://contextgeneric.dev/docs/reference/traits/optional/finalize_optional). -The `cgp` crate re-exports it as `cgp::extra::field`, so a project depends on -[`cgp`](https://crates.io/crates/cgp) alone, as the example does. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/extra/cgp-handler/README.md b/crates/extra/cgp-handler/README.md index 487fdd51..681ac792 100644 --- a/crates/extra/cgp-handler/README.md +++ b/crates/extra/cgp-handler/README.md @@ -27,14 +27,13 @@ fn main() { } ``` -The website's reference covers its main items: +Projects reach the handlers through the `cgp` crate, which re-exports them as `cgp::extra::handler`, +so they depend on [`cgp`](https://crates.io/crates/cgp) alone, as the example does. The website's +reference has a page for each of its main items: [`CanCompute`](https://contextgeneric.dev/docs/reference/components/handler/computer), [`CanHandle`](https://contextgeneric.dev/docs/reference/components/handler/handler), [`PipeHandlers`](https://contextgeneric.dev/docs/reference/providers/handler/pipe_handlers), and [`Promote`](https://contextgeneric.dev/docs/reference/providers/handler/promote). -The `cgp` crate re-exports it as `cgp::extra::handler`, so a project depends on -[`cgp`](https://crates.io/crates/cgp) alone, as the example does. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/extra/cgp-monad/README.md b/crates/extra/cgp-monad/README.md index 701b69c7..14c60dc6 100644 --- a/crates/extra/cgp-monad/README.md +++ b/crates/extra/cgp-monad/README.md @@ -1,11 +1,10 @@ # cgp-monad -`cgp-monad` provides the monadic handlers of Context-Generic Programming (CGP), which compose +`cgp-monad` provides the monadic handlers of Context-Generic Programming (CGP). They compose handlers through a monad that decides whether each step runs, such as one that stops a pipeline at -its first error. +its first error. Projects reach them through the `cgp` crate, which re-exports them as +`cgp::extra::monad`, so most depend on [`cgp`](https://crates.io/crates/cgp) alone and never add +this crate to their manifest. -The `cgp` crate re-exports it as `cgp::extra::monad`. Most projects therefore depend on -[`cgp`](https://crates.io/crates/cgp) alone, without adding this crate to their manifest. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/extra/cgp-run/README.md b/crates/extra/cgp-run/README.md index a4e524f6..e6a3e7a3 100644 --- a/crates/extra/cgp-run/README.md +++ b/crates/extra/cgp-run/README.md @@ -1,10 +1,9 @@ # cgp-run -`cgp-run` provides the task runners of Context-Generic Programming (CGP), the components that run a -task named by a type-level code. +`cgp-run` provides the task runners of Context-Generic Programming (CGP): the components that run a +task named by a type-level code. Projects reach them through the `cgp` crate, which re-exports them +as `cgp::extra::run`, so most depend on [`cgp`](https://crates.io/crates/cgp) alone and never add +this crate to their manifest. -The `cgp` crate re-exports it as `cgp::extra::run`. Most projects therefore depend on -[`cgp`](https://crates.io/crates/cgp) alone, without adding this crate to their manifest. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/extra/cgp-runtime/README.md b/crates/extra/cgp-runtime/README.md index 49b0956e..4bfec3f5 100644 --- a/crates/extra/cgp-runtime/README.md +++ b/crates/extra/cgp-runtime/README.md @@ -1,10 +1,9 @@ # cgp-runtime `cgp-runtime` provides the runtime abstraction of Context-Generic Programming (CGP), which lets each -context choose its async runtime while generic code reaches it through a trait. +context choose its async runtime while generic code reaches it through a trait. Projects reach it +through the `cgp` crate, which re-exports it as `cgp::extra::runtime`, so most depend on +[`cgp`](https://crates.io/crates/cgp) alone and never add this crate to their manifest. -The `cgp` crate re-exports it as `cgp::extra::runtime`. Most projects therefore depend on -[`cgp`](https://crates.io/crates/cgp) alone, without adding this crate to their manifest. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/macros/cgp-async-macro/README.md b/crates/macros/cgp-async-macro/README.md index 6cefec54..bcda0144 100644 --- a/crates/macros/cgp-async-macro/README.md +++ b/crates/macros/cgp-async-macro/README.md @@ -26,11 +26,10 @@ fn main() { } ``` -Its reference page on the website is -[`#[async_trait]`](https://contextgeneric.dev/docs/reference/macros/async_trait). +Projects use the macro through `cgp::prelude`, so they depend on +[`cgp`](https://crates.io/crates/cgp) alone, as the example does. The website's reference page for +[`#[async_trait]`](https://contextgeneric.dev/docs/reference/macros/async_trait) describes it in +full. -The `cgp` crate gathers its macro in `cgp::prelude`, so a project depends on -[`cgp`](https://crates.io/crates/cgp) alone, as the example does. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/macros/cgp-macro-core/README.md b/crates/macros/cgp-macro-core/README.md index 0dc50f56..5c69c14a 100644 --- a/crates/macros/cgp-macro-core/README.md +++ b/crates/macros/cgp-macro-core/README.md @@ -2,9 +2,7 @@ `cgp-macro-core` holds the shared core of the procedural macros of Context-Generic Programming (CGP): the syntax trees, parsers, visitors, and code-generation helpers that the macro crates build -on. +on. Projects use the macros through `cgp::prelude`, so they have no reason to depend on this crate. -Projects use the macros through `cgp::prelude` and have no reason to depend on this crate. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/macros/cgp-macro-extra-core/README.md b/crates/macros/cgp-macro-extra-core/README.md index b9be0543..e95906dd 100644 --- a/crates/macros/cgp-macro-extra-core/README.md +++ b/crates/macros/cgp-macro-extra-core/README.md @@ -2,9 +2,8 @@ `cgp-macro-extra-core` holds the shared core of the extra procedural macros of Context-Generic Programming (CGP): the syntax trees, parsers, and visitors behind `#[cgp_computer]`, -`#[cgp_producer]`, and `#[cgp_auto_dispatch]`. +`#[cgp_producer]`, and `#[cgp_auto_dispatch]`. Projects use the macros through `cgp::prelude`, so +they have no reason to depend on this crate. -Projects use the macros through `cgp::prelude` and have no reason to depend on this crate. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/macros/cgp-macro-extra-lib/README.md b/crates/macros/cgp-macro-extra-lib/README.md index 1358d2f6..581e3c97 100644 --- a/crates/macros/cgp-macro-extra-lib/README.md +++ b/crates/macros/cgp-macro-extra-lib/README.md @@ -1,9 +1,8 @@ # cgp-macro-extra-lib -`cgp-macro-extra-lib` implements the extra procedural macros of Context-Generic Programming (CGP) -that `cgp-macro-extra` exports: `#[cgp_computer]`, `#[cgp_producer]`, and `#[cgp_auto_dispatch]`. +`cgp-macro-extra-lib` implements the extra procedural macros of Context-Generic Programming (CGP), +`#[cgp_computer]`, `#[cgp_producer]`, and `#[cgp_auto_dispatch]`, which `cgp-macro-extra` exports. +Projects use the macros through `cgp::prelude`, so they have no reason to depend on this crate. -Projects use the macros through `cgp::prelude` and have no reason to depend on this crate. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/macros/cgp-macro-extra/README.md b/crates/macros/cgp-macro-extra/README.md index b931c771..c8f23a8c 100644 --- a/crates/macros/cgp-macro-extra/README.md +++ b/crates/macros/cgp-macro-extra/README.md @@ -44,13 +44,12 @@ fn main() { } ``` -The website's reference covers its main items: +Projects use these macros through `cgp::prelude`, so they depend on +[`cgp`](https://crates.io/crates/cgp) alone, as the example does. The website's reference has a page +for each of its main items: [`#[cgp_computer]`](https://contextgeneric.dev/docs/reference/macros/cgp_computer), [`#[cgp_producer]`](https://contextgeneric.dev/docs/reference/macros/cgp_producer), and [`#[cgp_auto_dispatch]`](https://contextgeneric.dev/docs/reference/macros/cgp_auto_dispatch). -The `cgp` crate gathers its macros in `cgp::prelude`, so a project depends on -[`cgp`](https://crates.io/crates/cgp) alone, as the example does. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/macros/cgp-macro-lib/README.md b/crates/macros/cgp-macro-lib/README.md index c3933783..bf44f85a 100644 --- a/crates/macros/cgp-macro-lib/README.md +++ b/crates/macros/cgp-macro-lib/README.md @@ -1,9 +1,8 @@ # cgp-macro-lib `cgp-macro-lib` implements the procedural macros of Context-Generic Programming (CGP), one module -per macro. The `cgp-macro` crate exports them. +per macro, and the `cgp-macro` crate exports them. Projects use the macros through `cgp::prelude`, +so they have no reason to depend on this crate. -Projects use the macros through `cgp::prelude` and have no reason to depend on this crate. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/macros/cgp-macro-test-util-lib/README.md b/crates/macros/cgp-macro-test-util-lib/README.md index 49901ada..e0921b15 100644 --- a/crates/macros/cgp-macro-test-util-lib/README.md +++ b/crates/macros/cgp-macro-test-util-lib/README.md @@ -1,10 +1,8 @@ # cgp-macro-test-util-lib -`cgp-macro-test-util-lib` implements the snapshot-testing macros of Context-Generic Programming -(CGP) that `cgp-macro-test-util` exports. CGP's own tests use them to emit the code a CGP macro -generates and pin it as an inline snapshot. +`cgp-macro-test-util-lib` implements the snapshot-testing macros that `cgp-macro-test-util` exports. +The tests of Context-Generic Programming (CGP) use them to emit the code a CGP macro generates and +pin it as an inline snapshot, so a project that uses CGP has no reason to depend on this crate. -Projects that use CGP have no reason to depend on this crate. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/macros/cgp-macro/README.md b/crates/macros/cgp-macro/README.md index b10170a8..a7985819 100644 --- a/crates/macros/cgp-macro/README.md +++ b/crates/macros/cgp-macro/README.md @@ -35,14 +35,13 @@ fn main() { } ``` -The website's reference covers its main items: +Projects use these macros through `cgp::prelude`, so they depend on +[`cgp`](https://crates.io/crates/cgp) alone, as the example does. The website's reference has a page +for each of its main items: [`#[cgp_component]`](https://contextgeneric.dev/docs/reference/macros/cgp_component), [`#[cgp_impl]`](https://contextgeneric.dev/docs/reference/macros/cgp_impl), [`delegate_components!`](https://contextgeneric.dev/docs/reference/macros/delegate_components), and [`check_components!`](https://contextgeneric.dev/docs/reference/macros/check_components). -The `cgp` crate gathers its macros in `cgp::prelude`, so a project depends on -[`cgp`](https://crates.io/crates/cgp) alone, as the example does. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/main/cgp-base-extra/README.md b/crates/main/cgp-base-extra/README.md index eb0705e2..72f316b2 100644 --- a/crates/main/cgp-base-extra/README.md +++ b/crates/main/cgp-base-extra/README.md @@ -1,11 +1,9 @@ # cgp-base-extra -`cgp-base-extra` gathers the base layer of Context-Generic Programming (CGP) together with its -abstract types, the foundation that CGP's error components are built on. +`cgp-base-extra` adds the abstract types of Context-Generic Programming (CGP) to CGP's base layer, +the foundation CGP's error components are built on. It is an internal layer of the `cgp` crate, +which re-exports everything it holds under `cgp::core`, so most projects depend on +[`cgp`](https://crates.io/crates/cgp) alone and never add this crate to their manifest. -It is an internal layer of the `cgp` crate, which re-exports everything it holds under `cgp::core`. -Most projects therefore depend on [`cgp`](https://crates.io/crates/cgp) alone, without adding this -crate to their manifest. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/main/cgp-base/README.md b/crates/main/cgp-base/README.md index 4fe32da7..de30c745 100644 --- a/crates/main/cgp-base/README.md +++ b/crates/main/cgp-base/README.md @@ -1,10 +1,9 @@ # cgp-base `cgp-base` gathers the base layer of Context-Generic Programming (CGP): the type-level primitives, -the component machinery, and the procedural macros, which CGP's higher layers build on. +the component machinery, and the procedural macros that CGP's higher layers build on. Projects reach +it through the `cgp` crate, which re-exports it as `cgp::core::base`, so most depend on +[`cgp`](https://crates.io/crates/cgp) alone and never add this crate to their manifest. -The `cgp` crate re-exports it as `cgp::core::base`. Most projects therefore depend on -[`cgp`](https://crates.io/crates/cgp) alone, without adding this crate to their manifest. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/main/cgp-core/README.md b/crates/main/cgp-core/README.md index c00063f6..b87bf357 100644 --- a/crates/main/cgp-core/README.md +++ b/crates/main/cgp-core/README.md @@ -1,8 +1,8 @@ # cgp-core -`cgp-core` gathers the core of [Context-Generic Programming (CGP)](https://contextgeneric.dev/), -which extends Rust with pluggable trait implementations chosen at compile time: the base layer and -the procedural macros, the `#[async_trait]` macro, and the error, field, and abstract-type +[Context-Generic Programming (CGP)](https://contextgeneric.dev/) extends Rust with pluggable trait +implementations chosen at compile time, and `cgp-core` gathers the core it rests on: the base layer +and the procedural macros, the `#[async_trait]` macro, and the error, field, and abstract-type components. A `#[cgp_fn]` function, for example, reads its arguments from the context's fields: ```rust,ignore @@ -25,13 +25,12 @@ fn main() { } ``` -The website's reference covers its main items: +Projects reach `cgp-core` through the `cgp` crate, which re-exports it as `cgp::core`, so they +depend on [`cgp`](https://crates.io/crates/cgp) alone, as the example does. The website's reference +has a page for each of its main items: [`#[cgp_component]`](https://contextgeneric.dev/docs/reference/macros/cgp_component), [`HasField`](https://contextgeneric.dev/docs/reference/traits/field-access/has_field), and [`HasErrorType`](https://contextgeneric.dev/docs/reference/components/has_error_type). -The `cgp` crate re-exports it as `cgp::core`, so a project depends on -[`cgp`](https://crates.io/crates/cgp) alone, as the example does. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/main/cgp-extra/README.md b/crates/main/cgp-extra/README.md index d9e1b8c7..e9062042 100644 --- a/crates/main/cgp-extra/README.md +++ b/crates/main/cgp-extra/README.md @@ -3,8 +3,8 @@ `cgp-extra` gathers the features [Context-Generic Programming (CGP)](https://contextgeneric.dev/) builds on its pluggable trait implementations: the handlers and the dispatch and monadic combinators that compose them, task runners and the runtime abstraction, the optional-field builders, and the -generic error providers. Its `alloc` feature turns on the providers that need an allocator. A -handler pipeline, for example, runs one computer after another: +generic error providers, two of which format an error into a `String` and so need the `alloc` +feature. A handler pipeline, for example, runs one computer after another: ```rust,ignore use cgp::extra::handler::{CanCompute, Computer, ComputerComponent, PipeHandlers}; @@ -37,13 +37,12 @@ fn main() { } ``` -The website's reference covers its main items: +Projects reach `cgp-extra` through the `cgp` crate, which re-exports it as `cgp::extra`, so they +depend on [`cgp`](https://crates.io/crates/cgp) alone, as the example does. The website's reference +has a page for each of its main items: [`CanHandle`](https://contextgeneric.dev/docs/reference/components/handler/handler), [`PipeHandlers`](https://contextgeneric.dev/docs/reference/providers/handler/pipe_handlers), and [`RaiseFrom`](https://contextgeneric.dev/docs/reference/providers/error/raise_from). -The `cgp` crate re-exports it as `cgp::extra`, so a project depends on -[`cgp`](https://crates.io/crates/cgp) alone, as the example does. - -The [CGP website](https://contextgeneric.dev/) teaches CGP from a first program to the reference for -each construct, and the [`cgp` crate's documentation](https://docs.rs/cgp) covers the API. \ No newline at end of file +To learn CGP itself, the [CGP website](https://contextgeneric.dev/) starts from a first program, and +the [`cgp` crate's documentation](https://docs.rs/cgp) covers the whole API. diff --git a/crates/standalone/error/cgp-error-anyhow/README.md b/crates/standalone/error/cgp-error-anyhow/README.md index beda59b1..6683d1b1 100644 --- a/crates/standalone/error/cgp-error-anyhow/README.md +++ b/crates/standalone/error/cgp-error-anyhow/README.md @@ -11,6 +11,8 @@ that raise errors into it and add context to it. Code written against `HasErrorT **[Website](https://contextgeneric.dev/) · [Modular error handling](https://contextgeneric.dev/docs/concepts/modular-error-handling) · [The error components](https://contextgeneric.dev/docs/reference/components/has_error_type)** +Each provider goes into the wiring under the components its row names: + | Provider | Wire it to | What it does | |---|---|---| | `UseAnyhowError` | `ErrorTypeProviderComponent` | sets the context's `Error` to `anyhow::Error` | @@ -45,10 +47,10 @@ fn main() { } ``` -A `String` needs `DisplayAnyhowError` or `DebugAnyhowError`, because it is not a standard error. -`DebugAnyhowError` prints it with quotes. The crate is `no_std` and builds anyhow without its `std` -feature. Enabling that feature elsewhere in the dependency graph turns on the parts of anyhow that -need `std`, such as backtrace capture. +A `String` is not a standard error, so it needs `DisplayAnyhowError` or `DebugAnyhowError`, and the +debug form prints it with quotes. The crate itself is `no_std` and builds anyhow without its `std` +feature. When another crate in the dependency graph enables that feature, the parts of anyhow that +need `std`, such as backtrace capture, turn on as well. The crate re-exports `anyhow::Error` as `cgp_error_anyhow::Error`. diff --git a/crates/standalone/error/cgp-error-eyre/README.md b/crates/standalone/error/cgp-error-eyre/README.md index 56d3b917..e1421da9 100644 --- a/crates/standalone/error/cgp-error-eyre/README.md +++ b/crates/standalone/error/cgp-error-eyre/README.md @@ -11,6 +11,8 @@ that raise errors into it and add context to it. Code written against `HasErrorT **[Website](https://contextgeneric.dev/) · [Modular error handling](https://contextgeneric.dev/docs/concepts/modular-error-handling) · [The error components](https://contextgeneric.dev/docs/reference/components/has_error_type)** +Each provider goes into the wiring under the components its row names: + | Provider | Wire it to | What it does | |---|---|---| | `UseEyreError` | `ErrorTypeProviderComponent` | sets the context's `Error` to `eyre::Report` | @@ -45,8 +47,8 @@ fn main() { } ``` -A `String` needs `DisplayEyreError` or `DebugEyreError`, because it is not a standard error. -`DebugEyreError` prints it with quotes. +A `String` is not a standard error, so it needs `DisplayEyreError` or `DebugEyreError`, and the +debug form prints it with quotes. The crate enables eyre's `auto-install` feature, so eyre's default report handler is installed the first time a report is built. To use another handler, such as `color-eyre`, install it with diff --git a/crates/standalone/error/cgp-error-std/README.md b/crates/standalone/error/cgp-error-std/README.md index 61446e5b..cb7b93ac 100644 --- a/crates/standalone/error/cgp-error-std/README.md +++ b/crates/standalone/error/cgp-error-std/README.md @@ -11,6 +11,9 @@ and `alloc`, so it suits a `no_std` context that still wants an open-ended error **[Website](https://contextgeneric.dev/) · [Modular error handling](https://contextgeneric.dev/docs/concepts/modular-error-handling) · [The error components](https://contextgeneric.dev/docs/reference/components/has_error_type)** +The providers go into the wiring under the components their rows name, and the last three rows +are the types they build: + | Item | Wire it to | What it does | |---|---|---| | `UseBoxedStdError` | `ErrorTypeProviderComponent` | sets the context's `Error` to `cgp_error_std::Error` | @@ -49,8 +52,7 @@ fn main() { } ``` -A `WrapError` prints its detail alone with `{}`, so a reporter that walks `source()` prints each -message once, and prints the whole chain with `{:#}` or `{:?}`. A `String` needs -`DisplayBoxedStdError` or `DebugBoxedStdError`, because it is not a standard error, and -`DebugBoxedStdError` prints it with quotes. +A `WrapError` prints only its detail with `{}`, so a reporter that walks `source()` prints each +message once, while `{:#}` and `{:?}` print the whole chain. A `String` is not a standard error, so +it needs `DisplayBoxedStdError` or `DebugBoxedStdError`, and the debug form prints it with quotes.