## Coverage Report

#### Created: 2025-11-22 06:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)

    /Users/andrewlamb/Software/datafusion/datafusion/expr-common/src/dyn_eq.rs

    Line
    Count
    Source
    1
    // Licensed to the Apache Software Foundation (ASF) under one
    2
    // or more contributor license agreements.  See the NOTICE file
    3
    // distributed with this work for additional information
    4
    // regarding copyright ownership.  The ASF licenses this file
    5
    // to you under the Apache License, Version 2.0 (the
    6
    // "License"); you may not use this file except in compliance
    7
    // with the License.  You may obtain a copy of the License at
    8
    //
    9
    //   http://www.apache.org/licenses/LICENSE-2.0
    10
    //
    11
    // Unless required by applicable law or agreed to in writing,
    12
    // software distributed under the License is distributed on an
    13
    // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    14
    // KIND, either express or implied.  See the License for the
    15
    // specific language governing permissions and limitations
    16
    // under the License.
    17
    18
    use std::any::Any;
    19
    use std::hash::{Hash, Hasher};
    20
    21
    /// A dyn-compatible version of [`Eq`] trait.
    22
    /// The implementation constraints for this trait are the same as for [`Eq`]:
    23
    /// the implementation must be reflexive, symmetric, and transitive.
    24
    /// Additionally, if two values can be compared with [`DynEq`] and [`PartialEq`] then
    25
    /// they must be [`DynEq`]-equal if and only if they are [`PartialEq`]-equal.
    26
    /// It is therefore strongly discouraged to implement this trait for types
    27
    /// that implement `PartialEq<Other>` or `Eq<Other>` for any type `Other` other than `Self`.
    28
    ///
    29
    /// Note: This trait should not be implemented directly. Implement `Eq` and `Any` and use
    30
    /// the blanket implementation.
    31
    #[allow(private_bounds)]
    32
    pub trait DynEq: private::EqSealed {
    33
        fn dyn_eq(&self, other: &dyn Any) -> bool;
    34
    }
    35
    36
    impl<T: Eq + Any> private::EqSealed for T {}
    37
    impl<T: Eq + Any> DynEq for T {
    38
    3
        fn dyn_eq(&self, other: &dyn Any) -> bool {
    39
    3
            other.downcast_ref::<Self>() == Some(self)
    40
    3
        }
    41
    }
    42
    43
    /// A dyn-compatible version of [`Hash`] trait.
    44
    /// If two values are equal according to [`DynEq`], they must produce the same hash value.
    45
    ///
    46
    /// Note: This trait should not be implemented directly. Implement `Hash` and `Any` and use
    47
    /// the blanket implementation.
    48
    #[allow(private_bounds)]
    49
    pub trait DynHash: private::HashSealed {
    50
        fn dyn_hash(&self, _state: &mut dyn Hasher);
    51
    }
    52
    53
    impl<T: Hash + Any> private::HashSealed for T {}
    54
    impl<T: Hash + Any> DynHash for T {
    55
    3
        fn dyn_hash(&self, mut state: &mut dyn Hasher) {
    56
    3
            self.type_id().hash(&mut state);
    57
    3
            self.hash(&mut state)
    58
    3
        }
    59
    }
    60
    61
    mod private {
    62
        pub(super) trait EqSealed {}
    63
        pub(super) trait HashSealed {}
    64
    }