Skip to main content

CapabilityRegistry

Struct CapabilityRegistry 

Source
pub struct CapabilityRegistry { /* private fields */ }
Expand description

中心能力注册表,提供注册/发现/调用的统一入口。

内部使用 parking_lot::RwLock<HashMap<String, Arc<dyn Capability>>> 保证并发安全。 所有读操作(get/find/search/list)在读锁内完成 Arc 克隆后释放锁,不跨 await 点。

§调用链路

call / call_with_tenant 执行三步链路:参数校验 → 权限检查 → 能力调用。 未设置 PermissionChecker 时默认放行。

§性能指标

操作延迟
register~187 ns
get~38 ns
find_by_tags (1000 能力)~20 μs

Implementations§

Source§

impl CapabilityRegistry

Source

pub fn new() -> Self

Source

pub fn set_permission_checker(&self, checker: Arc<dyn PermissionChecker>)

设置权限检查器,设置后所有 call / call_with_tenant 将在能力调用前执行权限检查。

Source

pub fn register(&self, cap: Arc<dyn Capability>) -> Option<Arc<dyn Capability>>

Source

pub fn unregister(&self, name: &str) -> Option<Arc<dyn Capability>>

Source

pub fn get(&self, name: &str) -> Option<Arc<dyn Capability>>

Source

pub fn find_by_tags( &self, tags: &[&str], source: Option<CapabilitySource>, ) -> Vec<Arc<dyn Capability>>

Source

pub fn search(&self, query: &str) -> Vec<Arc<dyn Capability>>

Source

pub fn list_all(&self) -> Vec<Arc<dyn Capability>>

Source

pub fn list_by_source( &self, source: CapabilitySource, ) -> Vec<Arc<dyn Capability>>

Source

pub async fn call(&self, name: &str, args: Value) -> CapResult<Value>

调用能力,使用默认 tenant_id = 0(无租户上下文)。

执行链路:参数校验 → 权限检查 → 能力调用。

Source

pub async fn call_with_tenant( &self, name: &str, args: Value, tenant_id: i64, ) -> CapResult<Value>

调用能力,携带租户上下文用于权限检查。

执行链路:参数校验 → 权限检查 → 能力调用。 未设置 PermissionChecker 时默认放行。

Source

pub fn len(&self) -> usize

Source

pub fn is_empty(&self) -> bool

Source

pub fn metrics(&self) -> CapMetrics

Source

pub fn list_info(&self) -> Vec<CapabilityInfo>

Trait Implementations§

Source§

impl Default for CapabilityRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more