kinetics_parser/
worker.rs1use crate::environment::{parse_environment, Environment};
2use serde::{Deserialize, Serialize};
3use syn::{
4 parse::{Parse, ParseStream},
5 token, Ident, LitBool, LitInt, LitStr,
6};
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct Worker {
10 pub name: Option<String>,
11 pub concurrency: u32,
12 pub fifo: bool,
13 pub environment: Environment,
14}
15
16impl Default for Worker {
17 fn default() -> Self {
18 Worker {
19 name: None,
20 concurrency: 1,
21 fifo: false,
22 environment: Environment::new(),
23 }
24 }
25}
26
27impl Parse for Worker {
28 fn parse(input: ParseStream) -> syn::Result<Self> {
29 let mut worker = Worker::default();
30
31 while !input.is_empty() {
32 let ident: Ident = input.parse()?;
33 input.parse::<token::Eq>()?;
34
35 match ident.to_string().as_str() {
36 "name" => {
37 worker.name = Some(input.parse::<LitStr>()?.value());
38 }
39 "environment" => {
40 worker.environment = parse_environment(input)?;
41 }
42 "concurrency" => {
43 worker.concurrency = input.parse::<LitInt>()?.base10_parse::<u32>()?;
44 }
45 "fifo" => {
46 worker.fifo = match input.parse::<LitBool>() {
47 Ok(bool) => bool.value,
48 Err(_) => {
49 return Err(input.error("expected boolean value for 'fifo'"));
50 }
51 };
52 }
53 _ => {}
55 }
56
57 if !input.is_empty() {
58 input.parse::<token::Comma>()?;
59 }
60 }
61
62 Ok(worker)
63 }
64}