use anyhow::Result;
use getset::Getters;
use typed_builder::TypedBuilder;
pub use self::current_working_directory::CurrentWorkingDirectory;
use crate::cancellation::Cancellation;
mod current_working_directory;
#[derive(Clone, Debug, Getters, TypedBuilder)]
pub struct Context {
#[builder(setter(into))]
#[getset(get = "pub")]
current_working_directory: CurrentWorkingDirectory,
#[builder(default)]
#[getset(get = "pub")]
cancellation: Cancellation,
}
impl Context {
pub fn try_new(cancellation: Cancellation) -> Result<Self> {
let current_working_directory = CurrentWorkingDirectory::try_from_env()?;
Ok(Self {
current_working_directory,
cancellation,
})
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn trait_send() {
fn assert_send<T: Send>() {}
assert_send::<Context>();
}
#[test]
fn trait_sync() {
fn assert_sync<T: Sync>() {}
assert_sync::<Context>();
}
#[test]
fn trait_unpin() {
fn assert_unpin<T: Unpin>() {}
assert_unpin::<Context>();
}
}