metrique-macro 0.1.12

Library for working with unit of work metrics - #[metrics] macro
Documentation
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
---
source: metrique-macro/src/lib.rs
expression: parsed_file
---
enum Operation {
    Read,
    Write,
}
#[doc(hidden)]
pub enum OperationValue {
    #[deprecated(
        note = "these fields will become private in a future release. To introspect an entry, use `metrique::writer::test_util::test_entry`"
    )]
    #[doc(hidden)]
    Read,
    #[deprecated(
        note = "these fields will become private in a future release. To introspect an entry, use `metrique::writer::test_util::test_entry`"
    )]
    #[doc(hidden)]
    Write,
}
impl ::std::convert::From<&'_ OperationValue> for &'static str {
    fn from(value: &OperationValue) -> Self {
        #[allow(deprecated)]
        match value {
            OperationValue::Read => "Read",
            OperationValue::Write => "Write",
        }
    }
}
impl ::std::convert::From<OperationValue> for &'static str {
    fn from(value: OperationValue) -> Self {
        <&str as ::std::convert::From<&_>>::from(&value)
    }
}
impl ::metrique::writer::core::SampleGroup for OperationValue {
    fn as_sample_group(&self) -> ::std::borrow::Cow<'static, str> {
        ::std::borrow::Cow::Borrowed(::std::convert::Into::<&str>::into(self))
    }
}
impl ::metrique::writer::Value for OperationValue {
    fn write(&self, writer: impl ::metrique::writer::ValueWriter) {
        writer.string(::std::convert::Into::<&str>::into(self));
    }
}
impl metrique::CloseValue for &'_ Operation {
    type Closed = OperationValue;
    fn close(self) -> Self::Closed {
        #[allow(deprecated)]
        match self {
            Operation::Read => OperationValue::Read,
            Operation::Write => OperationValue::Write,
        }
    }
}
impl metrique::CloseValue for Operation {
    type Closed = OperationValue;
    fn close(self) -> Self::Closed {
        <&Self>::close(&self)
    }
}
impl ::std::convert::From<&'_ Operation> for &'static str {
    fn from(value: &Operation) -> Self {
        #[allow(deprecated)]
        match value {
            Operation::Read => "Read",
            Operation::Write => "Write",
        }
    }
}
impl ::std::convert::From<Operation> for &'static str {
    fn from(value: Operation) -> Self {
        <&str as ::std::convert::From<&_>>::from(&value)
    }
}
impl ::metrique::writer::core::SampleGroup for Operation {
    fn as_sample_group(&self) -> ::std::borrow::Cow<'static, str> {
        ::std::borrow::Cow::Borrowed(::std::convert::Into::<&str>::into(self))
    }
}

