• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

facet-rs / facet / 15113146359

19 May 2025 12:36PM UTC coverage: 56.947% (+0.2%) from 56.733%
15113146359

Pull #628

github

web-flow
Merge 37349d055 into 453013232
Pull Request #628: feat(args): convert reflection spans from arg-wise to char-wise

117 of 183 new or added lines in 5 files covered. (63.93%)

3 existing lines in 2 files now uncovered.

9218 of 16187 relevant lines covered (56.95%)

131.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

66.67
/facet-deserialize/src/span.rs
1
use core::fmt;
2
use core::marker::PhantomData;
3

4
/// A Cooked variant of a Span (byte indexed)
5
#[derive(Debug, PartialEq)]
6
pub enum Cooked {}
7

8
/// A Raw variant of a Span (format-specific index)
9
#[derive(Debug, PartialEq)]
10
pub enum Raw {}
11

12
/// Position in the input (byte index)
13
pub type Pos = usize;
14

15
/// A span in the input, with a start position and length
16
#[derive(Debug, PartialEq, Eq)]
17
pub struct Span<C = Cooked> {
18
    /// Starting position of the span in bytes
19
    pub start: Pos,
20
    /// Length of the span in bytes
21
    pub len: usize,
22
    /// Hold on to C
23
    _p: PhantomData<C>,
24
}
25

26
/// Trait for types that can be annotated with a Span.
27
pub trait Spannable<C = Cooked>: Sized {
28
    /// Annotate this value with a span, wrapping it in `Spanned<Self, C>`
29
    fn with_span(self, span: Span<C>) -> Spanned<Self, C>;
30
}
31

32
impl<T, C> Spannable<C> for T {
33
    fn with_span(self, span: Span<C>) -> Spanned<Self, C> {
17✔
34
        Spanned { node: self, span }
17✔
35
    }
17✔
36
}
37

38
impl<C> Span<C> {
39
    /// Creates a new span with the given start position and length
40
    pub fn new(start: Pos, len: usize) -> Self {
2,780✔
41
        Span {
2,780✔
42
            start,
2,780✔
43
            len,
2,780✔
44
            _p: PhantomData,
2,780✔
45
        }
2,780✔
46
    }
2,780✔
47
    /// Start position of the span
48
    pub fn start(&self) -> Pos {
1,320✔
49
        self.start
1,320✔
50
    }
1,320✔
51
    /// Length of the span
52
    pub fn len(&self) -> usize {
1,132✔
53
        self.len
1,132✔
54
    }
1,132✔
55
    /// Returns `true` if this span has zero length
56
    pub fn is_empty(&self) -> bool {
×
57
        self.len == 0
×
58
    }
×
59
    /// End position (start + length)
60
    pub fn end(&self) -> Pos {
1,149✔
61
        self.start + self.len
1,149✔
62
    }
1,149✔
63
}
64

65
impl<C> Default for Span<C> {
NEW
66
    fn default() -> Self {
×
NEW
67
        Span {
×
NEW
68
            start: 0,
×
NEW
69
            len: 0,
×
NEW
70
            _p: PhantomData,
×
NEW
71
        }
×
NEW
72
    }
×
73
}
74

75
/// A value of type `T` annotated with its `Span`
76
#[derive(Debug, Clone, PartialEq, Eq)]
77
pub struct Spanned<T, C = Cooked> {
78
    /// The actual data/value being wrapped
79
    pub node: T,
80
    /// The span information indicating the position and length in the source
81
    pub span: Span<C>,
82
}
83

84
impl<T: fmt::Display, C> fmt::Display for Spanned<T, C> {
85
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
148✔
86
        write!(
148✔
87
            f,
148✔
88
            "{} at {}-{}",
148✔
89
            self.node,
90
            self.span.start(),
148✔
91
            self.span.end()
148✔
92
        )
93
    }
148✔
94
}
95

96
// Copy + Clone not auto-derived for PhantomData
97
// https://stackoverflow.com/a/31371094/2668831
98

99
impl<C> Clone for Span<C> {
NEW
100
    fn clone(&self) -> Self {
×
NEW
101
        *self
×
NEW
102
    }
×
103
}
104

105
impl<C> Copy for Span<C> {}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc