1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Copyright 2023 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use std::time::Duration;

use anyhow::bail;

pub mod static_strings;

/// Sets the duration for a trace.
pub enum TraceDuration {
    AlwaysOn,
    StopIn(Duration),
}

impl TryFrom<TraceDuration> for Duration {
    type Error = anyhow::Error;

    fn try_from(duration: TraceDuration) -> anyhow::Result<Self> {
        match duration {
            TraceDuration::AlwaysOn => Ok(Duration::from_millis(0)),
            TraceDuration::StopIn(d) if !d.is_zero() => Ok(d),
            TraceDuration::StopIn(_) => {
                bail!("zero duration not permitted; did you mean TraceDuration::AlwaysOn?")
            }
        }
    }
}