pub struct Services { /* private fields */ }Expand description
The service slots of a registry and the values contributed to them, fixed once the registry is built.
assemble produces it during the registry build, and
FlmRegistry::services
returns it. Every run shares it, and nothing changes it. Read a service by
its type (Services::service, Services::services) or, where two slots
have one type, by slot name (Services::service_named,
Services::services_named). A stage normally reads a service through its
context (StageCx::service) rather
than here.
Implementations§
Source§impl Services
impl Services
Sourcepub fn new() -> Services
pub fn new() -> Services
Returns services with no slot and no value: what a registry holds when no feature declares a service slot.
Sourcepub fn slot(&self, name: &str) -> Option<&SlotDecl>
pub fn slot(&self, name: &str) -> Option<&SlotDecl>
Returns the declaration of the service slot named name, or None
when no slot has that name.
Sourcepub fn slots(&self) -> impl Iterator<Item = &SlotDecl> + '_
pub fn slots(&self) -> impl Iterator<Item = &SlotDecl> + '_
Returns every declared service slot, in name order.
The order does not depend on the order in which the features registered, so a listing built from it is the same in every build.
Sourcepub fn slots_of<S: ?Sized + Any>(&self) -> &[Name]
pub fn slots_of<S: ?Sized + Any>(&self) -> &[Name]
Returns the names of the service slots whose values have the type S,
in name order.
When it returns more than one name, a contribution by type alone is refused as ambiguous, and a read by type alone takes the slots in this order; the operations that take a slot name select one slot.
Sourcepub fn service<S: ?Sized + Any + Send + Sync>(&self) -> Option<&S>
pub fn service<S: ?Sized + Any + Send + Sync>(&self) -> Option<&S>
Returns one service of type S: of the service slots whose values have
that type, taken in name order, the first that holds a value gives the
value that takes precedence in it (the first in the order of
Services::services_by_precedence_named).
Write S as the type the slot declares:
services.service::<dyn Fetcher>(). Returns None when no slot has the
type, or when every such slot is empty; an absent service is a normal
result, and the caller decides what to do about it.
See also Services::service_named, for a slot named directly.
Sourcepub fn services<S: ?Sized + Any + Send + Sync>(
&self,
) -> impl Iterator<Item = &S> + '_
pub fn services<S: ?Sized + Any + Send + Sync>( &self, ) -> impl Iterator<Item = &S> + '_
Returns every service of type S: the values of every service slot
whose values have that type, the slots taken in name order and the
values of each slot in their assembled order (see Arity::OrderedMany).
Sourcepub fn service_named<S: ?Sized + Any + Send + Sync>(
&self,
name: &str,
) -> Option<&S>
pub fn service_named<S: ?Sized + Any + Send + Sync>( &self, name: &str, ) -> Option<&S>
Returns the value of the service slot named name that takes
precedence, read as an S: the first in the order of
Services::services_by_precedence_named, so that between features,
the value of the feature placed last in the feature order.
Returns None when the slot does not exist, holds no value, or holds
values of another type.
Returns the value of the service slot named name that takes
precedence, as Services::service_named does, as the shared pointer
it was contributed as.
Use it to keep that value beyond the borrow of the services, as
Services::shared_named does for every value of a slot.
Sourcepub fn services_named<S: ?Sized + Any + Send + Sync>(
&self,
name: &str,
) -> impl Iterator<Item = &S> + '_
pub fn services_named<S: ?Sized + Any + Send + Sync>( &self, name: &str, ) -> impl Iterator<Item = &S> + '_
Returns every value of the service slot named name, read as S, in
their assembled order: the values contributed with contribute_first
or contribute_first_to come first, then the others, each group in the
order the values were contributed. Returns nothing when the slot does
not exist or holds values of another type.
Sourcepub fn services_by_precedence_named<S: ?Sized + Any + Send + Sync>(
&self,
name: &str,
) -> impl Iterator<Item = &S> + '_
pub fn services_by_precedence_named<S: ?Sized + Any + Send + Sync>( &self, name: &str, ) -> impl Iterator<Item = &S> + '_
Returns every value of the service slot named name, read as S, in
the order of precedence: the values contributed with
contribute_first or contribute_first_to first, then the others;
within each of these two groups, the values of the feature placed last
in the feature order first, each feature’s values in the order the
feature contributed them, and the embedding program’s values last.
Returns nothing when the slot does not exist or holds values of another
type.
Read a slot in this order where its values are asked in turn until one answers, so that between features, the feature placed last wins (see the order of a slot’s values).
Returns every value of the service slot named name, read as S, in
the order of Services::services_named, each as the shared pointer
it was contributed as.
Use it to keep a service beyond the registry build. A lowering rule,
for example, has no access to the registry’s services while it runs,
so a finalizer (Finalizer) hands
it the values of a slot: the pointer is cloned, and the value itself is
shared, not copied.
Sourcepub fn count(&self, name: &str) -> usize
pub fn count(&self, name: &str) -> usize
Returns how many values the service slot named name holds: zero for
a slot that is empty or does not exist.
Sourcepub fn peer_contributions(&self) -> &[PeerContribution]
pub fn peer_contributions(&self) -> &[PeerContribution]
Returns the record of every peer contribution the features made, in the order they made them, each stating whether its service slot is declared.
A peer contribution whose slot no feature declares has resolved set
to false, and its value was dropped when the slots were assembled.
Every peer contribution has its own record, while the registry build
reports one Note per feature and slot.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Services
impl !UnwindSafe for Services
impl Forget for Services
impl Freeze for Services
impl Move for Services
impl Send for Services
impl Sync for Services
impl Unpin for Services
impl UnsafeUnpin for Services
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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