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
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
use std::convert::TryFrom;

use delegate::delegate;
use wasm_bindgen::JsCast;

use crate::InvalidCast;

// TODO: the spec also allows just and end-mark (from navigation to named mark) by specifying
// `undefined` for the start mark, but web_sys's API currently does not allow this
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum PerformanceMarkRange<'a, 'b> {
    FromNavigation,
    From(&'a str),
    Between(&'a str, &'b str),
}

impl Default for PerformanceMarkRange<'_, '_> {
    fn default() -> Self {
        PerformanceMarkRange::FromNavigation
    }
}

pub struct Performance {
    inner: web_sys::Performance,
}

impl Performance {
    delegate! {
        target self.inner {
            pub fn now(&self) -> f64;

            pub fn set_resource_timing_buffer_size(&self, max_size: u32);

            pub fn clear_marks(&self);

            pub fn clear_measures(&self);

            pub fn clear_resource_timings(&self);
        }
    }

    pub fn mark(&self, mark_name: &str) {
        // No clear indication in the spec that this can fail (there's a TypeError when invoking a
        // timestamp constructor with a negative timestamp, but I don't believe we could ever end up
        // creating a negative timestamp in this manner, barring a browser bug), unwrap for now.
        self.inner.mark(mark_name).unwrap();
    }

    pub fn measure(&self, measure_name: &str, range: PerformanceMarkRange) {
        // TODO: unwrap or return Error? The only error that should occur is an invalid mark name
        // (note: negative ranges are explicitly permitted), which *should* always indicate
        // programmer error, hence panic?

        match range {
            PerformanceMarkRange::FromNavigation => {
                self.inner.measure(measure_name).unwrap();
            }
            PerformanceMarkRange::From(start_mark) => {
                self.inner
                    .measure_with_start_mark(measure_name, start_mark)
                    .unwrap();
            }
            PerformanceMarkRange::Between(start_mark, end_mark) => {
                self.inner
                    .measure_with_start_mark_and_end_mark(measure_name, start_mark, end_mark)
                    .unwrap();
            }
        }
    }

    pub fn clear_marks_named(&self, mark_name: &str) {
        self.inner.clear_marks_with_mark_name(mark_name);
    }

    pub fn clear_measures_named(&self, measure_name: &str) {
        self.inner.clear_measures_with_measure_name(measure_name);
    }

    pub fn entries(&self) -> PerformanceEntries {
        PerformanceEntries {
            inner: self.inner.get_entries(),
        }
    }

    pub fn marks(&self) -> PerformanceMarks {
        PerformanceMarks {
            inner: self.inner.get_entries_by_type("mark"),
        }
    }

    pub fn measures(&self) -> PerformanceMeasures {
        PerformanceMeasures {
            inner: self.inner.get_entries_by_type("measure"),
        }
    }

    pub fn resource_timings(&self) -> PerformanceResourceTimings {
        PerformanceResourceTimings {
            inner: self.inner.get_entries_by_type("resource"),
        }
    }

    pub fn entries_named(&self, name: &str) -> PerformanceEntries {
        PerformanceEntries {
            inner: self.inner.get_entries_by_name(name),
        }
    }

    pub fn marks_named(&self, name: &str) -> PerformanceMarks {
        PerformanceMarks {
            inner: self.inner.get_entries_by_name_with_entry_type(name, "mark"),
        }
    }

    pub fn measures_named(&self, name: &str) -> PerformanceMeasures {
        PerformanceMeasures {
            inner: self
                .inner
                .get_entries_by_name_with_entry_type(name, "measure"),
        }
    }

    pub fn resource_timings_named(&self, name: &str) -> PerformanceResourceTimings {
        PerformanceResourceTimings {
            inner: self
                .inner
                .get_entries_by_name_with_entry_type(name, "resource"),
        }
    }
}

impl From<web_sys::Performance> for Performance {
    fn from(inner: web_sys::Performance) -> Self {
        Performance { inner }
    }
}

impl AsRef<web_sys::Performance> for Performance {
    fn as_ref(&self) -> &web_sys::Performance {
        &self.inner
    }
}

pub struct PerformanceEntry {
    inner: web_sys::PerformanceEntry,
}

impl From<web_sys::PerformanceEntry> for PerformanceEntry {
    fn from(inner: web_sys::PerformanceEntry) -> Self {
        PerformanceEntry { inner }
    }
}

impl From<PerformanceEntry> for web_sys::PerformanceEntry {
    fn from(value: PerformanceEntry) -> Self {
        value.inner
    }
}

impl AsRef<web_sys::PerformanceEntry> for PerformanceEntry {
    fn as_ref(&self) -> &web_sys::PerformanceEntry {
        &self.inner
    }
}

pub struct PerformanceEntries {
    inner: js_sys::Array,
}

impl PerformanceEntries {
    pub fn get(&self, index: usize) -> Option<PerformanceEntry> {
        u32::try_from(index).ok().and_then(|index| {
            let e = self.inner.get(index);

            if e.is_undefined() {
                None
            } else {
                let e: web_sys::PerformanceEntry = e.unchecked_into();

                Some(e.into())
            }
        })
    }

    pub fn len(&self) -> usize {
        self.inner.length() as usize
    }

    pub fn is_empty(&self) -> bool {
        self.len() == 0
    }

    pub fn is_not_empty(&self) -> bool {
        !self.is_empty()
    }

    pub fn first(&self) -> Option<PerformanceEntry> {
        self.get(0)
    }

    pub fn last(&self) -> Option<PerformanceEntry> {
        let len = self.len();

        if len > 0 {
            self.get(len - 1)
        } else {
            None
        }
    }

    pub fn iter(&self) -> PerformanceEntriesIter {
        PerformanceEntriesIter {
            performance_entries: self,
            current: 0,
        }
    }
}

impl IntoIterator for PerformanceEntries {
    type Item = PerformanceEntry;
    type IntoIter = PerformanceEntriesIntoIter;

    fn into_iter(self) -> Self::IntoIter {
        PerformanceEntriesIntoIter {
            performance_entries: self,
            current: 0,
        }
    }
}

pub struct PerformanceEntriesIter<'a> {
    performance_entries: &'a PerformanceEntries,
    current: usize,
}

