Skip to main content

yang_base/definition/builder/
handle.rs

1//! 预解析 Action slot 句柄与强类型内部调用句柄。
2
3use std::marker::PhantomData;
4
5/// 已预解析的 Action Registry slot。
6#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
7pub struct ActionHandle(pub(super) usize);
8
9impl ActionHandle {
10    /// 返回稳定 slot 索引。
11    pub const fn slot(self) -> usize {
12        self.0
13    }
14}
15
16/// 带 Input/Output 类型信息的预解析内部调用句柄。
17#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
18pub struct TypedActionHandle<I, O> {
19    pub(super) raw: ActionHandle,
20    pub(super) marker: PhantomData<fn(I) -> O>,
21}
22
23impl<I, O> Copy for TypedActionHandle<I, O> {}
24
25impl<I, O> Clone for TypedActionHandle<I, O> {
26    fn clone(&self) -> Self {
27        *self
28    }
29}
30
31impl<I, O> TypedActionHandle<I, O> {
32    /// 返回底层稳定 slot。
33    pub const fn raw(self) -> ActionHandle {
34        self.raw
35    }
36}