1#![cfg_attr(docsrs, feature(doc_cfg))]
2
3#![cfg_attr(
71 feature = "persian-rug",
72 doc = r##"
73
74# persian-rug
75
76When the `"persian-rug"` feature is enabled, a parallel set of types,
77traits and derive macros are enabled, i.e. [`BuildableWithPersianRug`]
78and [`GeneratableWithPersianRug`]. These provide similar facilities,
79but for types based on the [persian-rug](::persian_rug) crate.
80
81Briefly, [persian-rug](::persian_rug) moves ownership of all values
82into a single container (the "rug" or
83[`Context`](::persian_rug::Context)). Client code then deals with handles
84(in the form [`Proxy<T>`](::persian_rug::Proxy)) to these values. The
85builders and generators take a mutator for the type's context in their
86[`build`](BuilderWithPersianRug::build) and
87[`generate`](GeneratorWithPersianRug::generate) methods, which means
88at the point of construction, the set of other constructed instances
89(of all types in that context) is available.
90
91Since the derived generators pass through
92[`Proxy<T>`](::persian_rug::Proxy), and since to get the most benefit from
93this system you should work with proxies where possible, the most common
94usage is to use these solely through the pass throughs.
95
96Example:
97```rust
98use boulder::{BuilderWithPersianRug, BuildableWithPersianRug};
99use persian_rug::{contextual, persian_rug, Context, Proxy};
100
101#[persian_rug]
102struct Rug(
103 #[table] Foo,
104 #[table] Bar,
105);
106
107#[contextual(Rug)]
108#[derive(BuildableWithPersianRug)]
109#[boulder(persian_rug(context=Rug))]
110struct Foo {
111 #[boulder(default=5)]
112 pub a: i32,
113 #[boulder(buildable_with_persian_rug(a=5))]
114 pub b: Proxy<Bar>,
115}
116
117#[contextual(Rug)]
118#[derive(BuildableWithPersianRug)]
119#[boulder(persian_rug(context=Rug))]
120struct Bar {
121 #[boulder(default=2)]
122 pub a: i32
123}
124
125let mut r = Rug(Default::default(), Default::default());
126let (f, _) = Proxy::<Foo>::builder()
127 .a(27)
128 .build(&mut r);
129assert_eq!(r.get(&f).a, 27);
130assert_eq!(r.get(&r.get(&f).b).a, 5);
131```
132
133"##
134)]
135
136mod builder;
137mod generator;
138
139pub use self::builder::{Buildable, Builder};
140pub use self::generator::generators::{
141 Const, Cycle, Inc, Pattern, Repeat, Sample, Some, Subsets, Time,
142};
143pub use self::generator::{Generatable, Generator};
144pub use self::generator::{GeneratorIterator, GeneratorMutIterator};
145
146#[cfg(feature = "persian-rug")]
147mod persian_rug;
148#[cfg(feature = "persian-rug")]
149#[cfg_attr(docsrs, doc(cfg(feature = "persian-rug")))]
150pub use self::persian_rug::{
151 BuildableWithPersianRug, BuilderWithPersianRug, GeneratableWithPersianRug,
152 GeneratorToGeneratorWithPersianRugWrapper, GeneratorWithPersianRug,
153 GeneratorWithPersianRugIterator, GeneratorWithPersianRugMutIterator, RepeatFromPersianRug,
154 SampleFromPersianRug, SequenceGeneratorWithPersianRug, SubsetsFromPersianRug,
155 TryRepeatFromPersianRug,
156};
157
158#[doc(hidden)]
159pub mod guts {
160 pub use crate::builder::guts as builder;
161 pub use crate::generator::guts as generator;
162
163 #[cfg(feature = "persian-rug")]
164 pub mod persian_rug {
165 pub use crate::persian_rug::builder::guts as builder;
166 pub use crate::persian_rug::generator::guts as generator;
167 }
168}