pub struct Managed<T: Counted> { /* private fields */ }
Expand description
The Managed
wrapper ensures outcomes are correctly emitted for the contained item.
Implementations§
Source§impl<T: Counted> Managed<T>
impl<T: Counted> Managed<T>
Sourcepub fn from_envelope(envelope: &ManagedEnvelope, value: T) -> Self
pub fn from_envelope(envelope: &ManagedEnvelope, value: T) -> Self
Creates a new managed instance with a value
from a ManagedEnvelope
.
The Managed
instance, inherits all metadata from the passed ManagedEnvelope
,
like received time or scoping.
Sourcepub fn wrap<S>(&self, other: S) -> Managed<S>where
S: Counted,
pub fn wrap<S>(&self, other: S) -> Managed<S>where
S: Counted,
Creates another Managed
instance, with a new value but shared metadata.
Sourcepub fn received_at(&self) -> DateTime<Utc>
pub fn received_at(&self) -> DateTime<Utc>
Original received timestamp.
Sourcepub fn split_once<F, S, U>(self, f: F) -> (Managed<S>, Managed<U>)
pub fn split_once<F, S, U>(self, f: F) -> (Managed<S>, Managed<U>)
Splits Self
into two other Managed
items.
The two resulting managed instances together are expected to have the same outcomes as the original instance.. Since splitting may introduce a new type of item, which some of the original quantities are transferred to, there may be new additional data categories created.
Sourcepub fn split<F, I, S>(self, f: F) -> Split<I::IntoIter, I::Item> ⓘ
pub fn split<F, I, S>(self, f: F) -> Split<I::IntoIter, I::Item> ⓘ
Splits Self
into a variable amount if individual items.
Useful when the current instance contains multiple items of the same type and must be split into individually managed items.
Sourcepub fn split_with_context<F, I, S, C>(
self,
f: F,
) -> (Split<I::IntoIter, I::Item>, C)
pub fn split_with_context<F, I, S, C>( self, f: F, ) -> (Split<I::IntoIter, I::Item>, C)
Splits Self
into a variable amount if individual items.
Like Self::split
but also allows returning an untracked context,
a way of returning additional data when deconstructing the original item.
Sourcepub fn retain<S, I, U, E>(&mut self, select: S, retain: U)where
S: FnOnce(&mut T) -> &mut Vec<I>,
I: Counted,
U: FnMut(&mut I, &mut RecordKeeper<'_>) -> Result<(), E>,
E: OutcomeError,
pub fn retain<S, I, U, E>(&mut self, select: S, retain: U)where
S: FnOnce(&mut T) -> &mut Vec<I>,
I: Counted,
U: FnMut(&mut I, &mut RecordKeeper<'_>) -> Result<(), E>,
E: OutcomeError,
Filters individual items and emits outcomes for them if they are removed.
This is particularly useful when the managed instance is a container of individual items, which need to be processed or filtered on a case by case basis.
§Examples:
struct Items {
items: Vec<Item>,
}
fn process_items(items: &mut Managed<Items>, ctx: Context<'_>) {
items.retain(|items| &mut items.items, |item, _| process(item, ctx));
}
fn process(item: &mut Item, ctx: Context<'_>) -> Result<(), Error> {
todo!()
}
Sourcepub fn retain_with_context<S, C, I, U, E>(&mut self, select: S, retain: U)
pub fn retain_with_context<S, C, I, U, E>(&mut self, select: S, retain: U)
Filters individual items and emits outcomes for them if they are removed.
Like Self::retain
, but it allows for an additional context extracted from the managed
object passed to the retain function.
§Examples:
struct Items {
ty: String,
items: Vec<Item>,
}
fn process_items(items: &mut Managed<Items>, ctx: Context<'_>) {
items.retain_with_context(|items| (&mut items.items, &items.ty), |item, ty, _| process(item, ty, ctx));
}
fn process(item: &mut Item, ty: &str, ctx: Context<'_>) -> Result<(), Error> {
todo!()
}
Sourcepub fn map<S, F>(self, f: F) -> Managed<S>
pub fn map<S, F>(self, f: F) -> Managed<S>
Maps a Managed<T>
to Managed<S>
by applying the mapping function f
.
Like Self::try_map
but not fallible.
Sourcepub fn try_map<S, F, E>(self, f: F) -> Result<Managed<S>, Rejected<E::Error>>
pub fn try_map<S, F, E>(self, f: F) -> Result<Managed<S>, Rejected<E::Error>>
Maps a Managed<T>
to Managed<S>
by applying the mapping function f
.
The mapping function gets access to a RecordKeeper
, to emit outcomes for partial
discards.
If the mapping function returns an error, the entire (original) Self
is rejected,
no partial outcomes are emitted.
Sourcepub fn modify<F>(&mut self, f: F)
pub fn modify<F>(&mut self, f: F)
Gives mutable access to the contained value to modify it.
Like Self::try_modify
but not fallible.
Sourcepub fn try_modify<F, E>(&mut self, f: F) -> Result<(), Rejected<E::Error>>
pub fn try_modify<F, E>(&mut self, f: F) -> Result<(), Rejected<E::Error>>
Gives mutable access to the contained value to modify it.
The modifying function gets access to a RecordKeeper
, to emit outcomes for partial
discards.
If the modifying function returns an error, the entire (original) Self
is rejected,
no partial outcomes are emitted.
Sourcepub fn accept<F, S>(self, f: F) -> Swhere
F: FnOnce(T) -> S,
pub fn accept<F, S>(self, f: F) -> Swhere
F: FnOnce(T) -> S,
Accepts the item of this managed instance.
This should be called if the item has been or is about to be accepted by the upstream, which means that the responsibility for logging outcomes has been moved. This function will not log any outcomes.
Like Self::try_accept
, but infallible.
Sourcepub fn try_accept<F, S, E>(self, f: F) -> Result<S, Rejected<E::Error>>
pub fn try_accept<F, S, E>(self, f: F) -> Result<S, Rejected<E::Error>>
Accepts the item of this managed instance.
This should be called if the item has been or is about to be accepted by the upstream.
Outcomes are only emitted when the accepting closure returns an error, which means that in the success case the responsibility for logging outcomes has been moved to the caller/upstream.
Sourcepub fn internal_error(&self, reason: &'static str) -> Rejected<()>
pub fn internal_error(&self, reason: &'static str) -> Rejected<()>
Rejects the entire Managed
instance with an internal error.
Internal errors should be reserved for uses where logical invariants are violated. Cases which should never happen and always indicate a logical bug.
This function will panic in debug builds, but discard the item with an internal discard reason in release builds.
Sourcepub fn reject_err<E>(&self, error: E) -> Rejected<E::Error>where
E: OutcomeError,
pub fn reject_err<E>(&self, error: E) -> Rejected<E::Error>where
E: OutcomeError,
Rejects the entire Managed
instance.
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for Managed<T>
impl<T> RefUnwindSafe for Managed<T>where
T: RefUnwindSafe,
impl<T> Send for Managed<T>where
T: Send,
impl<T> Sync for Managed<T>where
T: Sync,
impl<T> Unpin for Managed<T>where
T: Unpin,
impl<T> UnwindSafe for Managed<T>where
T: UnwindSafe,
Blanket Implementations§
§impl<T, A, P> Access<T> for P
impl<T, A, P> Access<T> for P
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<T, A> DynAccess<T> for Awhere
A: Access<T>,
<A as Access<T>>::Guard: 'static,
impl<T, A> DynAccess<T> for Awhere
A: Access<T>,
<A as Access<T>>::Guard: 'static,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered
].