From 97b2675a89eb827d9dd459db0bd6c496ee78bd45 Mon Sep 17 00:00:00 2001 From: WenyXu Date: Mon, 11 Dec 2023 06:17:41 +0000 Subject: [PATCH] feat: add `with_default` to `OperatorBuilder` --- core/src/types/operator/builder.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/core/src/types/operator/builder.rs b/core/src/types/operator/builder.rs index 785b8622964..2cb93cdfc51 100644 --- a/core/src/types/operator/builder.rs +++ b/core/src/types/operator/builder.rs @@ -349,13 +349,21 @@ pub struct OperatorBuilder { } impl OperatorBuilder { - /// 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 { // 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) -> OperatorBuilder { + builder.layer(ErrorContextLayer).layer(CompleteLayer) } /// Create a new layer with static dispatch.