impl<'a> Iterator for PerformanceEntriesIter<'a> {
    type Item = PerformanceEntry;

    fn next(&mut self) -> Option<Self::Item> {
        let current = self.current;

        self.current += 1;

        self.performance_entries.get(current)
    }
}

pub struct PerformanceEntriesIntoIter {
    performance_entries: PerformanceEntries,
    current: usize,
}

impl Iterator for PerformanceEntriesIntoIter {
    type Item = PerformanceEntry;

    fn next(&mut self) -> Option<Self::Item> {
        let current = self.current;

        self.current += 1;

        self.performance_entries.get(current)
    }
}

pub struct PerformanceMark {
    inner: web_sys::PerformanceMark,
}

impl PerformanceMark {
    delegate! {
        target self.inner {
            pub fn name(&self) -> String;
        }
    }

    pub fn time(&self) -> f64 {
        self.inner.start_time()
    }
}

impl From<web_sys::PerformanceMark> for PerformanceMark {
    fn from(inner: web_sys::PerformanceMark) -> Self {
        PerformanceMark { inner }
    }
}

impl TryFrom<PerformanceEntry> for PerformanceMark {
    type Error = InvalidCast<PerformanceEntry>;

    fn try_from(value: PerformanceEntry) -> Result<Self, Self::Error> {
        let e: web_sys::PerformanceEntry = value.into();

        e.dyn_into::<web_sys::PerformanceMark>()
            .map(|e| e.into())
            .map_err(|e| InvalidCast(e.into()))
    }
}

impl AsRef<web_sys::PerformanceMark> for PerformanceMark {
    fn as_ref(&self) -> &web_sys::PerformanceMark {
        &self.inner
    }
}

impl AsRef<web_sys::PerformanceEntry> for PerformanceMark {
    fn as_ref(&self) -> &web_sys::PerformanceEntry {
        self.inner.as_ref()
    }
}

pub struct PerformanceMarks {
    inner: js_sys::Array,
}

impl PerformanceMarks {
    pub fn get(&self, index: usize) -> Option<PerformanceMark> {
        u32::try_from(index).ok().and_then(|index| {
            let e = self.inner.get(index);

            if e.is_undefined() {
                None
            } else {
                let e: web_sys::PerformanceMark = e.unchecked_into();

                Some(e.into())
            }
        })
    }

    pub fn len(&self) -> usize {
        self.inner.length() as usize
    }

    pub fn is_empty(&self) -> bool {
        self.len() == 0
    }

