Skip to main content

UpcasterChain

Struct UpcasterChain 

Source
pub struct UpcasterChain<Event, Upcaster> { /* private fields */ }
Expand description

English:
Insertion-ordered sequence of upcasters of a single concrete type. Each stage consumes the preceding output. The chain does not select stages by event identity, sort versions, or restore an event after failure. Use an enum or another common upcaster type when stages need different behaviors. It stores no event value and adds no locking.

Add stages explicitly; each successful result becomes the next input.

日本語:
同じ具体型の変換器を追加順に保持する列です。 各段階は直前の出力を消費します。イベント識別情報による段階の選択、バージョンの並べ替え、 失敗後のイベント復元はしません。異なる動作の段階には列挙型などの共通の変換器型を用います。 イベント値は保持せず、ロックも追加しません。

段階を明示的に追加すると、各段階の成功結果が次の入力になります。

§Example / 使用例

use ddd_toolkit_core::{EventUpcaster, UpcasterChain};

struct Append(&'static str);
impl EventUpcaster<String> for Append {
    type Error = std::convert::Infallible;
    fn upcast(&self, mut event: String) -> Result<String, Self::Error> {
        event.push_str(self.0);
        Ok(event)
    }
}
let mut chain = UpcasterChain::new();
chain.push(Append("-v2"));
chain.push(Append("-v3"));
assert_eq!(chain.apply(String::from("v1")).unwrap(), "v1-v2-v3");
assert_eq!(chain.len(), 2);

Implementations§

Source§

impl<Event, Upcaster> UpcasterChain<Event, Upcaster>

Source

pub fn new() -> UpcasterChain<Event, Upcaster>

English:
Creates an empty chain, also used by Default::default. Applying an empty chain returns the input unchanged.

日本語:
Default::default でも使う空の列を作ります。 空の列を適用すると、入力を変更せず返します。

Source

pub fn push(&mut self, upcaster: Upcaster)

English:
Appends upcaster as the last stage without inspecting its version or running it.

日本語:
バージョンを調べたり実行したりせず、upcaster を最後の段階に追加します。

Source

pub fn len(&self) -> usize

English:
Returns the number of stored stages, not the number of supported event versions.

日本語:
対応するイベントバージョン数ではなく、保持する段階数を返します。

Source

pub fn is_empty(&self) -> bool

English:
Returns true when no upcasters have been added.

日本語:
変換器を一つも追加していない場合に true を返します。

Source

pub fn apply( &self, event: Event, ) -> Result<Event, <Upcaster as EventUpcaster<Event>>::Error>
where Upcaster: EventUpcaster<Event>,

English:
Runs all stages in insertion order and returns the final owned event. The first error stops evaluation and is returned unchanged; later stages are not called. Earlier side effects are not rolled back. An empty chain returns Ok(event). Panics from a stage propagate, and the chain itself remains stored for future calls.

日本語:
全段階を追加順に実行し、最後の所有されたイベントを返します。 最初のエラーで評価を止め、変更せず返します。後続の段階は呼び出しません。 先行する副作用は取り消しません。空の列は Ok(event) を返します。 段階のパニックは伝播し、列自体は後続の呼び出しにも使えるよう保持されます。

Trait Implementations§

Source§

impl<Event, Upcaster> Default for UpcasterChain<Event, Upcaster>

Source§

fn default() -> UpcasterChain<Event, Upcaster>

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

Auto Trait Implementations§

§

impl<Event, Upcaster> Freeze for UpcasterChain<Event, Upcaster>
where Vec<Upcaster>: Freeze, PhantomData<fn() -> Event>: Freeze,

§

impl<Event, Upcaster> RefUnwindSafe for UpcasterChain<Event, Upcaster>
where Vec<Upcaster>: RefUnwindSafe, PhantomData<fn() -> Event>: RefUnwindSafe,

§

impl<Event, Upcaster> Send for UpcasterChain<Event, Upcaster>
where Vec<Upcaster>: Send, PhantomData<fn() -> Event>: Send,

§

impl<Event, Upcaster> Sync for UpcasterChain<Event, Upcaster>
where Vec<Upcaster>: Sync, PhantomData<fn() -> Event>: Sync,

§

impl<Event, Upcaster> Unpin for UpcasterChain<Event, Upcaster>
where Vec<Upcaster>: Unpin, PhantomData<fn() -> Event>: Unpin,

§

impl<Event, Upcaster> UnsafeUnpin for UpcasterChain<Event, Upcaster>
where Vec<Upcaster>: UnsafeUnpin, PhantomData<fn() -> Event>: UnsafeUnpin,

§

impl<Event, Upcaster> UnwindSafe for UpcasterChain<Event, Upcaster>
where Vec<Upcaster>: UnwindSafe, PhantomData<fn() -> Event>: UnwindSafe,

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.