generic_octree/
node.rs

1#[cfg(feature = "serialize")]
2extern crate serde;
3
4#[cfg(feature = "serialize")]
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug)]
8#[cfg_attr(feature = "serialize", derive(Serialize, Deserialize))]
9pub struct OctreeNode<D> {
10    pub data: D,
11}
12
13impl<D> OctreeNode<D> {
14    /// Create a new Node from it's Data and a LocCode.
15    pub(crate) fn new(data: D) -> Self {
16        Self { data }
17    }
18
19    pub(crate) fn transform<U>(self) -> OctreeNode<U>
20    where
21        U: From<D>,
22    {
23        OctreeNode {
24            data: U::from(self.data),
25        }
26    }
27
28    pub(crate) fn transform_fn<U, F>(self, function: F) -> OctreeNode<U>
29    where
30        F: Fn(D) -> U,
31    {
32        OctreeNode {
33            data: function(self.data),
34        }
35    }
36}