    pub fn is_not_empty(&self) -> bool {
        !self.is_empty()
    }

    pub fn first(&self) -> Option<PerformanceMark> {
        self.get(0)
    }

    pub fn last(&self) -> Option<PerformanceMark> {
        let len = self.len();

        if len > 0 {
            self.get(len - 1)
        } else {
            None
        }
    }

    pub fn iter(&self) -> PerformanceMarksIter {
        PerformanceMarksIter {
            performance_marks: self,
            current: 0,
        }
    }
}

impl IntoIterator for PerformanceMarks {
    type Item = PerformanceMark;
    type IntoIter = PerformanceMarksIntoIter;

    fn into_iter(self) -> Self::IntoIter {
        PerformanceMarksIntoIter {
            performance_marks: self,
            current: 0,
        }
    }
}

pub struct PerformanceMarksIter<'a> {
    performance_marks: &'a PerformanceMarks,
    current: usize,
}

impl<'a> Iterator for PerformanceMarksIter<'a> {
    type Item = PerformanceMark;

    fn next(&mut self) -> Option<Self::Item> {
        let current = self.current;

        self.current += 1;

        self.performance_marks.get(current)
    }
}

pub struct PerformanceMarksIntoIter {
    performance_marks: PerformanceMarks,
    current: usize,
}

impl Iterator for PerformanceMarksIntoIter {
    type Item = PerformanceMark;

    fn next(&mut self) -> Option<Self::Item> {
        let current = self.current;

        self.current += 1;

        self.performance_marks.get(current)
    }
}

pub struct PerformanceMeasure {
    inner: web_sys::PerformanceMeasure,
}

impl PerformanceMeasure {
    delegate! {
        target self.inner {
            pub fn name(&self) -> String;

            pub fn start_time(&self) -> f64;

            pub fn duration(&self) -> f64;
        }
    }
}

impl From<web_sys::PerformanceMeasure> for PerformanceMeasure {
    fn from(inner: web_sys::PerformanceMeasure) -> Self {
        PerformanceMeasure { inner }
    }
}

impl TryFrom<PerformanceEntry> for PerformanceMeasure {
    type Error = InvalidCast<PerformanceEntry>;

    fn try_from(value: PerformanceEntry) -> Result<Self, Self::Error> {
        let e: web_sys::PerformanceEntry = value.into();

        e.dyn_into::<web_sys::PerformanceMeasure>()
            .map(|e| e.into())
            .map_err(|e| InvalidCast(e.into()))
    }
}

impl AsRef<web_sys::PerformanceMeasure> for PerformanceMeasure {
    fn as_ref(&self) -> &web_sys::PerformanceMeasure {
        &self.inner
    }
}

impl AsRef<web_sys::PerformanceEntry> for PerformanceMeasure {
    fn as_ref(&self) -> &web_sys::PerformanceEntry {
        self.inner.as_ref()
    }
}

pub struct PerformanceMeasures {
    inner: js_sys::Array,
}

impl PerformanceMeasures {
    pub fn get(&self, index: usize) -> Option<PerformanceMeasure> {
        u32::try_from(index).ok().and_then(|index| {
            let e = self.inner.get(index);

            if e.is_undefined() {
                None
            } else {
                let e: web_sys::PerformanceMeasure = e.unchecked_into();

                Some(e.into())
            }
        })
    }

    pub fn len(&self) -> usize {
        self.inner.length() as usize
    }

    pub fn is_empty(&self) -> bool {
        self.len() == 0
    }

    pub fn is_not_empty(&self) -> bool {
        !self.is_empty()
    }

    pub fn first(&self) -> Option<PerformanceMeasure> {
        self.get(0)
    }

    pub fn last(&self) -> Option<PerformanceMeasure> {
        let len = self.len();

        if len > 0 {
            self.get(len - 1)
        } else {
            None
        }
    }

    pub fn iter(&self) -> PerformanceMeasuresIter {
        PerformanceMeasuresIter {
            performance_measures: self,
            current: 0,
        }
    }
}

impl IntoIterator for PerformanceMeasures {
    type Item = PerformanceMeasure;
    type IntoIter = PerformanceMeasuresIntoIter;

    fn into_iter(self) -> Self::IntoIter {
        PerformanceMeasuresIntoIter {
            performance_measures: self,
            current: 0,
        }
    }
}

pub struct PerformanceMeasuresIter<'a> {
    performance_measures: &'a PerformanceMeasures,
    current: usize,
}

