pub struct Transformed<T> {
pub data: T,
pub transformed: bool,
pub tnr: TreeNodeRecursion,
}Expand description
Result of tree walk / transformation APIs
Transformed is a wrapper around the tree node data (e.g. Expr or
LogicalPlan). It is used to indicate whether the node was transformed
and how the recursion should proceed.
TreeNode API users control the transformation by returning:
- The resulting (possibly transformed) node,
transformed: flag indicating whether any change was made to the nodetnr:TreeNodeRecursionspecifying how to proceed with the recursion.
At the end of the transformation, the return value will contain:
- The final (possibly transformed) tree,
transformed: flag indicating whether any change was made to the nodetnr:TreeNodeRecursionspecifying how the recursion ended.
See also
Transformed::update_datato modify the node without changing thetransformedflagTransformed::map_datafor fallable operation that return the same typeTransformed::transform_datato chain fallable transformationsTransformedResultfor working withResult<Transformed<U>>
§Examples
Use Transformed::yes and Transformed::no to signal that a node was
rewritten and the recursion should continue:
let expr = orig_expr();
// Create a new `Transformed` object signaling the node was not rewritten
let ret = Transformed::no(expr.clone());
assert!(!ret.transformed);
// Create a new `Transformed` object signaling the node was rewritten
let ret = Transformed::yes(expr);
assert!(ret.transformed)Access the node within the Transformed object:
let expr = orig_expr();
// `Transformed` object signaling the node was not rewritten
let ret = Transformed::no(expr.clone());
// Access the inner object using .data
assert_eq!(expr, ret.data);Transform the node within the Transformed object.
let expr = orig_expr();
let ret = Transformed::no(expr.clone())
.transform_data(|expr| {
// closure returns a result and potentially transforms the node
// in this example, it does transform the node
let new_expr = make_new_expr(expr);
Ok(Transformed::yes(new_expr))
}).unwrap();
// transformed flag is the union of the original ans closure's transformed flag
assert!(ret.transformed);§Example APIs that use TreeNode
Fields§
§data: T§transformed: bool§tnr: TreeNodeRecursionImplementations§
Source§impl<T> Transformed<T>
impl<T> Transformed<T>
Sourcepub fn new(data: T, transformed: bool, tnr: TreeNodeRecursion) -> Transformed<T>
pub fn new(data: T, transformed: bool, tnr: TreeNodeRecursion) -> Transformed<T>
Create a new Transformed object with the given information.
Sourcepub fn new_transformed(data: T, transformed: bool) -> Transformed<T>
pub fn new_transformed(data: T, transformed: bool) -> Transformed<T>
Create a Transformed with transformed and TreeNodeRecursion::Continue.
Sourcepub fn yes(data: T) -> Transformed<T>
pub fn yes(data: T) -> Transformed<T>
Wrapper for transformed data with TreeNodeRecursion::Continue statement.
Sourcepub fn complete(data: T) -> Transformed<T>
pub fn complete(data: T) -> Transformed<T>
Wrapper for transformed data with TreeNodeRecursion::Stop statement.
Sourcepub fn no(data: T) -> Transformed<T>
pub fn no(data: T) -> Transformed<T>
Wrapper for unchanged data with TreeNodeRecursion::Continue statement.
Sourcepub fn update_data<U, F>(self, f: F) -> Transformed<U>where
F: FnOnce(T) -> U,
pub fn update_data<U, F>(self, f: F) -> Transformed<U>where
F: FnOnce(T) -> U,
Applies an infallible f to the data of this Transformed object,
without modifying the transformed flag.
Sourcepub fn map_data<U, F>(self, f: F) -> Result<Transformed<U>, DataFusionError>
pub fn map_data<U, F>(self, f: F) -> Result<Transformed<U>, DataFusionError>
Applies a fallible f (returns Result) to the data of this
Transformed object, without modifying the transformed flag.
Sourcepub fn transform_data<U, F>(
self,
f: F,
) -> Result<Transformed<U>, DataFusionError>
pub fn transform_data<U, F>( self, f: F, ) -> Result<Transformed<U>, DataFusionError>
Applies a fallible transforming f to the data of this Transformed
object.
The returned Transformed object has the transformed flag set if either
self or the return value of f have the transformed flag set.
Sourcepub fn transform_children<F>(
self,
f: F,
) -> Result<Transformed<T>, DataFusionError>
pub fn transform_children<F>( self, f: F, ) -> Result<Transformed<T>, DataFusionError>
Maps the Transformed object to the result of the given f depending on the
current TreeNodeRecursion value and the fact that f is changing the current
node’s children.
Sourcepub fn transform_sibling<F>(
self,
f: F,
) -> Result<Transformed<T>, DataFusionError>
pub fn transform_sibling<F>( self, f: F, ) -> Result<Transformed<T>, DataFusionError>
Maps the Transformed object to the result of the given f depending on the
current TreeNodeRecursion value and the fact that f is changing the current
node’s sibling.
Sourcepub fn transform_parent<F>(
self,
f: F,
) -> Result<Transformed<T>, DataFusionError>
pub fn transform_parent<F>( self, f: F, ) -> Result<Transformed<T>, DataFusionError>
Maps the Transformed object to the result of the given f depending on the
current TreeNodeRecursion value and the fact that f is changing the current
node’s parent.
Trait Implementations§
Source§impl<T> Debug for Transformed<T>where
T: Debug,
impl<T> Debug for Transformed<T>where
T: Debug,
Source§impl<T> PartialEq for Transformed<T>where
T: PartialEq,
impl<T> PartialEq for Transformed<T>where
T: PartialEq,
impl<T> StructuralPartialEq for Transformed<T>
Auto Trait Implementations§
impl<T> Freeze for Transformed<T>where
T: Freeze,
impl<T> RefUnwindSafe for Transformed<T>where
T: RefUnwindSafe,
impl<T> Send for Transformed<T>where
T: Send,
impl<T> Sync for Transformed<T>where
T: Sync,
impl<T> Unpin for Transformed<T>where
T: Unpin,
impl<T> UnwindSafe for Transformed<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> AlignerFor<1> for T
impl<T> AlignerFor<1> for T
Source§impl<T> AlignerFor<1024> for T
impl<T> AlignerFor<1024> for T
Source§type Aligner = AlignTo1024<T>
type Aligner = AlignTo1024<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<128> for T
impl<T> AlignerFor<128> for T
Source§type Aligner = AlignTo128<T>
type Aligner = AlignTo128<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<16> for T
impl<T> AlignerFor<16> for T
Source§impl<T> AlignerFor<16384> for T
impl<T> AlignerFor<16384> for T
Source§type Aligner = AlignTo16384<T>
type Aligner = AlignTo16384<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<2> for T
impl<T> AlignerFor<2> for T
Source§impl<T> AlignerFor<2048> for T
impl<T> AlignerFor<2048> for T
Source§type Aligner = AlignTo2048<T>
type Aligner = AlignTo2048<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<256> for T
impl<T> AlignerFor<256> for T
Source§type Aligner = AlignTo256<T>
type Aligner = AlignTo256<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<32> for T
impl<T> AlignerFor<32> for T
Source§impl<T> AlignerFor<32768> for T
impl<T> AlignerFor<32768> for T
Source§type Aligner = AlignTo32768<T>
type Aligner = AlignTo32768<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<4> for T
impl<T> AlignerFor<4> for T
Source§impl<T> AlignerFor<4096> for T
impl<T> AlignerFor<4096> for T
Source§type Aligner = AlignTo4096<T>
type Aligner = AlignTo4096<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<512> for T
impl<T> AlignerFor<512> for T
Source§type Aligner = AlignTo512<T>
type Aligner = AlignTo512<T>
AlignTo* type which aligns Self to ALIGNMENT.Source§impl<T> AlignerFor<64> for T
impl<T> AlignerFor<64> for T
Source§impl<T> AlignerFor<8> for T
impl<T> AlignerFor<8> for T
Source§impl<T> AlignerFor<8192> for T
impl<T> AlignerFor<8192> for T
Source§type Aligner = AlignTo8192<T>
type Aligner = AlignTo8192<T>
AlignTo* type which aligns Self to ALIGNMENT.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
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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 moreSource§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<S> ROExtAcc for S
impl<S> ROExtAcc for S
Source§fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
fn f_get<F>(&self, offset: FieldOffset<S, F, Aligned>) -> &F
offset. Read moreSource§fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
fn f_get_mut<F>(&mut self, offset: FieldOffset<S, F, Aligned>) -> &mut F
offset. Read moreSource§fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
fn f_get_ptr<F, A>(&self, offset: FieldOffset<S, F, A>) -> *const F
offset. Read moreSource§fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
fn f_get_mut_ptr<F, A>(&mut self, offset: FieldOffset<S, F, A>) -> *mut F
offset. Read moreSource§impl<S> ROExtOps<Aligned> for S
impl<S> ROExtOps<Aligned> for S
Source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Aligned>, value: F) -> F
offset) with value,
returning the previous value of the field. Read moreSource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Aligned>) -> Fwhere
F: Copy,
Source§impl<S> ROExtOps<Unaligned> for S
impl<S> ROExtOps<Unaligned> for S
Source§fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
fn f_replace<F>(&mut self, offset: FieldOffset<S, F, Unaligned>, value: F) -> F
offset) with value,
returning the previous value of the field. Read moreSource§fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
fn f_get_copy<F>(&self, offset: FieldOffset<S, F, Unaligned>) -> Fwhere
F: Copy,
Source§impl<T> SelfOps for Twhere
T: ?Sized,
impl<T> SelfOps for Twhere
T: ?Sized,
Source§fn piped<F, U>(self, f: F) -> U
fn piped<F, U>(self, f: F) -> U
Source§fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
fn piped_ref<'a, F, U>(&'a self, f: F) -> Uwhere
F: FnOnce(&'a Self) -> U,
piped except that the function takes &Self
Useful for functions that take &Self instead of Self. Read moreSource§fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
fn piped_mut<'a, F, U>(&'a mut self, f: F) -> Uwhere
F: FnOnce(&'a mut Self) -> U,
piped, except that the function takes &mut Self.
Useful for functions that take &mut Self instead of Self.Source§fn mutated<F>(self, f: F) -> Self
fn mutated<F>(self, f: F) -> Self
Source§fn observe<F>(self, f: F) -> Self
fn observe<F>(self, f: F) -> Self
Source§fn as_ref_<T>(&self) -> &T
fn as_ref_<T>(&self) -> &T
AsRef,
using the turbofish .as_ref_::<_>() syntax. Read more