roplat 0.1.0

roplat: just a robot operation system
Documentation
use std::marker::PhantomData;

use crate::resource::{backed, perm};

/// All resource interfaces must implement this trait,
/// which defines the associated command type.
pub trait Interface {
    type Cmd: Send + 'static;
}

/// Unified resource handle structure.
/// T: Interface type (Phantom)
/// B: Backend strategy (Local or Remote)
/// P: Permission marker (ReadOnly or ReadWrite)
pub struct ResHandle<T, B = crate::resource::backed::Local<T>, P = perm::ReadOnly>
where
    T: Interface,
    B: backed::Backend<T, T::Cmd>,
{
    backend: B,
    _marker: PhantomData<(T, P)>,
}

// 手动实现 Clone
impl<T, B, P> Clone for ResHandle<T, B, P>
where
    T: Interface,
    B: backed::Backend<T, T::Cmd> + Clone,
{
    fn clone(&self) -> Self {
        Self { backend: self.backend.clone(), _marker: PhantomData }
    }
}

impl<T, B, P> ResHandle<T, B, P>
where
    T: Interface,
    B: backed::Backend<T, T::Cmd>,
{
    /// 仅限 SystemBuilder 使用
    pub fn from_backend(backend: B) -> Self {
        Self { backend, _marker: PhantomData }
    }

    /// 暴露给宏生成的代码使用
    #[inline(always)]
    pub fn backend(&self) -> &B {
        &self.backend
    }
}