impl<'a> Iterator for PerformanceMeasuresIter<'a> {
    type Item = PerformanceMeasure;

    fn next(&mut self) -> Option<Self::Item> {
        let current = self.current;

        self.current += 1;

        self.performance_measures.get(current)
    }
}

pub struct PerformanceMeasuresIntoIter {
    performance_measures: PerformanceMeasures,
    current: usize,
}

impl Iterator for PerformanceMeasuresIntoIter {
    type Item = PerformanceMeasure;

    fn next(&mut self) -> Option<Self::Item> {
        let current = self.current;

        self.current += 1;

        self.performance_measures.get(current)
    }
}

pub struct PerformanceResourceTiming {
    inner: web_sys::PerformanceResourceTiming,
}

impl PerformanceResourceTiming {
    delegate! {
        target self.inner {
            pub fn name(&self) -> String;

            pub fn start_time(&self) -> f64;

            pub fn duration(&self) -> f64;

            pub fn initiator_type(&self) -> String;

            pub fn next_hop_protocol(&self) -> String;

            pub fn worker_start(&self) -> f64;

            pub fn redirect_start(&self) -> f64;

            pub fn redirect_end(&self) -> f64;

            pub fn fetch_start(&self) -> f64;

            pub fn domain_lookup_start(&self) -> f64;

            pub fn domain_lookup_end(&self) -> f64;

            pub fn connect_start(&self) -> f64;

            pub fn connect_end(&self) -> f64;

            pub fn secure_connection_start(&self) -> f64;

            pub fn request_start(&self) -> f64;

            pub fn response_start(&self) -> f64;

            pub fn response_end(&self) -> f64;

            // TODO: do these next 3 methods always return whole numbers? Perhaps u64 makes more
            // sense?

            pub fn transfer_size(&self) -> f64;

            pub fn encoded_body_size(&self) -> f64;

            pub fn decoded_body_size(&self) -> f64;
        }
    }

    // TODO: MDN seems to indicate that this may return null/undefined/SecurityError if not on a
    // secure connection (although the Server Timings spec gives no indication of this); needs
    // investigating.
    pub fn server_timings(&self) -> PerformanceServerTimings {
        PerformanceServerTimings {
            inner: self.inner.server_timing(),
        }
    }
}

impl From<web_sys::PerformanceResourceTiming> for PerformanceResourceTiming {
    fn from(inner: web_sys::PerformanceResourceTiming) -> Self {
        PerformanceResourceTiming { inner }
    }
}

impl TryFrom<PerformanceEntry> for PerformanceResourceTiming {
    type Error = InvalidCast<PerformanceEntry>;

    fn try_from(value: PerformanceEntry) -> Result<Self, Self::Error> {
        let e: web_sys::PerformanceEntry = value.into();

        e.dyn_into::<web_sys::PerformanceResourceTiming>()
            .map(|e| e.into())
            .map_err(|e| InvalidCast(e.into()))
    }
}

impl AsRef<web_sys::PerformanceResourceTiming> for PerformanceResourceTiming {
    fn as_ref(&self) -> &web_sys::PerformanceResourceTiming {
        &self.inner
    }
}

impl AsRef<web_sys::PerformanceEntry> for PerformanceResourceTiming {
    fn as_ref(&self) -> &web_sys::PerformanceEntry {
        self.inner.as_ref()
    }
}

pub struct PerformanceResourceTimings {
    inner: js_sys::Array,
}

impl PerformanceResourceTimings {
    pub fn get(&self, index: usize) -> Option<PerformanceResourceTiming> {
        u32::try_from(index).ok().and_then(|index| {
            let e = self.inner.get(index);

            if e.is_undefined() {
                None
            } else {
                let e: web_sys::PerformanceResourceTiming = e.unchecked_into();

                Some(e.into())
            }
        })
    }

    pub fn len(&self) -> usize {
        self.inner.length() as usize
    }

    pub fn is_empty(&self) -> bool {
        self.len() == 0
    }

    pub fn is_not_empty(&self) -> bool {
        !self.is_empty()
    }

    pub fn first(&self) -> Option<PerformanceResourceTiming> {
        self.get(0)
    }

    pub fn last(&self) -> Option<PerformanceResourceTiming> {
        let len = self.len();

        if len > 0 {
            self.get(len - 1)
        } else {
            None
        }
    }

