fn get_comparable_any()

in gazebo/src/cmp.rs [373:401]


        fn get_comparable_any(this: &Self) -> PartialEqAny {
            /// this provides an allocation free "view" over the vector that provides the equals
            /// functionality
            #[repr(transparent)]
            struct View<T>(Vec<T>);

            impl<T> PartialEq for View<T>
            where
                T: MaybeEq,
            {
                fn eq(&self, other: &Self) -> bool {
                    if self.0.len() != other.0.len() {
                        return false;
                    }

                    let this = self.0.iter().map(MaybeEq::get_comparable_any);
                    let other = other.0.iter().map(MaybeEq::get_comparable_any);

                    this.eq(other)
                }
            }

            PartialEqAny::new(unsafe {
                // we do a ref cast from the vector into the view
                // Ideally, we would use the ref_cast crate, but we do this ourselves to avoid
                // taking on an extra dependency.
                &*(this as *const Vec<T> as *const View<T>)
            })
        }