@@ -6,4 +6,55 @@ title = "Context-Generic Programming"
6
6
7
7
# Introduction
8
8
9
- Context-generic programming (CGP) is a new programming paradigm for Rust.
9
+ Context-generic programming (CGP) is a new programming paradigm for Rust that
10
+ allows strongly-typed components to be implemented and composed in a modular,
11
+ generic, and type-safe way.
12
+
13
+ ## Modular Component System
14
+
15
+ CGP makes use of Rust's trait system to define generic component _ interfaces_
16
+ that decouple code that _ consumes_ an interface from code that _ implements_ an interface.
17
+ This is done by having _ provider traits_ that are used for implementing a
18
+ component interface, in addition to _ consumer traits_ which are used for
19
+ consuming a component interface.
20
+
21
+ The separation of provider traits from consumer traits allows multiple context-generic
22
+ provider implementations to be defined, bypassing Rust's trait system original restriction
23
+ of forbidding overlapping implementations.
24
+
25
+ ## Expressive Ways to Write Code
26
+
27
+ With CGP, one can easily write _ abstract programs_ that is generic over
28
+ a context, together with all its associated types and methods. CGP allows such
29
+ generic code to be written without needing to explicitly specify a long list
30
+ generic parameters in the type signatures.
31
+
32
+ CGP also provides powerful _ macros_ for defining component interfaces, as well
33
+ as providing simple ways to wire up component implementations to be used with
34
+ a concrete context.
35
+
36
+ CGP allows Rust code to be written with the same level of expressiveness,
37
+ if not more, as other popular programming paradigms, including object-oriented programming
38
+ and dynamic-typed programming.
39
+
40
+ ## Type-Safe Composition
41
+
42
+ CGP makes use of Rust's strong type system to help ensure that all wiring
43
+ of components is _ type-safe_ , catching any missing dependencies as compile-time
44
+ errors. CGP works fully within safe Rust, and does not make use of
45
+ any dynamic-typing techniques, e.g. ` dyn ` traits, ` Any ` , or reflection.
46
+ As a result, developers can ensure that no CGP-specific errors can happen
47
+ during application runtime.
48
+
49
+ ## No-Std Friendly
50
+
51
+ CGP makes it possible to build _ fully-abstract programs_ that can be defined
52
+ with _ zero dependencies_ . This allows such programs to be instantiated with
53
+ specialized-dependencies in no-std environments, such as on embedded systems,
54
+ operating system kernels, or Wasm sandboxes.
55
+
56
+ ## Zero-Cost Abstraction
57
+
58
+ Since all CGP features work only at compile-time, it provides the same
59
+ _ zero-cost abstraction_ advantage as Rust. Applications do not have to sacrifice
60
+ any runtime overhead for using CGP in the code base.
0 commit comments