Skip to content

Commit

Permalink
feat: add with_default to OperatorBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
WenyXu committed Dec 11, 2023
1 parent 11faa19 commit ce71b88
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions core/src/types/operator/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,13 +349,21 @@ pub struct OperatorBuilder<A: Accessor> {
}

impl<A: Accessor> OperatorBuilder<A> {
/// Create a new operator builder.
/// Create a new operator builder with default layers.
#[allow(clippy::new_ret_no_self)]
pub fn new(accessor: A) -> OperatorBuilder<impl Accessor> {
// Make sure error context layer has been attached.
OperatorBuilder { accessor }
.layer(ErrorContextLayer)
.layer(CompleteLayer)
Self::with_default(Self::empty(accessor))
}

/// Return an empty [OperatorBuilder].
pub fn empty(accessor: A) -> Self {
Self { accessor }
}

/// Add default layers to builder.
pub fn with_default(builder: OperatorBuilder<impl Accessor>) -> OperatorBuilder<impl Accessor> {
builder.layer(ErrorContextLayer).layer(CompleteLayer)
}

/// Create a new layer with static dispatch.
Expand Down

0 comments on commit ce71b88

Please sign in to comment.