Struct Managed

Source
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>

Source

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.

Source

pub fn wrap<S>(&self, other: S) -> Managed<S>
where S: Counted,

Creates another Managed instance, with a new value but shared metadata.

Source

pub fn received_at(&self) -> DateTime<Utc>

Original received timestamp.

Source

pub fn scoping(&self) -> Scoping

Scoping information stored in this context.

Source

pub fn split_once<F, S, U>(self, f: F) -> (Managed<S>, Managed<U>)
where F: FnOnce(T) -> (S, U), S: Counted, U: Counted,

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.

Source

pub fn split<F, I, S>(self, f: F) -> Split<I::IntoIter, I::Item>
where F: FnOnce(T) -> I, I: IntoIterator<Item = S>, S: Counted,

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.

Source

pub fn split_with_context<F, I, S, C>( self, f: F, ) -> (Split<I::IntoIter, I::Item>, C)
where F: FnOnce(T) -> (I, C), I: IntoIterator<Item = S>, S: Counted,

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.

Source

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!()
}
Source

pub fn retain_with_context<S, C, I, U, E>(&mut self, select: S, retain: U)
where for<'a> S: FnOnce(&'a mut T) -> (&'a mut Vec<I>, &'a C), I: Counted, U: FnMut(&mut I, &C, &mut RecordKeeper<'_>) -> Result<(), E>, E: OutcomeError,

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!()
}
Source

pub fn map<S, F>(self, f: F) -> Managed<S>
where F: FnOnce(T, &mut RecordKeeper<'_>) -> S, S: Counted,

Maps a Managed<T> to Managed<S> by applying the mapping function f.

Like Self::try_map but not fallible.

Source

pub fn try_map<S, F, E>(self, f: F) -> Result<Managed<S>, Rejected<E::Error>>
where F: FnOnce(T, &mut RecordKeeper<'_>) -> Result<S, E>, S: Counted, E: OutcomeError,

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.

Source

pub fn modify<F>(&mut self, f: F)
where F: FnOnce(&mut T, &mut RecordKeeper<'_>),

Gives mutable access to the contained value to modify it.

Like Self::try_modify but not fallible.

Source

pub fn try_modify<F, E>(&mut self, f: F) -> Result<(), Rejected<E::Error>>
where F: FnOnce(&mut T, &mut RecordKeeper<'_>) -> Result<(), E>, E: OutcomeError,

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.

Source

pub fn accept<F, S>(self, f: F) -> S
where 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.

Source

pub fn try_accept<F, S, E>(self, f: F) -> Result<S, Rejected<E::Error>>
where F: FnOnce(T) -> Result<S, E>, E: OutcomeError,

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.

Source

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.

Source

pub fn reject_err<E>(&self, error: E) -> Rejected<E::Error>
where E: OutcomeError,

Rejects the entire Managed instance.

Trait Implementations§

Source§

impl<T: Counted> AsRef<T> for Managed<T>

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T: Counted + Debug> Debug for Managed<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Counted> Deref for Managed<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: Counted> Drop for Managed<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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
where A: Access<T> + ?Sized, P: Deref<Target = A>,

§

type Guard = <A as Access<T>>::Guard

A guard object containing the value and keeping it alive. Read more
§

fn load(&self) -> <P as Access<T>>::Guard

The loading method. Read more
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
§

impl<T, A> DynAccess<T> for A
where A: Access<T>, <A as Access<T>>::Guard: 'static,

§

fn load(&self) -> DynGuard<T>

The equivalent of [Access::load].
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> Formattable for T
where T: Deref, <T as Deref>::Target: Formattable,

§

impl<T> MaybeSendSync for T

§

impl<T> Parsable for T
where T: Deref, <T as Deref>::Target: Parsable,