@@ -19,6 +19,20 @@ pub enum Node<'a, D: Distance> {
1919 SplitPlaneNormal ( SplitPlaneNormal < ' a , D > ) ,
2020}
2121
22+ impl < ' a , D : Distance > Node < ' a , D > {
23+ pub fn into_owned ( self ) -> Node < ' static , D > {
24+ match self {
25+ Node :: Leaf ( leaf) => Node :: Leaf ( leaf. into_owned ( ) ) ,
26+ Node :: Descendants ( descendants) => Node :: Descendants ( Descendants {
27+ descendants : Cow :: Owned ( descendants. descendants . into_owned ( ) ) ,
28+ } ) ,
29+ Node :: SplitPlaneNormal ( split_plane_normal) => {
30+ Node :: SplitPlaneNormal ( split_plane_normal. into_owned ( ) )
31+ }
32+ }
33+ }
34+ }
35+
2236/// A node generic over the version of the database.
2337/// Should only be used while reading from the database.
2438#[ derive( Clone , Debug ) ]
@@ -40,8 +54,15 @@ impl<'a, D: Distance> Node<'a, D> {
4054 None
4155 }
4256 }
43- }
4457
58+ pub fn descendants ( self ) -> Option < Descendants < ' a > > {
59+ if let Node :: Descendants ( descendants) = self {
60+ Some ( descendants)
61+ } else {
62+ None
63+ }
64+ }
65+ }
4566/// A leaf node which corresponds to the vector inputed
4667/// by the user and the distance header.
4768pub struct Leaf < ' a , D : Distance > {
@@ -142,6 +163,19 @@ impl<D: Distance> fmt::Debug for SplitPlaneNormal<'_, D> {
142163 }
143164}
144165
166+ impl < D : Distance > SplitPlaneNormal < ' _ , D > {
167+ pub fn into_owned ( self ) -> SplitPlaneNormal < ' static , D > {
168+ SplitPlaneNormal {
169+ left : self . left ,
170+ right : self . right ,
171+ normal : self . normal . map ( |normal| Leaf {
172+ header : normal. header ,
173+ vector : Cow :: Owned ( normal. vector . into_owned ( ) ) ,
174+ } ) ,
175+ }
176+ }
177+ }
178+
145179impl < D : Distance > Clone for SplitPlaneNormal < ' _ , D > {
146180 fn clone ( & self ) -> Self {
147181 Self { left : self . left , right : self . right , normal : self . normal . clone ( ) }
0 commit comments