Use Cow<'a,B> for toplevel configuration

This commit is contained in:
bakaq
2024-12-12 05:59:59 -03:00
parent 500a6cdaf1
commit 74e3d32ca9
2 changed files with 12 additions and 6 deletions

View File

@@ -1,3 +1,5 @@
use std::borrow::Cow;
use rand::{rngs::StdRng, SeedableRng};
use crate::Machine;
@@ -41,7 +43,7 @@ enum StreamConfigInner {
/// Describes how a [`Machine`](crate::Machine) will be configured.
pub struct MachineBuilder {
pub(crate) streams: StreamConfig,
pub(crate) toplevel: &'static str,
pub(crate) toplevel: Cow<'static, str>,
}
impl Default for MachineBuilder {
@@ -49,7 +51,7 @@ impl Default for MachineBuilder {
fn default() -> Self {
MachineBuilder {
streams: Default::default(),
toplevel: default_toplevel(),
toplevel: default_toplevel().into(),
}
}
}
@@ -67,8 +69,8 @@ impl MachineBuilder {
}
/// Uses the given toplevel in this configuration.
pub fn with_toplevel(mut self, toplevel: &'static str) -> Self {
self.toplevel = toplevel;
pub fn with_toplevel(mut self, toplevel: impl Into<Cow<'static, str>>) -> Self {
self.toplevel = toplevel.into();
self
}