1 // Copyright 2023 The ChromiumOS Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 use std::time::Duration; 6 7 use anyhow::bail; 8 9 pub mod static_strings; 10 11 /// Sets the duration for a trace. 12 pub enum TraceDuration { 13 AlwaysOn, 14 StopIn(Duration), 15 } 16 17 impl TryFrom<TraceDuration> for Duration { 18 type Error = anyhow::Error; 19 try_from(duration: TraceDuration) -> anyhow::Result<Self>20 fn try_from(duration: TraceDuration) -> anyhow::Result<Self> { 21 match duration { 22 TraceDuration::AlwaysOn => Ok(Duration::from_millis(0)), 23 TraceDuration::StopIn(d) if !d.is_zero() => Ok(d), 24 TraceDuration::StopIn(_) => { 25 bail!("zero duration not permitted; did you mean TraceDuration::AlwaysOn?") 26 } 27 } 28 } 29 } 30