    pub fn iter(&self) -> PerformanceResourceTimingsIter {
        PerformanceResourceTimingsIter {
            performance_resource_timings: self,
            current: 0,
        }
    }
}

impl IntoIterator for PerformanceResourceTimings {
    type Item = PerformanceResourceTiming;
    type IntoIter = PerformanceResourceTimingsIntoIter;

    fn into_iter(self) -> Self::IntoIter {
        PerformanceResourceTimingsIntoIter {
            performance_resource_timings: self,
            current: 0,
        }
    }
}

pub struct PerformanceResourceTimingsIter<'a> {
    performance_resource_timings: &'a PerformanceResourceTimings,
    current: usize,
}

impl<'a> Iterator for PerformanceResourceTimingsIter<'a> {
    type Item = PerformanceResourceTiming;

    fn next(&mut self) -> Option<Self::Item> {
        let current = self.current;

        self.current += 1;

        self.performance_resource_timings.get(current)
    }
}

pub struct PerformanceResourceTimingsIntoIter {
    performance_resource_timings: PerformanceResourceTimings,
    current: usize,
}

impl Iterator for PerformanceResourceTimingsIntoIter {
    type Item = PerformanceResourceTiming;

    fn next(&mut self) -> Option<Self::Item> {
        let current = self.current;

        self.current += 1;

        self.performance_resource_timings.get(current)
    }
}

pub struct PerformanceServerTiming {
    inner: web_sys::PerformanceServerTiming,
}

impl PerformanceServerTiming {
    delegate! {
        target self.inner {
            pub fn name(&self) -> String;

            pub fn description(&self) -> String;

            pub fn duration(&self) -> f64;
        }
    }
}

impl From<web_sys::PerformanceServerTiming> for PerformanceServerTiming {
    fn from(inner: web_sys::PerformanceServerTiming) -> Self {
        PerformanceServerTiming { inner }
    }
}

impl AsRef<web_sys::PerformanceServerTiming> for PerformanceServerTiming {
    fn as_ref(&self) -> &web_sys::PerformanceServerTiming {
        &self.inner
    }
}

pub struct PerformanceServerTimings {
    inner: js_sys::Array,
}

impl PerformanceServerTimings {
    pub fn get(&self, index: usize) -> Option<PerformanceServerTiming> {
        u32::try_from(index).ok().and_then(|index| {
            let e = self.inner.get(index);

            if e.is_undefined() {
                None
            } else {
                let e: web_sys::PerformanceServerTiming = e.unchecked_into();

                Some(e.into())
            }
        })
    }

    pub fn len(&self) -> usize {
        self.inner.length() as usize
    }

    pub fn is_empty(&self) -> bool {
        self.len() == 0
    }

    pub fn is_not_empty(&self) -> bool {
        !self.is_empty()
    }

    pub fn first(&self) -> Option<PerformanceServerTiming> {
        self.get(0)
    }

    pub fn last(&self) -> Option<PerformanceServerTiming> {
        let len = self.len();

        if len > 0 {
            self.get(len - 1)
        } else {
            None
        }
    }

    pub fn iter(&self) -> PerformanceServerTimingsIter {
        PerformanceServerTimingsIter {
            performance_server_timings: self,
            current: 0,
        }
    }
}

impl IntoIterator for PerformanceServerTimings {
    type Item = PerformanceServerTiming;
    type IntoIter = PerformanceServerTimingsIntoIter;

    fn into_iter(self) -> Self::IntoIter {
        PerformanceServerTimingsIntoIter {
            performance_server_timings: self,
            current: 0,
        }
    }
}

pub struct PerformanceServerTimingsIter<'a> {
    performance_server_timings: &'a PerformanceServerTimings,
    current: usize,
}

impl<'a> Iterator for PerformanceServerTimingsIter<'a> {
    type Item = PerformanceServerTiming;

    fn next(&mut self) -> Option<Self::Item> {
        let current = self.current;

        self.current += 1;

        self.performance_server_timings.get(current)
    }
}

pub struct PerformanceServerTimingsIntoIter {
    performance_server_timings: PerformanceServerTimings,
    current: usize,
}

impl Iterator for PerformanceServerTimingsIntoIter {
    type Item = PerformanceServerTiming;

    fn next(&mut self) -> Option<Self::Item> {
        let current = self.current;

        self.current += 1;

        self.performance_server_timings.get(current)
    }
}