MCPcopy Create free account
hub / github.com/It4innovations/hyperqueue / parse_resource_range

Function parse_resource_range

crates/hyperqueue/src/worker/parser.rs:118–143  ·  view source on GitHub ↗

Parses a range resource. The start of the range must be smaller or equal to the end. Example: `range(1-5)`.

()

Source from the content-addressed store, hash-verified

116/// The start of the range must be smaller or equal to the end.
117/// Example: `range(1-5)`.
118fn parse_resource_range() -> impl CharParser<ResourceDescriptorKind> {
119 let start = parse_exact_string("range").then(just('(').padded());
120 let end = just(')').padded();
121
122 let range = parse_u32()
123 .labelled("start")
124 .then_ignore(just('-').padded())
125 .then(parse_u32().labelled("end"))
126 .labelled("range");
127
128 range
129 .delimited_by(start, end)
130 .try_map(|(start, end), span| {
131 if start > end {
132 Err(ParseError::custom(
133 span,
134 "Start must be greater or equal to end",
135 ))
136 } else {
137 Ok(ResourceDescriptorKind::Range {
138 start: start.into(),
139 end: end.into(),
140 })
141 }
142 })
143}
144
145/// Parse a sum resource.
146/// Example: `sum(100)`.

Callers 1

parse_resource_kindFunction · 0.85

Calls 3

parse_exact_stringFunction · 0.85
parse_u32Function · 0.85
intoMethod · 0.80

Tested by

no test coverage detected