compose_lens/model/
cpu_rt_runtime.rs1use super::lifecycle::valid_stop_grace_period;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
7#[non_exhaustive]
8pub enum CpuRtRuntime {
9 Microseconds(String),
11 Duration(String),
13 Expression(String),
15 Other(String),
17}
18
19impl CpuRtRuntime {
20 pub(crate) fn parse_number(value: String, is_integer: bool) -> Self {
21 if is_integer && value.bytes().all(|byte| byte.is_ascii_digit()) {
22 Self::Microseconds(value)
23 } else {
24 Self::Other(value)
25 }
26 }
27 pub(crate) fn parse_string(value: String) -> Self {
28 if value.contains('$') {
29 Self::Expression(value)
30 } else if valid_stop_grace_period(value.trim_end_matches(['\r', '\n'])) {
31 Self::Duration(value)
32 } else {
33 Self::Other(value)
34 }
35 }
36 #[must_use]
38 pub const fn is_valid(&self) -> bool {
39 !matches!(self, Self::Other(_))
40 }
41}