shared: add with_root method in CidrTree

pull/121/head
Jake McGinty 2021-06-23 16:11:37 +09:00
parent 0c8a2ee991
commit 3c8530d956
1 changed files with 5 additions and 1 deletions

View File

@ -217,7 +217,7 @@ impl Deref for Cidr {
} }
} }
#[derive(PartialEq, PartialOrd, Eq, Ord)] #[derive(Clone, PartialEq, PartialOrd, Eq, Ord)]
pub struct CidrTree<'a> { pub struct CidrTree<'a> {
cidrs: &'a [Cidr], cidrs: &'a [Cidr],
contents: &'a Cidr, contents: &'a Cidr,
@ -237,6 +237,10 @@ impl<'a> CidrTree<'a> {
.iter() .iter()
.min_by_key(|c| c.cidr.prefix()) .min_by_key(|c| c.cidr.prefix())
.expect("failed to find root CIDR"); .expect("failed to find root CIDR");
Self::with_root(cidrs, root)
}
pub fn with_root(cidrs: &'a [Cidr], root: &'a Cidr) -> Self {
Self { Self {
cidrs, cidrs,
contents: root, contents: root,