Skip to main content

FactoryRegistry

Struct FactoryRegistry 

Source
pub struct FactoryRegistry<T>
where T: ?Sized + 'static,
{ /* private fields */ }
Expand description

工厂实现的注册表条目。

存储工厂的元数据,包括其 ID、产品类型 ID 和工厂实例。 此类型与 inventory crate 一起用于编译时注册。

Implementations§

Source§

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

Source

pub const fn new( id: &'static str, factory: &'static (dyn Factory<T> + Sync), ) -> Self

创建一个新的工厂注册表条目。

§参数
  • id - 此工厂的唯一标识符
  • factory - 创建产品的工厂实例
Source

pub fn simple_factory() -> SimpleFactory<T>

查找产品类型 T 的所有已注册工厂。

此函数扫描编译时工厂注册表,并返回一个 SimpleFactory 实例, 该实例包含一个从工厂 ID 到工厂实例的映射,这些工厂实例生产类型 T 的实例。 只包含为确切产品类型 T 注册的工厂。

§返回值

一个 SimpleFactory<T> 实例,包装一个 BTreeMap,其中:

  • 键是工厂的静态字符串标识符
  • 值是实现 Factory<T> 的工厂实例的引用

Trait Implementations§

Source§

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

Auto Trait Implementations§

§

impl<T> Freeze for FactoryRegistry<T>
where T: ?Sized,

§

impl<T> !RefUnwindSafe for FactoryRegistry<T>

§

impl<T> Send for FactoryRegistry<T>
where T: ?Sized,

§

impl<T> Sync for FactoryRegistry<T>
where T: ?Sized,

§

impl<T> Unpin for FactoryRegistry<T>
where T: ?Sized,

§

impl<T> UnsafeUnpin for FactoryRegistry<T>
where T: ?Sized,

§

impl<T> !UnwindSafe for FactoryRegistry<T>

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, 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.