Skip to main content

Container

Struct Container 

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

See the crate docs.

Implementations§

Source§

impl Container

Source

pub fn new() -> Container

Source

pub fn epoch(&self) -> u64

Changes whenever any binding, alias, extender, contextual binding, tag or callback changes, whenever an instance is forgotten, and at every request start and end. Resolving never changes it. A cache built at another epoch must re-check; one built at this epoch is current.

Source

pub fn registering(&self, lifetime: Lifetime) -> Registering<'_>

Registrations made while the returned guard lives get lifetime (a bridge sets Request around PHP’s calls).

Source

pub fn set_autowirer(&self, autowirer: Rc<dyn Autowirer>)

Who builds keys that have no entry.

Source

pub fn bind( &self, key: &str, factory: impl Fn(&Container, &Params) -> Result<Resolved, ContainerError> + 'static, )

Source

pub fn bind_if( &self, key: &str, factory: impl Fn(&Container, &Params) -> Result<Resolved, ContainerError> + 'static, )

Source

pub fn singleton( &self, key: &str, factory: impl Fn(&Container, &Params) -> Result<Resolved, ContainerError> + 'static, )

Source

pub fn singleton_if( &self, key: &str, factory: impl Fn(&Container, &Params) -> Result<Resolved, ContainerError> + 'static, )

Source

pub fn scoped( &self, key: &str, factory: impl Fn(&Container, &Params) -> Result<Resolved, ContainerError> + 'static, )

Shared until the request ends.

Source

pub fn scoped_if( &self, key: &str, factory: impl Fn(&Container, &Params) -> Result<Resolved, ContainerError> + 'static, )

Source

pub fn instance(&self, key: &str, value: Resolved)

Source

pub fn bind_foreign( &self, key: &str, factory: impl Fn(&Container, &Params) -> Result<Resolved, ContainerError> + 'static, )

A binding made by a language bridge: Container::is_foreign is true while it is on top.

Source

pub fn singleton_foreign( &self, key: &str, factory: impl Fn(&Container, &Params) -> Result<Resolved, ContainerError> + 'static, )

Source

pub fn scoped_foreign( &self, key: &str, factory: impl Fn(&Container, &Params) -> Result<Resolved, ContainerError> + 'static, )

As Container::bind_foreign, shared until the request ends.

Source

pub fn instance_foreign(&self, key: &str, value: Resolved)

An instance registered by a language bridge.

Source

pub fn bind_port<P: ?Sized + 'static>( &self, key: &str, factory: impl Fn(&Container, &Params) -> Result<Rc<P>, ContainerError> + 'static, )

Binds a port (a trait object) by its key.

Source

pub fn singleton_port<P: ?Sized + 'static>( &self, key: &str, factory: impl Fn(&Container, &Params) -> Result<Rc<P>, ContainerError> + 'static, )

Source

pub fn make_port<P: ?Sized + 'static>( &self, key: &str, ) -> Result<Rc<P>, ContainerError>

The value of a port binding, as its trait object.

Source

pub fn alias(&self, key: &str, alias: &str)

alias resolves to key. Panics on an alias cycle (use Container::try_alias to handle it).

Source

pub fn try_alias(&self, key: &str, alias: &str) -> Result<(), ContainerError>

Source

pub fn is_alias(&self, key: &str) -> bool

Source

pub fn get_alias(&self, key: &str) -> String

The key an alias finally resolves to (the key itself when it is no alias).

Source

pub fn extend( &self, key: &str, extender: impl Fn(Resolved, &Container) -> Result<Resolved, ContainerError> + 'static, )

Decorates every value key resolves to, from now on; an already shared value is decorated at once.

Source

pub fn when(&self, consumer: &str) -> When<'_>

Source

pub fn tag(&self, keys: &[&str], tag: &str)

Source

pub fn tagged(&self, tag: &str) -> Result<Vec<Resolved>, ContainerError>

Every key with tag, resolved, in tag order.

Source

pub fn before_resolving( &self, key: Option<&str>, callback: impl Fn(&str, &Container) + 'static, )

Source

pub fn resolving( &self, key: Option<&str>, callback: impl Fn(&Resolved, &Container) + 'static, )

Source

pub fn after_resolving( &self, key: Option<&str>, callback: impl Fn(&Resolved, &Container) + 'static, )

Source

pub fn sharing(&self, key: &str) -> Option<Sharing>

How the entry answering key (after aliases) shares its value: an instance counts as a singleton; None when key has no entry.

Source

pub fn has(&self, key: &str) -> bool

True when key (or what it aliases) has an entry.

Source

pub fn bound(&self, key: &str) -> bool

The same as Container::has (Laravel’s bound).

Source

pub fn generation(&self, key: &str) -> u64

Changes whenever what key (or what it aliases) resolves to may change: a binding, instance, extender or forgetting. A cache of a resolved value is current while this is unchanged.

Source

pub fn resolved(&self, key: &str) -> bool

Whether key has been resolved at least once.

Source

pub fn is_foreign(&self, key: &str) -> bool

Whether the entry answering for key now was registered by a language bridge.

Source

pub fn make(&self, key: &str) -> Result<Resolved, ContainerError>

Source

pub fn make_with( &self, key: &str, params: &Params, ) -> Result<Resolved, ContainerError>

Builds key with params; never returns nor becomes a shared instance when params is not empty.

Source

pub fn factory<'a>( &'a self, key: &str, ) -> impl Fn() -> Result<Resolved, ContainerError> + 'a

A function that makes key each time it is called.

Source

pub fn resolved_in_request(&self, key: &str) -> bool

Whether key was resolved since the request started (a cached shared value counts).

Source

pub fn start_request(&self)

Starts a request: nothing counts as resolved in it yet.

Source

pub fn forget_instance(&self, key: &str)

Drops the shared value of key (and its registered instances).

Source

pub fn forget_instances(&self)

Drops every shared value and registered instance.

Source

pub fn forget_scoped_instances(&self)

Drops every scoped value; singletons stay.

Source

pub fn flush(&self)

Forgets everything.

Source

pub fn end_request(&self)

Ends the request: removes every Request registration (bindings, instances, aliases, extenders, contextual bindings, tags, callbacks) and every scoped value. Each key answers with its worker-lifetime entry again.

Trait Implementations§

Source§

impl Default for Container

Source§

fn default() -> Self

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

impl Drop for Container

A dropped container moves the epoch, so a PortCell warmed while it lived stops answering from its cache and reports the container as gone.

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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<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 = !

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

fn try_from(value: U) -> Result<T, !>

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.