1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
//! This module defines the `pieces` feature ([`PiecesFeature`]), along with
//! the functions that select the pieces placed during a render.
//!
//! A *piece* is a part of the output that a backend places before or after the
//! document's content, such as the document's title or the bibliography
//! ([`Piece`](crate::core::piece::Piece)). The `pieces` feature registers two
//! things:
//!
//! - the service slot [`SLOT`] (`flm.pieces`), to which each feature that
//! offers a piece contributes the declaration of the piece ([`PieceDecl`]);
//! - the settings `include` and `exclude` ([`PiecesRenderOptions`]), with which
//! the pieces to be placed during a render are selected.
//!
//! The feature registers no stage and no table. Each backend that places
//! pieces registers its own pieces stage ([`PiecesStage`](super::PiecesStage))
//! and the table that this stage writes.
//!
//! The declarations of the pieces are values contributed to a service slot
//! ([`crate::core::services`]), and not a kind of definition in the registry.
//! A declaration is data that the pieces stages read: a name, a table, a place
//! and a default. The registry has nothing to check or to schedule for it.
//!
//! A registry that contains a backend with a pieces stage must also contain the
//! `pieces` feature. Otherwise, building a plan for this backend fails with an
//! error that identifies the option type [`PiecesRenderOptions`].
use ;
use Arc;
use crateSettingsDecl;
use cratePieceDecl;
use crate;
use crateArity;
use crate;
use crateBind;
/// The name of the `pieces` feature, `pieces`.
///
/// The identifiers of the conditions that the pieces stages report begin with
/// `flm.pieces.` ([`super::error`]).
pub const FEATURE: &str = "pieces";
/// Returns the settings declaration of the `pieces` feature. The fields of
/// [`PiecesRenderOptions`] are the settings of the feature, set on the render
/// request.
/// The name of the service slot `flm.pieces`, to which features contribute the
/// declarations of their pieces.
///
/// Each value of this service slot is a [`PieceDecl`]. The service slot keeps
/// the declarations in the order of their contributions. A backend places two
/// pieces with the same place in this order.
///
/// A feature that offers a piece contributes its declaration with
/// [`FeatureBuilder::peer_slot`], so that the feature can also be used in a
/// registry without the `pieces` feature. In such a registry, the declaration
/// is dropped, and the registry build reports a note.
pub const SLOT: &str = "flm.pieces";
/// The render option with which the pieces placed during a render are
/// selected.
///
/// A piece is placed during a render if it is listed in `include`, or if it is
/// placed by default
/// ([`PieceDecl::default_on`](crate::core::piece::PieceDecl#structfield.default_on))
/// and is not listed in `exclude`. A piece that is listed in both sets is
/// therefore placed. The two sets apply to every backend of the render.
///
/// The field [`backends`](Self::backends) restricts this selection for each
/// backend separately:
///
/// - On a backend that has an entry in `backends`, only the selected pieces
/// listed in this entry are placed.
/// - On a backend without an entry, all selected pieces are placed, unless the
/// pieces stage of the backend places only the pieces listed for it
/// ([`PiecesStage::placing_only_named`](super::PiecesStage::placing_only_named)).
/// In that case, no piece is placed on this backend.
///
/// The function [`selected_pieces`] applies these rules.
///
/// The option is set on the render request ([`Bind::Render`]). A piece that is
/// not placed during a render is not built: the stage that builds the content
/// of the piece is not scheduled in the plan. A name in `include` or `exclude`
/// that is not the name of a piece defined in any feature is ignored, and
/// reported as `flm.pieces.unknown-piece`
/// ([`UnknownPiece`](super::UnknownPiece)).
///
/// # Examples
///
/// ```
/// use flm_core::stdlib::backends::pieces::PiecesRenderOptions;
///
/// let options = PiecesRenderOptions::default().exclude("mypkg.notes");
/// assert!(options.exclude.iter().any(|name| name.as_str() == "mypkg.notes"));
/// assert!(options.include.is_empty());
/// ```
/// Returns the declarations of all pieces of `registry`, in the order of the
/// service slot [`SLOT`].
///
/// In a registry without the `pieces` feature, no piece is declared, and the
/// result is empty.
+ '_
/// Returns the declarations of the pieces placed on `backend` during a render
/// with `options`, in the order of the service slot [`SLOT`].
///
/// The selection follows the rules described at [`PiecesRenderOptions`]. The
/// flag `only_named` applies when `backend` has no entry in
/// [`PiecesRenderOptions::backends`]. In that case, the function returns all
/// pieces that `include` and `exclude` select if `only_named` is `false`, and
/// no piece if `only_named` is `true`.
///
/// The pieces stage of a backend calls this function with its own flag
/// ([`PiecesStage::places_only_named`](super::PiecesStage::places_only_named)),
/// first when the plan is built, then when the stage runs. When the plan is
/// built, the stages that build the returned pieces are scheduled. When the
/// stage runs, it lowers the returned pieces.
///
/// In a registry without the `pieces` feature, no piece is declared, and the
/// result is empty.
/// Returns the names in `include` and `exclude` of `options` that are not the
/// names of pieces declared in `registry`, sorted and without duplicates.
///
/// The pieces stage of each backend reports each of these names as
/// `flm.pieces.unknown-piece` ([`UnknownPiece`](super::UnknownPiece)).
/// The `pieces` feature, which registers the service slot [`SLOT`] and the
/// settings [`PiecesRenderOptions`] (see the [module
/// documentation](mod@super::feature)).
///
/// Use [`feature()`] to obtain the feature as a shared value.
;
/// Returns the `pieces` feature as a shared value, for instance to list it in
/// a package entry.
///
/// # Examples
///
/// ```
/// use flm_core::stdlib::backends::pieces;
///
/// assert_eq!(pieces::feature().info().name.as_str(), pieces::FEATURE);
/// ```