oxide_update_engine_types/macros.rs
1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5/// Defines type aliases for types-crate types parameterized by a
6/// particular [`EngineSpec`](crate::spec::EngineSpec).
7///
8/// This macro defines a number of type aliases. For example:
9///
10/// ```ignore
11/// oxide_update_engine_types::define_update_engine_types!(pub(crate) MySpec);
12/// ```
13///
14/// defines a number of type aliases, each of which are of the form:
15///
16/// ```ignore
17/// pub(crate) type Event<S = MySpec> =
18/// oxide_update_engine_types::events::Event<S>;
19/// pub(crate) type EventBuffer<S = MySpec> =
20/// oxide_update_engine_types::buffer::EventBuffer<S>;
21/// // ... and so on.
22/// ```
23///
24/// These aliases make it easy to use a type without having to repeat
25/// the name of the specification over and over, while still providing
26/// a type parameter as an escape hatch if required.
27///
28/// For consumers that also depend on the engine crate, a companion
29/// macro
30/// [`oxide_update_engine::define_update_engine!`](https://docs.rs/oxide-update-engine)
31/// generates aliases for engine-crate types.
32#[macro_export]
33macro_rules! define_update_engine_types {
34 ($v:vis $spec_type:ty) => {
35 $v type Event<S = $spec_type> =
36 $crate::events::Event<S>;
37 $v type StepEvent<S = $spec_type> =
38 $crate::events::StepEvent<S>;
39 $v type StepEventKind<S = $spec_type> =
40 $crate::events::StepEventKind<S>;
41 $v type ProgressEvent<S = $spec_type> =
42 $crate::events::ProgressEvent<S>;
43 $v type ProgressEventKind<S = $spec_type> =
44 $crate::events::ProgressEventKind<S>;
45 $v type StepInfo<S = $spec_type> =
46 $crate::events::StepInfo<S>;
47 $v type StepComponentSummary<S = $spec_type> =
48 $crate::events::StepComponentSummary<S>;
49 $v type StepInfoWithMetadata<S = $spec_type> =
50 $crate::events::StepInfoWithMetadata<S>;
51 $v type StepProgress<S = $spec_type> =
52 $crate::events::StepProgress<S>;
53 $v type StepOutcome<S = $spec_type> =
54 $crate::events::StepOutcome<S>;
55 $v type EventReport<S = $spec_type> =
56 $crate::events::EventReport<S>;
57 $v type EventBuffer<S = $spec_type> =
58 $crate::buffer::EventBuffer<S>;
59 };
60}