|
1 | 1 | mod bytes_received;
|
2 | 2 | mod bytes_sent;
|
| 3 | +mod cached_event; |
3 | 4 | pub mod component_events_dropped;
|
4 | 5 | mod events_received;
|
5 | 6 | mod events_sent;
|
| 7 | +mod optional_tag; |
6 | 8 | mod prelude;
|
7 | 9 | pub mod service;
|
8 | 10 |
|
| 11 | +use std::ops::{Add, AddAssign}; |
| 12 | + |
9 | 13 | pub use metrics::SharedString;
|
10 | 14 |
|
11 | 15 | pub use bytes_received::BytesReceived;
|
12 | 16 | pub use bytes_sent::BytesSent;
|
| 17 | +#[allow(clippy::module_name_repetitions)] |
| 18 | +pub use cached_event::{RegisterTaggedInternalEvent, RegisteredEventCache}; |
13 | 19 | pub use component_events_dropped::{ComponentEventsDropped, INTENTIONAL, UNINTENTIONAL};
|
14 | 20 | pub use events_received::EventsReceived;
|
15 |
| -pub use events_sent::{EventsSent, DEFAULT_OUTPUT}; |
| 21 | +pub use events_sent::{EventsSent, TaggedEventsSent, DEFAULT_OUTPUT}; |
| 22 | +pub use optional_tag::OptionalTag; |
16 | 23 | pub use prelude::{error_stage, error_type};
|
17 | 24 | pub use service::{CallError, PollReadyError};
|
18 | 25 |
|
@@ -109,9 +116,24 @@ pub struct ByteSize(pub usize);
|
109 | 116 | pub struct Count(pub usize);
|
110 | 117 |
|
111 | 118 | /// Holds the tuple `(count_of_events, estimated_json_size_of_events)`.
|
112 |
| -#[derive(Clone, Copy)] |
| 119 | +#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)] |
113 | 120 | pub struct CountByteSize(pub usize, pub JsonSize);
|
114 | 121 |
|
| 122 | +impl AddAssign for CountByteSize { |
| 123 | + fn add_assign(&mut self, rhs: Self) { |
| 124 | + self.0 += rhs.0; |
| 125 | + self.1 += rhs.1; |
| 126 | + } |
| 127 | +} |
| 128 | + |
| 129 | +impl Add<CountByteSize> for CountByteSize { |
| 130 | + type Output = CountByteSize; |
| 131 | + |
| 132 | + fn add(self, rhs: CountByteSize) -> Self::Output { |
| 133 | + CountByteSize(self.0 + rhs.0, self.1 + rhs.1) |
| 134 | + } |
| 135 | +} |
| 136 | + |
115 | 137 | // Wrapper types used to hold parameters for registering events
|
116 | 138 |
|
117 | 139 | pub struct Output(pub Option<SharedString>);
|
@@ -196,6 +218,9 @@ macro_rules! registered_event {
|
196 | 218 |
|
197 | 219 | fn emit(&$slf:ident, $data_name:ident: $data:ident)
|
198 | 220 | $emit_body:block
|
| 221 | + |
| 222 | + $(fn register($tags_name:ident: $tags:ty) |
| 223 | + $register_body:block)? |
199 | 224 | ) => {
|
200 | 225 | paste::paste!{
|
201 | 226 | #[derive(Clone)]
|
@@ -223,6 +248,17 @@ macro_rules! registered_event {
|
223 | 248 | fn emit(&$slf, $data_name: $data)
|
224 | 249 | $emit_body
|
225 | 250 | }
|
| 251 | + |
| 252 | + $(impl $crate::internal_event::cached_event::RegisterTaggedInternalEvent for $event { |
| 253 | + type Tags = $tags; |
| 254 | + |
| 255 | + fn register( |
| 256 | + $tags_name: $tags, |
| 257 | + ) -> <TaggedEventsSent as super::RegisterInternalEvent>::Handle { |
| 258 | + $register_body |
| 259 | + } |
| 260 | + })? |
| 261 | + |
226 | 262 | }
|
227 | 263 | };
|
228 | 264 | }
|
0 commit comments