Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 52 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ itertools = "0.11.0"
serde = {version = "1", features = ["derive"] }
serde_json = "1"
anyhow = "1"
cgp = { version = "0.1.0" }
cgp = { version = "0.2.0" }
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

This repository contains the source code for the book _Context-Generic Programming Patterns_. The published version of this book is available at https://patterns.contextgeneric.dev/.

For more information about context-generic programming, check out the
main website at https://www.contextgeneric.dev/.

## Build Instructions

This book is built using [mdBook](https://rust-lang.github.io/mdBook/). Follow the [installation instructions](https://rust-lang.github.io/mdBook/guide/installation.html) to install mdBook on your machine. You can then serve a local version of the book by running:
Expand Down
12 changes: 10 additions & 2 deletions content/component-macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,20 @@ use serde::{Serialize, Deserialize};

// Component definitions

#[derive_component(StringFormatterComponent, StringFormatter<Context>)]
#[cgp_component {
name: StringFormatterComponent,
provider: StringFormatter,
context: Context,
}]
pub trait CanFormatToString {
fn format_to_string(&self) -> Result<String, Error>;
}

#[derive_component(StringParserComponent, StringParser<Context>)]
#[cgp_component {
name: StringParserComponent,
provider: StringParser,
context: Context,
}]
pub trait CanParseFromString: Sized {
fn parse_from_string(raw: &str) -> Result<Self, Error>;
}
Expand Down
48 changes: 40 additions & 8 deletions content/debugging-techniques.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,20 @@ Consider if we made a mistake and forgot to implement `Serialize` for `Person`:
# use anyhow::Error;
# use serde::{Serialize, Deserialize};
#
# #[derive_component(StringFormatterComponent, StringFormatter<Context>)]
# #[cgp_component {
# name: StringFormatterComponent,
# provider: StringFormatter,
# context: Context,
# }]
# pub trait CanFormatToString {
# fn format_to_string(&self) -> Result<String, Error>;
# }
#
# #[derive_component(StringParserComponent, StringParser<Context>)]
# #[cgp_component {
# name: StringParserComponent,
# provider: StringParser,
# context: Context,
# }]
# pub trait CanParseFromString: Sized {
# fn parse_from_string(raw: &str) -> Result<Self, Error>;
# }
Expand Down Expand Up @@ -108,12 +116,20 @@ call `format_to_string`, and check if it works:
# use anyhow::Error;
# use serde::{Serialize, Deserialize};
#
# #[derive_component(StringFormatterComponent, StringFormatter<Context>)]
# #[cgp_component {
# name: StringFormatterComponent,
# provider: StringFormatter,
# context: Context,
# }]
# pub trait CanFormatToString {
# fn format_to_string(&self) -> Result<String, Error>;
# }
#
# #[derive_component(StringParserComponent, StringParser<Context>)]
# #[cgp_component {
# name: StringParserComponent,
# provider: StringParser,
# context: Context,
# }]
# pub trait CanParseFromString: Sized {
# fn parse_from_string(raw: &str) -> Result<Self, Error>;
# }
Expand Down Expand Up @@ -246,12 +262,20 @@ defined as follows:
# use anyhow::Error;
# use serde::{Serialize, Deserialize};
#
# #[derive_component(StringFormatterComponent, StringFormatter<Context>)]
# #[cgp_component {
# name: StringFormatterComponent,
# provider: StringFormatter,
# context: Context,
# }]
# pub trait CanFormatToString {
# fn format_to_string(&self) -> Result<String, Error>;
# }
#
# #[derive_component(StringParserComponent, StringParser<Context>)]
# #[cgp_component {
# name: StringParserComponent,
# provider: StringParser,
# context: Context,
# }]
# pub trait CanParseFromString: Sized {
# fn parse_from_string(raw: &str) -> Result<Self, Error>;
# }
Expand Down Expand Up @@ -372,12 +396,20 @@ the super trait of `CanUsePerson` as follows:
# use anyhow::Error;
# use serde::{Serialize, Deserialize};
#
# #[derive_component(StringFormatterComponent, StringFormatter<Context>)]
# #[cgp_component {
# name: StringFormatterComponent,
# provider: StringFormatter,
# context: Context,
# }]
# pub trait CanFormatToString {
# fn format_to_string(&self) -> Result<String, Error>;
# }
#
# #[derive_component(StringParserComponent, StringParser<Context>)]
# #[cgp_component {
# name: StringParserComponent,
# provider: StringParser,
# context: Context,
# }]
# pub trait CanParseFromString: Sized {
# fn parse_from_string(raw: &str) -> Result<Self, Error>;
# }
Expand Down
Loading