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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
/// ProcessName is used to uniquely name a process from a Rust type.
///
/// It is implemented for common string types such as `&str` and `String`,
/// but can be implemented on a custom type to create a process name type.
///
/// It is best used with the [ProcessName](lunatic_macros::ProcessName) derive
/// macro to generate a unique name.
///
/// # Example
///
/// ```
/// #[derive(ProcessName)]
/// struct LoggingProcess;
///
/// let process = lunatic::spawn!(|| { /* ... */});
/// process.register(&LoggingProcess);
/// ```
///
/// Alternatively, you can implement the trait manually.
///
/// ```
/// struct LoggingProcess;
///
/// impl ProcessName for LoggingProcess {
/// fn process_name(&self) -> &str {
/// "global_logging_process"
/// }
/// }
/// ```
///
/// For more information, see the [derive macro](lunatic_macros::ProcessName)
/// docs.
pub trait ProcessName {
fn process_name(&self) -> &str;
}
impl ProcessName for str {
fn process_name(&self) -> &str {
self
}
}
impl ProcessName for &str {
fn process_name(&self) -> &str {
self
}
}
impl ProcessName for String {
fn process_name(&self) -> &str {
self.as_str()
}
}
impl<'a> ProcessName for std::borrow::Cow<'a, str> {
fn process_name(&self) -> &str {
self
}
}