use arc_handle::arc_handle;
#[arc_handle]
pub trait Greeter {
fn greet(&self, name: &str) -> String;
}
struct EnglishGreeter;
impl GreeterImpl for EnglishGreeter {
fn greet(&self, name: &str) -> String {
format!("Hello, {name}!")
}
}
fn main() {
let handle = Greeter::new(EnglishGreeter);
assert_eq!(handle.greet("world"), "Hello, world!");
let cloned = handle.clone();
assert_eq!(cloned.greet("world"), "Hello, world!");
let arc = handle.into_inner();
let handle2 = Greeter::from_arc(arc);
assert_eq!(handle2.greet("world"), "Hello, world!");
let boxed: Box<dyn GreeterImpl + Send + Sync> = Box::new(EnglishGreeter);
let handle3 = Greeter::from_boxed(boxed);
assert_eq!(handle3.greet("world"), "Hello, world!");
}