pub struct Contribution {
pub owner: FeatureName,
pub target: SlotTarget,
pub value: Arc<dyn Any + Send + Sync>,
pub ty: TypeKey,
pub prepend: bool,
pub peer: bool,
}Expand description
One value offered to a service slot, as the registry builder records it.
The feature builder’s contribute methods and
FeatureBuilder::peer_slot
create these. assemble checks each one against the slot’s declaration
and, when it fits, places the value in the slot.
Fields§
§owner: FeatureNameThe feature that contributes the value, or
HOST_FEATURE when the
embedding program contributes it through the registry builder.
target: SlotTargetThe service slot the value is offered to.
value: Arc<dyn Any + Send + Sync>The value itself, held type-erased.
ty: TypeKeyThe type the value was contributed as, checked against the slot’s declared type.
prepend: boolWhether the value precedes, in a slot that takes several values, the contributions that do not ask to come first.
peer: boolWhether this is a peer contribution: a value offered to a service slot another feature owns, which is dropped, rather than failing the registry build, when no feature of the registry declares that slot.
A plain contribution to a slot no feature declares is
ServiceError::UndeclaredSlot, since it usually comes from a
misspelled name. A peer contribution states instead that the slot
belongs to another feature, which may or may not be registered: when no
feature declares the slot, assemble drops the value and records the
contribution as unresolved (Services::peer_contributions), and the
registry build reports one Note. Set it with Contribution::as_peer.
This applies only to a contribution that gives its slot’s name
(SlotTarget::ByName). A contribution that identifies its slot by
type alone has no name the build could report as unresolved, so a type
that no slot has stays ServiceError::UndeclaredSlot.
Implementations§
Source§impl Contribution
impl Contribution
Sourcepub fn new<S: ?Sized + Any + Send + Sync>(
owner: impl Into<FeatureName>,
target: SlotTarget,
imp: Arc<S>,
prepend: bool,
) -> Contribution
pub fn new<S: ?Sized + Any + Send + Sync>( owner: impl Into<FeatureName>, target: SlotTarget, imp: Arc<S>, prepend: bool, ) -> Contribution
Returns the contribution of the value imp to the service slot
target, by the feature owner; prepend says whether the value
comes first (Contribution::prepend).
Write S as the type the slot declares: a trait object type, as in
Contribution::new::<dyn Fetcher>(…), whenever the service is
behavior. A concrete Arc<MyFetcher> may still be passed as imp,
because Rust converts it at the call.
Sourcepub fn as_peer(self) -> Contribution
pub fn as_peer(self) -> Contribution
Marks this contribution as a peer contribution, and returns it: the service slot belongs to another feature, and the value is dropped, rather than the registry build failing, when no feature declares the slot.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Contribution
impl !UnwindSafe for Contribution
impl Forget for Contribution
impl Freeze for Contribution
impl Move for Contribution
impl Send for Contribution
impl Sync for Contribution
impl Unpin for Contribution
impl UnsafeUnpin for Contribution
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