use super::handle::ResourceHandle;
use crate::actor::ActorId;
use std::sync::Arc;
#[must_use]
pub struct Capability<H: ResourceHandle> {
owner: ActorId,
handle: Arc<H>,
}
impl<H: ResourceHandle> Capability<H> {
pub fn new(owner: ActorId, handle: H) -> Self {
Self {
owner,
handle: Arc::new(handle),
}
}
pub fn owner(&self) -> ActorId {
self.owner
}
pub fn handle(&self) -> &H {
&self.handle
}
pub fn into_handle(self) -> Arc<H> {
self.handle
}
}
impl<H: ResourceHandle> Clone for Capability<H> {
fn clone(&self) -> Self {
Self {
owner: self.owner,
handle: Arc::clone(&self.handle),
}
}
}