You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: blog/2025-01-09-v0.3.0-release.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,33 +9,33 @@ I'm excited to announce the release of [v0.3.0](https://github.com/contextgeneri
9
9
10
10
<!-- truncate -->
11
11
12
-
# New Book Chapters
12
+
##New Book Chapters
13
13
14
14
We’ve added a few new chapters to the [CGP Patterns](https://patterns.contextgeneric.dev/) book. Below is a brief summary of the newly published content.
15
15
16
-
## Associated Types
16
+
###Associated Types
17
17
18
18
In the [launch announcement](/blog/early-preview-announcement/) for CGP, some readers remarked that CGP seemed to be primarily a dependency injection framework in Rust. While this observation captured part of its functionality, a key feature not yet covered was CGP's ability to use _abstract types_ in conjunction with the dependency injection of _types_.
19
19
20
20
In the [new chapter](https://patterns.contextgeneric.dev/associated-types.html) of the book, we explore this powerful feature with a motivating example: implementing a context-generic authentication token validator that is not only generic over the `Context` but also over abstract `Time` and `AuthToken` types. The chapter also demonstrates how to use the `cgp_type!` macro to streamline the declaration of abstract type traits and how to employ `UseType` in component wiring to instantiate abstract types.
21
21
22
-
## Error Handling
22
+
###Error Handling
23
23
24
24
CGP introduces a novel approach to error handling that differs significantly from the conventional patterns used in Rust today. In the [new chapter](https://patterns.contextgeneric.dev/error-handling.html) of the book, we begin by leveraging an abstract `Error` type from `HasErrorType` to define error-returning method signatures. The chapter then delves into how `CanRaiseError` and `CanWrapError` can be used to produce abstract errors within context-generic provider implementations. Further, the chapter discusses how to define context-generic error raisers and leverage the `UseDelegate` pattern for static dispatching of error handling to various providers.
25
25
26
-
## Field Accessors
26
+
###Field Accessors
27
27
28
28
CGP provides a robust mechanism for dependency injection using [impl-side dependencies](https://patterns.contextgeneric.dev/impl-side-dependencies.html). However, since these dependencies are expressed through traits and constraints, we need to define _accessor traits_ to retrieve field values from a generic context.
29
29
30
30
In the [new chapter](https://patterns.contextgeneric.dev/field-accessors.html), we explore different approaches for defining, using, and implementing accessor traits in CGP. This chapter explains how the `#[derive(HasField)]` macro operates and dives into the internal workings of `HasField` and `Symbol!`. It also introduces the` #[cgp_auto_getter]` and `#[cgp_getter]` macros, which automatically generate accessor provider implementations that work with `HasField`.
31
31
32
-
# `cgp` v0.3.0 Release
32
+
##`cgp` v0.3.0 Release
33
33
34
-
The `cgp` crate has been upgraded from `v0.2.0` to `v0.3.0`, introducing new features that significantly enhance usability and include minor breaking changes. You can view the full [release notes here](https://github.com/contextgeneric/cgp/releases/tag/v0.3.0). Additionally, the [Hello World example](/#hello-world-example) on the project homepage has been updated to showcase a simplified implementation using the latest CGP constructs.
34
+
The `cgp` crate has been upgraded from `v0.2.0` to `v0.3.0`, introducing new features that significantly enhance usability and include minor breaking changes. You can view the full [release notes here](https://github.com/contextgeneric/cgp/releases/tag/v0.3.0). Additionally, the [Hello World example](/docs/tutorials/hello) on the project homepage has been updated to showcase a simplified implementation using the latest CGP constructs.
35
35
36
36
Below is a summary of key updates in this release.
37
37
38
-
## `cgp_type!` Macro
38
+
###`cgp_type!` Macro
39
39
40
40
The new `cgp_type!` macro streamlines the process of declaring abstract type traits, enabling you to define them in a single line of code. For instance, the `HasErrorType` trait in `cgp` is now defined as:
41
41
@@ -64,7 +64,7 @@ where
64
64
65
65
For a detailed explanation of cgp_type! and its usage, check out the new [Associated Types](https://patterns.contextgeneric.dev/associated-types.html#defining-abstract-type-traits-with-cgp_type) chapter in the CGP Patterns book.
66
66
67
-
## `#[cgp_auto_getter]` Macro
67
+
###`#[cgp_auto_getter]` Macro
68
68
69
69
The `#[cgp_auto_getter]` macro simplifies the process of defining accessor traits with blanket implementations based on `HasField`. When a trait is marked with `#[cgp_auto_getter]`, any context deriving `HasField` that has the required fields and types will automatically implement the specified trait without additional boilerplate.
70
70
@@ -96,7 +96,7 @@ In this example, the `Person` struct derives the `HasField` trait, which automat
96
96
97
97
For more details on `#[cgp_auto_getter]`, refer to the [Generic Accessor Providers](https://patterns.contextgeneric.dev/generic-accessor-providers.html#the-cgp_auto_getter-macro) chapter in the CGP Patterns book.
98
98
99
-
## `#[cgp_getter]` Macro
99
+
###`#[cgp_getter]` Macro
100
100
101
101
The `#[cgp_getter]` macro, like `#[cgp_auto_getter]`, generates blanket implementations that make use of `HasField`. However, `#[cgp_getter]` extends functionality by also creating full CGP constructs for the trait, similar to `#[cgp_component]`. This requires explicit wiring in the context using `delegate_components!`. Additionally, `#[cgp_getter]` derives a blanket implementation for the `UseFields` provider, so that it can be used inside the component wiring as follows:
102
102
@@ -138,7 +138,7 @@ fn main() {
138
138
139
139
For additional information on `#[cgp_getter]`, refer to the [Generic Accessor Providers](https://patterns.contextgeneric.dev/generic-accessor-providers.html#the-cgp_getter-macro) chapter of the CGP Patterns book.
140
140
141
-
## `CanWrapError` Trait
141
+
###`CanWrapError` Trait
142
142
143
143
The `CanWrapError` trait has been introduced to streamline the process of wrapping existing errors. Its definition is as follows:
144
144
@@ -155,13 +155,13 @@ Previously, error wrapping relied on using `CanRaiseError` with a tuple, such as
155
155
156
156
For more details about the usage of `CanWrapError`, refer to the [Error Wrapping](https://patterns.contextgeneric.dev/error-wrapping.html) chapter in the CGP Patterns book.
157
157
158
-
## `cgp-error-anyhow` Crate
158
+
###`cgp-error-anyhow` Crate
159
159
160
160
We have published a new [`cgp-error-anyhow`](https://docs.rs/cgp-error-anyhow/0.3.0/cgp_error_anyhow/index.html) crate, which provides context-generic error raisers for `anyhow::Error`. This addition complements the previously published [`cgp-error-eyre`](https://docs.rs/cgp-error-eyre/0.3.0/cgp_error_eyre/index.html) and [`cgp-error-std`](https://docs.rs/cgp-error-std/0.3.0/cgp_error_std/index.html) crates, which support CGP error handling with `eyre::Error` and `Box<dyn core::error::Error + Send + Sync + 'static>`. Given the popularity of `anyhow::Error`, this crate extends support for its usage.
161
161
162
162
Details on using `cgp-error-anyhow` for error handling can be found in the [Error Handling](https://patterns.contextgeneric.dev/error-handling.html#the-cgp-error-anyhow-crate) chapter of the CGP Patterns book.
163
163
164
-
## `cgp-runtime` Crate
164
+
###`cgp-runtime` Crate
165
165
166
166
The new [`cgp-runtime`](https://docs.rs/cgp-runtime/0.3.0/cgp_runtime/index.html) crate introduces standardized interfaces for runtimes, paving the way for future discussions on asynchronous programming in the CGP Patterns book.
Stay tuned for updates to the CGP Patterns book for more information on using pluggable async runtimes with CGP.
182
182
183
-
# Future Work
183
+
##Future Work
184
184
185
185
There are several additional features and improvements I had hoped to include in this update. However, with my New Year vacation coming to an end, I need to wrap up the current progress. Below are some of the tasks deferred to future updates.
186
186
187
-
## Documenting the `cgp` Crate
187
+
###Documenting the `cgp` Crate
188
188
189
189
While the CGP Patterns book offers extensive conceptual coverage, the `cgp` crate currently lacks comprehensive Rustdoc documentation. Many constructs remain undocumented, and users must rely on the CGP Patterns book or this website for detailed guidance.
190
190
191
191
In future updates, I plan to add concise Rustdoc comments to these constructs and include links to relevant chapters in the CGP Patterns book. This will help bridge the gap and provide in-crate documentation to enhance usability. For now, all detailed information about CGP is accessible only through the book and website.
192
192
193
-
## Tutorials with More Complex Use Cases
193
+
###Tutorials with More Complex Use Cases
194
194
195
195
During the [launch announcement](/blog/early-preview-announcement/), many readers noted the lack of practical examples demonstrating how CGP can address more complex, real-world problems. While I had planned to create such tutorials, much of my time was spent completing relevant chapters and updating the `cgp` crate. I ask for your patience as I work on delivering concise, compelling examples to better illustrate CGP's utility.
196
196
197
197
In the meantime, the simplified examples in the recently added [Associated Types](https://patterns.contextgeneric.dev/associated-types.html), [Error Handling](https://patterns.contextgeneric.dev/error-handling.html), and [Field Accessors](https://patterns.contextgeneric.dev/field-accessors.html) chapters provide a glimpse into CGP's practical applications. These include examples like validating whether an authentication token has expired and making HTTP API calls to fetch messages. While not exhaustive, these examples go beyond the basic "Hello World" tutorial on the homepage and offer a clearer picture of how CGP can be applied to your projects.
198
198
199
-
# Acknowledgement
199
+
##Acknowledgement
200
200
201
201
A big thank you to [@marvin-hansen](https://github.com/marvin-hansen) for his enthusiastic involvement in discussions, testing CGP with real-world projects, and providing invaluable feedback! The implementation of the `#[cgp_getter]` and `#[cgp_auto_getter]` macros was primarily motivated by his input, highlighting that the direct use of `HasField` could be too complex for beginners. Thanks to his suggestions, CGP now offers a more seamless and intuitive experience for declaring and using field accessor traits.
0 commit comments