pub trait Object:
From<Family<Self>>
+ Sized
+ Clone
+ 'static {
// Required method
fn family(&self) -> Family<Self>;
}
Expand description
Operations available on every instance of a linked object.
The only supported way to implement this is via #[linked::object]
.
Required Methods§
Sourcefn family(&self) -> Family<Self>
fn family(&self) -> Family<Self>
The object family that the current instance is linked to.
The returned object can be used to create additional instances linked to the same family.
§Example
use std::thread;
use linked::Object; // Import trait to access .family() method
let resource = SharedResource::new("initial".to_string());
// Get the family handle from an existing instance
let family = resource.family();
// Use the family to create a new instance on another thread
thread::spawn(move || {
let new_resource: SharedResource = family.into();
// This new instance shares state with the original
new_resource.set_data("updated".to_string());
})
.join()
.unwrap();
// The original instance sees the update
assert_eq!(resource.get_data(), "updated");
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.