Skip to main content

soil_cli/params/
runtime_params.rs

1// This file is part of Soil.
2
3// Copyright (C) Soil contributors.
4// Copyright (C) Parity Technologies (UK) Ltd.
5// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
6
7use clap::Args;
8use std::str::FromStr;
9
10/// Parameters used to config runtime.
11#[derive(Debug, Clone, Args)]
12pub struct RuntimeParams {
13	/// The size of the instances cache for each runtime [max: 32].
14	///
15	/// Values higher than 32 are illegal.
16	#[arg(long, default_value_t = 8, value_parser = parse_max_runtime_instances)]
17	pub max_runtime_instances: usize,
18
19	/// Maximum number of different runtimes that can be cached.
20	#[arg(long, default_value_t = 2)]
21	pub runtime_cache_size: u8,
22}
23
24fn parse_max_runtime_instances(s: &str) -> Result<usize, String> {
25	let max_runtime_instances = usize::from_str(s)
26		.map_err(|_err| format!("Illegal `--max-runtime-instances` value: {s}"))?;
27
28	if max_runtime_instances > 32 {
29		Err(format!("Illegal `--max-runtime-instances` value: {max_runtime_instances} is more than the allowed maximum of `32` "))
30	} else {
31		Ok(max_runtime_instances)
32	}
33}