struct Metadata {
    operation: Operation,
    request_id: String,
}
#[doc(hidden)]
#[allow(clippy::type_complexity)]
pub struct MetadataEntry {
    #[deprecated(
        note = "these fields will become private in a future release. To introspect an entry, use `metrique::writer::test_util::test_entry`"
    )]
    #[doc(hidden)]
    operation: <Operation as metrique::CloseValue>::Closed,
    #[deprecated(
        note = "these fields will become private in a future release. To introspect an entry, use `metrique::writer::test_util::test_entry`"
    )]
    #[doc(hidden)]
    request_id: <String as metrique::CloseValue>::Closed,
}
const _: () = {
    #[expect(deprecated)]
    impl<NS: ::metrique::NameStyle> ::metrique::InflectableEntry<NS> for MetadataEntry {
        fn write<'__metrique_write>(
            &'__metrique_write self,
            writer: &mut impl ::metrique::writer::EntryWriter<'__metrique_write>,
        ) {
            ::metrique::writer::EntryWriter::value(
                writer,
                {
                    struct OperationPreserve;
                    impl ::metrique::concat::ConstStr for OperationPreserve {
                        const VAL: &'static str = "operation";
                    }
                    struct OperationKebab;
                    impl ::metrique::concat::ConstStr for OperationKebab {
                        const VAL: &'static str = "operation";
                    }
                    struct OperationPascal;
                    impl ::metrique::concat::ConstStr for OperationPascal {
                        const VAL: &'static str = "Operation";
                    }
                    struct OperationSnake;
                    impl ::metrique::concat::ConstStr for OperationSnake {
                        const VAL: &'static str = "operation";
                    }
                    ::metrique::concat::const_str_value::<
                        <NS as ::metrique::NameStyle>::Inflect<
                            OperationPreserve,
                            OperationPascal,
                            OperationSnake,
                            OperationKebab,
                        >,
                    >()
                },
                &self.operation,
            );
            ::metrique::writer::EntryWriter::value(
                writer,
                {
                    struct RequestIdPreserve;
                    impl ::metrique::concat::ConstStr for RequestIdPreserve {
                        const VAL: &'static str = "request_id";
                    }
                    struct RequestIdKebab;
                    impl ::metrique::concat::ConstStr for RequestIdKebab {
                        const VAL: &'static str = "request-id";
                    }
                    struct RequestIdPascal;
                    impl ::metrique::concat::ConstStr for RequestIdPascal {
                        const VAL: &'static str = "RequestId";
                    }
                    struct RequestIdSnake;
                    impl ::metrique::concat::ConstStr for RequestIdSnake {
                        const VAL: &'static str = "request_id";
                    }
                    ::metrique::concat::const_str_value::<
                        <NS as ::metrique::NameStyle>::Inflect<
                            RequestIdPreserve,
                            RequestIdPascal,
                            RequestIdSnake,
                            RequestIdKebab,
                        >,
                    >()
                },
                &self.request_id,
            );
        }
        fn sample_group(
            &self,
        ) -> impl ::std::iter::Iterator<
            Item = (::std::borrow::Cow<'static, str>, ::std::borrow::Cow<'static, str>),
        > {
            {
                struct OperationPreserve;
                impl ::metrique::concat::ConstStr for OperationPreserve {
                    const VAL: &'static str = "operation";
                }
                struct OperationKebab;
                impl ::metrique::concat::ConstStr for OperationKebab {
                    const VAL: &'static str = "operation";
                }
                struct OperationPascal;
                impl ::metrique::concat::ConstStr for OperationPascal {
                    const VAL: &'static str = "Operation";
                }
                struct OperationSnake;
                impl ::metrique::concat::ConstStr for OperationSnake {
                    const VAL: &'static str = "operation";
                }
                ::std::iter::once((
                    ::metrique::concat::const_str_value::<
                        <NS as ::metrique::NameStyle>::Inflect<
                            OperationPreserve,
                            OperationPascal,
                            OperationSnake,
                            OperationKebab,
                        >,
                    >(),
                    ::metrique::writer::core::SampleGroup::as_sample_group(
                        &self.operation,
                    ),
                ))
            }
        }
    }
};
impl metrique::CloseValue for &'_ Metadata {
    type Closed = MetadataEntry;
    fn close(self) -> Self::Closed {
        #[allow(deprecated)]
        MetadataEntry {
            operation: metrique::CloseValue::close(&self.operation),
            request_id: metrique::CloseValue::close(&self.request_id),
        }
    }
}
impl metrique::CloseValue for Metadata {
    type Closed = MetadataEntry;
    fn close(self) -> Self::Closed {
        <&Self>::close(&self)
    }
}

