Skip to content

Commit 216993e

Browse files
authored
Update book chapters outline (#12)
1 parent a9b419e commit 216993e

File tree

5 files changed

+66
-45
lines changed

5 files changed

+66
-45
lines changed

content/SUMMARY.md

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
- [Introduction](introduction.md)
44

5-
# Core Concepts
5+
# Terminology
66

77
- [Context](context.md)
88
- [Consumer](consumer.md)
99
- [Provider](provider.md)
1010

11-
# Basic Patterns
11+
# Core Concepts
1212

1313
- [Blanket Implementations](blanket-implementations.md)
1414
- [Impl-side Dependencies](impl-side-dependencies.md)
@@ -20,35 +20,43 @@
2020

2121
# Design Patterns
2222

23-
- [Context-Generic Providers](context-generic-providers.md)
24-
- [Provider Middleware](provider-middleware.md)
25-
- [Associated Contexts](associated-contexts.md)
26-
- [Impl-side Generic Types](impl-side-generic-types.md)
27-
- [Associated Type Specialization](associated-type-specialization.md)
28-
- [Async Generic](async-generic.md)
29-
- [Fully Abstract Programs](fully-abstract-programs.md)
23+
- [Associated Types]()
24+
- [Parameterized Associated Types]()
25+
- [Impl-side Generic Types]()
26+
- [Associated Type Specialization]()
27+
- [`HasType`]()
28+
- [Error Handling]()
29+
- [`HasErrorType`]()
30+
- [From Errors]()
31+
- [`CanRaiseError`]()
32+
- [Provider Composition]()
33+
- [Provider Middleware]()
34+
- [Generalized Providers]()
35+
- [`WithProvider`]()
36+
- [`UseContext`]()
37+
- [`UseType`]()
38+
- [`UseDelegate`]()
39+
- [Field Accessors]()
40+
- [`HasField`]()
41+
- [`HasFieldMut`]()
42+
- [Field Macros]()
43+
- [Context-Generic Dispatch]()
44+
- [App-Specific Associated Types]()
45+
- [Async Generic]()
46+
- [Fully Abstract Programs]()
3047

3148
# Domain-Specific Patterns
3249

33-
- [Error Handling](error-handling.md)
34-
- [Abstract Error Types](abstract-error-types.md)
35-
- [From Errors](from-errors.md)
36-
- [Error Raisers](error-raisers.md)
37-
- [Error Detail Types](error-detail-types.md)
38-
- [Error Handler Delegation](error-handler-delegation.md)
39-
40-
- [Logging and Telemetry](logging-and-telemetry.md)
41-
- [Abstract Logger](abstract-logger.md)
42-
- [Logging Entry Types](logging-entry-types.md)
43-
- [Logger Delegation](logger-delegation.md)
50+
- [Logging and Telemetry]()
51+
- [Encoding]()
4452

4553
# Related Concepts
4654

47-
- [Object-Oriented Programming](object-oriented-programming.md)
48-
- [Dependency Injection](dependency-injection.md)
49-
- [Dynamic-Typed Programming](dynamic-typed-programming.md)
50-
- [Functional Programming](functional-programming.md)
51-
- [New Type Wrappers](new-type-wrappers.md)
52-
- [Monad](monad.md)
53-
- [Algebraic Effects](algebraic-effects.md)
54-
- [ML Modules](ml-modules.md)
55+
- [Object-Oriented Programming]()
56+
- [Dependency Injection]()
57+
- [Dynamic-Typed Programming]()
58+
- [Functional Programming]()
59+
- [New Type Wrappers]()
60+
- [Monad]()
61+
- [Algebraic Effects]()
62+
- [ML Modules]()

content/associated-contexts.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

content/associated-types.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Associated Types

content/debugging-techniques.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
By leveraging [impl-side dependencies](./impl-side-dependencies.md), CGP providers
44
are able to include additional dependencies that are not specified in the provider
5-
trait. We have already seen this in action in the [previous chapter](./provider-delegation.md),
6-
for example where the provider `FormatAsJsonString` is able to require `Context`
5+
trait. We have already seen this in action in the [previous chapter](./provider-delegation.md), for example,
6+
where the provider `FormatAsJsonString` is able to require `Context`
77
to implement `Serialize`, while that is not specified anywhere in the provider
88
trait `StringFormatter`.
99

@@ -22,8 +22,8 @@ try to use a consumer trait against a concrete context.
2222
## Unsatisfied Dependency Errors
2323

2424
To demonstrate how such error would arise, we would reuse the same example
25-
`PersonContext` as the [previous chapter](./component-macros.md#example-use).
26-
Consider if we made a mistake and forgot to implement `Serialize` for `PersonContext`:
25+
`Person` context as the [previous chapter](./component-macros.md#example-use).
26+
Consider if we made a mistake and forgot to implement `Serialize` for `Person`:
2727

2828
```rust
2929
# extern crate anyhow;
@@ -88,9 +88,9 @@ delegate_components! {
8888
}
8989
```
9090

91-
We know that `PersonContext` uses `PersonComponents` to implement `CanFormatToString`,
91+
We know that `Person` uses `PersonComponents` to implement `CanFormatToString`,
9292
and `PersonComponents` delegates the provider implementation to `FormatAsJsonString`.
93-
However, since `FormatAsJsonString` requires `PersonContext` to implement `Serialize`,
93+
However, since `FormatAsJsonString` requires `Person` to implement `Serialize`,
9494
without it `CanFormatToString` cannot be implemented on `PersonContext`.
9595

9696
However, notice that the above code still compiles successfully. This is because we

content/introduction.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ to be implemented and composed in a modular, generic, and type-safe way.
66

77
## What is Context-Generic Programming
88

9-
At its core, CGP makes use of Rust's trait system to build generic _interfaces_
10-
decouple code that _consumes_ an interface from code that _implements_ an
11-
interface. Through this decoupling, code can be written to be generic over
12-
any context, and then be wired to be used on a concrete context by writing
13-
few lines of code. CGP makes use of Rust's strong type system to help ensure
14-
that any such wiring is _type-safe_, catching any unsatisfied dependencies
15-
as compile-time errors.
9+
At its core, CGP makes use of Rust's trait system to build generic
10+
component _interfaces_ that decouple code that _consumes_ an interface
11+
from code that _implements_ an interface.
12+
Through this decoupling, code can be written to be generic over any context,
13+
and then be wired to be used on a concrete context by writing few lines of code.
14+
CGP makes use of Rust's strong type system to help ensure that any such
15+
wiring is _type-safe_, catching any unsatisfied dependencies as compile-time errors.
1616

1717
CGP shares some similarities with other modular programming patterns, such as
1818
OCaml modules, Scala implicits, mixins, and dependency injection. Compared to
@@ -21,6 +21,19 @@ while also being type-safe and concise. With Rust as its host language, CGP
2121
also allows high-performance and low-level code to be written in a modular
2222
way, without requiring complex runtime support.
2323

24+
CGP is designed to solve a wide range of common problems in programming,
25+
including error handling, logging, encoding, and modular dispatch.
26+
In particular, it allows writing static-typed Rust programs to be almost
27+
as expressive as writing dynamic-typed programs, but with the additional
28+
type safety guarantees.
29+
If you ever feel that Rust's type system is restricting your ability to reuse
30+
code, or be forced to duplicate code through copy-pasting or macros, then
31+
CGP may be of help to solve your problem.
32+
33+
That said, programming in CGP is as expressive, but not as easy,
34+
as dynamic-typed programming. There may be a steep learning curve
35+
in learning how to program in a generic way, and this book aims to help
36+
make that learning process more approachable.
2437
Thoughout this book, we will slowly understand how CGP works, and learn about
2538
useful design patterns that can be used in any programming situation.
2639

@@ -43,11 +56,11 @@ that covers real world use of CGP.
4356

4457
## Chapter Outlines
4558

46-
The first section of this book, _Core Concepts_, will introduce core concepts of CGP.
59+
The first section of this book, _Terminology_, will introduce common terms to be used to understand CGP.
4760
We will learn about what is a context, and what are consumer and provider traits.
4861

49-
In the next section, _Basic Patterns_, we will cover the basic design patterns that enable us to write
50-
context-generic code.
62+
In the next section, _Core Concepts_, we will cover the core concepts and the Rust-specific
63+
design patterns that we use to enable context-generic programming.
5164

5265
Following that, _Design Patterns_ will introduce general design patterns that are built on top of the
5366
foundation of context-generic programming.

0 commit comments

Comments
 (0)