Skip to main content

apache_datasketches/theta/
input.rs

1use super::{CompactThetaSketch, ThetaSketch, WrappedCompactThetaSketch};
2use apache_datasketches_sys::theta_input::ThetaInputRef;
3
4mod sealed {
5    pub trait Sealed {}
6    impl Sealed for super::ThetaSketch {}
7    impl Sealed for super::CompactThetaSketch {}
8    impl<'a> Sealed for super::WrappedCompactThetaSketch<'a> {}
9}
10
11/// Any of the three theta sketch types can be fed into a `ThetaUnion`,
12/// `ThetaIntersection`, `ThetaAnotB`, or `jaccard_similarity`. This trait
13/// is sealed — it cannot be implemented outside this crate — since the
14/// set-op shims only have concrete overloads for these three exact types.
15pub trait ThetaInput: sealed::Sealed {
16    #[doc(hidden)]
17    fn as_theta_input(&self) -> ThetaInputRef<'_>;
18}
19
20impl ThetaInput for ThetaSketch {
21    fn as_theta_input(&self) -> ThetaInputRef<'_> {
22        ThetaInputRef::Sketch(&self.inner)
23    }
24}
25
26impl ThetaInput for CompactThetaSketch {
27    fn as_theta_input(&self) -> ThetaInputRef<'_> {
28        ThetaInputRef::Compact(&self.inner)
29    }
30}
31
32impl<'a> ThetaInput for WrappedCompactThetaSketch<'a> {
33    fn as_theta_input(&self) -> ThetaInputRef<'_> {
34        ThetaInputRef::Wrapped(&self.inner)
35    }
36}