enum RequestResult {
    Success { operation: Operation, bytes: usize },
    Error { operation: Operation, error_code: u32 },
    Timeout(Metadata),
    Cancelled(Metadata, StatusEntry),
}
#[doc(hidden)]
pub enum RequestResultEntry {
    #[deprecated(
        note = "these fields will become private in a future release. To introspect an entry, use `metrique::writer::test_util::test_entry`"
    )]
    #[doc(hidden)]
    Success {
        #[deprecated(
            note = "these fields will become private in a future release. To introspect an entry, use `metrique::writer::test_util::test_entry`"
        )]
        #[doc(hidden)]
        operation: <Operation as metrique::CloseValue>::Closed,
        #[deprecated(
            note = "these fields will become private in a future release. To introspect an entry, use `metrique::writer::test_util::test_entry`"
        )]
        #[doc(hidden)]
        bytes: <usize as metrique::CloseValue>::Closed,
    },
    #[deprecated(
        note = "these fields will become private in a future release. To introspect an entry, use `metrique::writer::test_util::test_entry`"
    )]
    #[doc(hidden)]
    Error {
        #[deprecated(
            note = "these fields will become private in a future release. To introspect an entry, use `metrique::writer::test_util::test_entry`"
        )]
        #[doc(hidden)]
        operation: <Operation as metrique::CloseValue>::Closed,
        #[deprecated(
            note = "these fields will become private in a future release. To introspect an entry, use `metrique::writer::test_util::test_entry`"
        )]
        #[doc(hidden)]
        error_code: <u32 as metrique::CloseValue>::Closed,
    },
    #[deprecated(
        note = "these fields will become private in a future release. To introspect an entry, use `metrique::writer::test_util::test_entry`"
    )]
    #[doc(hidden)]
    Timeout(<Metadata as metrique::CloseValue>::Closed),
    #[deprecated(
        note = "these fields will become private in a future release. To introspect an entry, use `metrique::writer::test_util::test_entry`"
    )]
    #[doc(hidden)]
    Cancelled(<Metadata as metrique::CloseValue>::Closed, StatusEntry),
}
const _: () = {
    enum RequestResultEntrySampleGroupIter<V0, V1, V2, V3> {
        V0(V0),
        V1(V1),
        V2(V2),
        V3(V3),
    }
    impl<
        V0: ::std::iter::Iterator<
                Item = (
                    ::std::borrow::Cow<'static, str>,
                    ::std::borrow::Cow<'static, str>,
                ),
            >,
        V1: ::std::iter::Iterator<
                Item = (
                    ::std::borrow::Cow<'static, str>,
                    ::std::borrow::Cow<'static, str>,
                ),
            >,
        V2: ::std::iter::Iterator<
                Item = (
                    ::std::borrow::Cow<'static, str>,
                    ::std::borrow::Cow<'static, str>,
                ),
            >,
        V3: ::std::iter::Iterator<
                Item = (
                    ::std::borrow::Cow<'static, str>,
                    ::std::borrow::Cow<'static, str>,
                ),
            >,
    > ::std::iter::Iterator for RequestResultEntrySampleGroupIter<V0, V1, V2, V3> {
        type Item = (::std::borrow::Cow<'static, str>, ::std::borrow::Cow<'static, str>);
        fn next(&mut self) -> ::std::option::Option<Self::Item> {
            match self {
                RequestResultEntrySampleGroupIter::V0(iter) => iter.next(),
                RequestResultEntrySampleGroupIter::V1(iter) => iter.next(),
                RequestResultEntrySampleGroupIter::V2(iter) => iter.next(),
                RequestResultEntrySampleGroupIter::V3(iter) => iter.next(),
            }
        }
    }
    #[expect(deprecated)]
    impl<NS: ::metrique::NameStyle> ::metrique::InflectableEntry<NS>
    for RequestResultEntry {
        fn write<'__metrique_write>(
            &'__metrique_write self,
            writer: &mut impl ::metrique::writer::EntryWriter<'__metrique_write>,
        ) {
            #[allow(deprecated)]
            match self {
                RequestResultEntry::Success { operation, bytes } => {
                    ::metrique::writer::EntryWriter::value(
                        writer,
                        {
                            struct OperationPreserve;
                            impl ::metrique::concat::ConstStr for OperationPreserve {
                                const VAL: &'static str = "operation";
                            }
                            struct OperationKebab;
                            impl ::metrique::concat::ConstStr for OperationKebab {
                                const VAL: &'static str = "operation";
                            }
                            struct OperationPascal;
                            impl ::metrique::concat::ConstStr for OperationPascal {
                                const VAL: &'static str = "Operation";
                            }
                            struct OperationSnake;
                            impl ::metrique::concat::ConstStr for OperationSnake {
                                const VAL: &'static str = "operation";
                            }
                            ::metrique::concat::const_str_value::<
                                <NS as ::metrique::NameStyle>::Inflect<
                                    OperationPreserve,
                                    OperationPascal,
                                    OperationSnake,
                                    OperationKebab,
                                >,
                            >()
                        },
                        operation,
                    );
                    ::metrique::writer::EntryWriter::value(
                        writer,
                        {
                            struct BytesPreserve;
                            impl ::metrique::concat::ConstStr for BytesPreserve {
                                const VAL: &'static str = "bytes";
                            }
                            struct BytesKebab;
                            impl ::metrique::concat::ConstStr for BytesKebab {
                                const VAL: &'static str = "bytes";
                            }
                            struct BytesPascal;
                            impl ::metrique::concat::ConstStr for BytesPascal {
                                const VAL: &'static str = "Bytes";
                            }
                            struct BytesSnake;
                            impl ::metrique::concat::ConstStr for BytesSnake {
                                const VAL: &'static str = "bytes";
                            }
                            ::metrique::concat::const_str_value::<
                                <NS as ::metrique::NameStyle>::Inflect<
                                    BytesPreserve,
                                    BytesPascal,
                                    BytesSnake,
                                    BytesKebab,
                                >,
                            >()
                        },
                        bytes,
                    );
                }
                RequestResultEntry::Error { operation, error_code } => {
                    ::metrique::writer::EntryWriter::value(
                        writer,
                        {
                            struct OperationPreserve;
                            impl ::metrique::concat::ConstStr for OperationPreserve {
                                const VAL: &'static str = "operation";
                            }
                            struct OperationKebab;
                            impl ::metrique::concat::ConstStr for OperationKebab {
                                const VAL: &'static str = "operation";
                            }
                            struct OperationPascal;
                            impl ::metrique::concat::ConstStr for OperationPascal {
                                const VAL: &'static str = "Operation";
                            }
                            struct OperationSnake;
                            impl ::metrique::concat::ConstStr for OperationSnake {
                                const VAL: &'static str = "operation";
                            }
                            ::metrique::concat::const_str_value::<
                                <NS as ::metrique::NameStyle>::Inflect<
                                    OperationPreserve,
                                    OperationPascal,
                                    OperationSnake,
                                    OperationKebab,
                                >,
                            >()
                        },
                        operation,
                    );
                    ::metrique::writer::EntryWriter::value(
                        writer,
                        {
                            struct ErrorCodePreserve;
                            impl ::metrique::concat::ConstStr for ErrorCodePreserve {
                                const VAL: &'static str = "error_code";
                            }
                            struct ErrorCodeKebab;
                            impl ::metrique::concat::ConstStr for ErrorCodeKebab {
                                const VAL: &'static str = "error-code";
                            }
                            struct ErrorCodePascal;
                            impl ::metrique::concat::ConstStr for ErrorCodePascal {
                                const VAL: &'static str = "ErrorCode";
                            }
                            struct ErrorCodeSnake;
                            impl ::metrique::concat::ConstStr for ErrorCodeSnake {
                                const VAL: &'static str = "error_code";
                            }
                            ::metrique::concat::const_str_value::<
                                <NS as ::metrique::NameStyle>::Inflect<
                                    ErrorCodePreserve,
                                    ErrorCodePascal,
                                    ErrorCodeSnake,
                                    ErrorCodeKebab,
                                >,
                            >()
                        },
                        error_code,
                    );
                }
                RequestResultEntry::Timeout(v0) => {
                    ::metrique::InflectableEntry::<NS>::write(v0, writer);
                }
                RequestResultEntry::Cancelled(v0, v1) => {
                    ::metrique::InflectableEntry::<NS>::write(v0, writer);
                    ::metrique::writer::Entry::write(v1, writer);
                }
            }
        }
        fn sample_group(
            &self,
        ) -> impl ::std::iter::Iterator<
            Item = (::std::borrow::Cow<'static, str>, ::std::borrow::Cow<'static, str>),
        > {
            match self {
                RequestResultEntry::Success { operation, .. } => {
                    RequestResultEntrySampleGroupIter::V0({
                        struct OperationPreserve;
                        impl ::metrique::concat::ConstStr for OperationPreserve {
                            const VAL: &'static str = "operation";
                        }
                        struct OperationKebab;
                        impl ::metrique::concat::ConstStr for OperationKebab {
                            const VAL: &'static str = "operation";
                        }
                        struct OperationPascal;
                        impl ::metrique::concat::ConstStr for OperationPascal {
                            const VAL: &'static str = "Operation";
                        }
                        struct OperationSnake;
                        impl ::metrique::concat::ConstStr for OperationSnake {
                            const VAL: &'static str = "operation";
                        }
                        ::std::iter::once((
                            ::metrique::concat::const_str_value::<
                                <NS as ::metrique::NameStyle>::Inflect<
                                    OperationPreserve,
                                    OperationPascal,
                                    OperationSnake,
                                    OperationKebab,
                                >,
                            >(),
                            ::metrique::writer::core::SampleGroup::as_sample_group(
                                operation,
                            ),
                        ))
                    })
                }
                RequestResultEntry::Error { operation, .. } => {
                    RequestResultEntrySampleGroupIter::V1({
                        struct OperationPreserve;
                        impl ::metrique::concat::ConstStr for OperationPreserve {
                            const VAL: &'static str = "operation";
                        }
                        struct OperationKebab;
                        impl ::metrique::concat::ConstStr for OperationKebab {
                            const VAL: &'static str = "operation";
                        }
                        struct OperationPascal;
                        impl ::metrique::concat::ConstStr for OperationPascal {
                            const VAL: &'static str = "Operation";
                        }
                        struct OperationSnake;
                        impl ::metrique::concat::ConstStr for OperationSnake {
                            const VAL: &'static str = "operation";
                        }
                        ::std::iter::once((
                            ::metrique::concat::const_str_value::<
                                <NS as ::metrique::NameStyle>::Inflect<
                                    OperationPreserve,
                                    OperationPascal,
                                    OperationSnake,
                                    OperationKebab,
                                >,
                            >(),
                            ::metrique::writer::core::SampleGroup::as_sample_group(
                                operation,
                            ),
                        ))
                    })
                }
                RequestResultEntry::Timeout(v0) => {
                    RequestResultEntrySampleGroupIter::V2(
                        ::metrique::InflectableEntry::<NS>::sample_group(v0),
                    )
                }
                RequestResultEntry::Cancelled(v0, v1) => {
                    RequestResultEntrySampleGroupIter::V3(
                        ::metrique::InflectableEntry::<NS>::sample_group(v0)
                            .chain(::metrique::writer::Entry::sample_group(v1)),
                    )
                }
            }
        }
    }
};
impl metrique::CloseValue for RequestResult {
    type Closed = RequestResultEntry;
    fn close(self) -> Self::Closed {
        #[allow(deprecated)]
        match self {
            RequestResult::Success { operation, bytes } => {
                RequestResultEntry::Success {
                    operation: metrique::CloseValue::close(operation),
                    bytes: metrique::CloseValue::close(bytes),
                }
            }
            RequestResult::Error { operation, error_code } => {
                RequestResultEntry::Error {
                    operation: metrique::CloseValue::close(operation),
                    error_code: metrique::CloseValue::close(error_code),
                }
            }
            RequestResult::Timeout(v0) => {
                RequestResultEntry::Timeout(::metrique::CloseValue::close(v0))
            }
            RequestResult::Cancelled(v0, v1) => {
                RequestResultEntry::Cancelled(::metrique::CloseValue::close(v0), v1)
            }
        }
    }
}
impl ::std::convert::From<&'_ RequestResult> for &'static str {
    fn from(value: &RequestResult) -> Self {
        #[allow(deprecated)]
        match value {
            RequestResult::Success { .. } => "Success",
            RequestResult::Error { .. } => "Error",
            RequestResult::Timeout(_) => "Timeout",
            RequestResult::Cancelled(_, _) => "Cancelled",
        }
    }
}
impl ::std::convert::From<RequestResult> for &'static str {
    fn from(value: RequestResult) -> Self {
        <&str as ::std::convert::From<&_>>::from(&value)
    }
}
impl ::metrique::writer::core::SampleGroup for RequestResult {
    fn as_sample_group(&self) -> ::std::borrow::Cow<'static, str> {
        ::std::borrow::Cow::Borrowed(::std::convert::Into::<&str>::into(self))
    }
}
#[doc = concat!(
    "Metrics guard returned from [`", "RequestResult",
    "::append_on_drop`], closes the entry and appends the metrics to a sink when dropped."
)]
type RequestResultGuard<Q = ::metrique::DefaultSink> = ::metrique::AppendAndCloseOnDrop<
    RequestResult,
    Q,
>;
#[doc = concat!(
    "Metrics handle returned from [`", "RequestResultGuard",
    "::handle`], similar to an `Arc<", "RequestResultGuard", ">`."
)]
type RequestResultHandle<Q = ::metrique::DefaultSink> = ::metrique::AppendAndCloseOnDropHandle<
    RequestResult,
    Q,
>;
impl RequestResult {
    ///Creates an AppendAndCloseOnDrop that will be automatically appended to `sink` on drop.
    fn append_on_drop<
        Q: ::metrique::writer::EntrySink<::metrique::RootEntry<RequestResultEntry>>
            + Send + Sync + 'static,
    >(self, sink: Q) -> RequestResultGuard<Q> {
        ::metrique::append_and_close(self, sink)
    }
}