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

Function p_allocation_request

crates/hyperqueue/src/client/resources.rs:12–41  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

10use crate::worker::parser::{is_valid_resource_char, is_valid_starting_resource_char};
11
12fn p_allocation_request() -> impl CharParser<AllocationRequest> {
13 parse_exact_string("all")
14 .map(|_| AllocationRequest::All)
15 .or(parse_resource_amount()
16 .padded()
17 .then(
18 choice((
19 just("compact!"),
20 just("compact"),
21 just("tight!"),
22 just("tight"),
23 just("scatter"),
24 ))
25 .or_not(),
26 )
27 .try_map(|(amount, policy), span| {
28 let alloc = match policy {
29 None | Some("compact") => AllocationRequest::Compact(amount),
30 Some("compact!") => AllocationRequest::ForceCompact(amount),
31 Some("tight") => AllocationRequest::Tight(amount),
32 Some("tight!") => AllocationRequest::ForceTight(amount),
33 Some("scatter") => AllocationRequest::Scatter(amount),
34 _ => unreachable!(),
35 };
36 alloc
37 .validate()
38 .map_err(|e| ParseError::custom(span, e.to_string()))?;
39 Ok(alloc)
40 }))
41}
42
43fn p_resource_identifier() -> impl CharParser<String> {
44 filter(|&c| is_valid_starting_resource_char(c))

Callers 2

p_resource_requestFunction · 0.85
parse_allocation_requestFunction · 0.85

Calls 5

parse_exact_stringFunction · 0.85
parse_resource_amountFunction · 0.85
orMethod · 0.80
to_stringMethod · 0.80
validateMethod · 0.45

Tested by

no test coverage detected