Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
ip2asn/ip2asn_lib/src/lib.rs /
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
37 lines (30 sloc)
780 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pub mod bgptools; | |
| pub use self::bgptools::BgpTools; | |
| use std::collections::BTreeMap; | |
| use std::path::Path; | |
| #[derive(Debug)] | |
| pub enum Error { | |
| File(std::io::Error), | |
| Json(serde_json::Error), | |
| } | |
| impl From<std::io::Error> for Error { | |
| fn from(other: std::io::Error) -> Self { | |
| Error::File(other) | |
| } | |
| } | |
| impl From<serde_json::Error> for Error { | |
| fn from(other: serde_json::Error) -> Self { | |
| Error::Json(other) | |
| } | |
| } | |
| pub struct AsnMap<T: std::cmp::Ord> { | |
| map: BTreeMap<T, u32>, | |
| } | |
| impl<T: std::cmp::Ord> AsnMap<T> { | |
| pub fn lookup(&self, key: impl Into<T>) -> Option<&u32> { | |
| self.map.range(..=key.into()).next_back().map(|(_, v)| v) | |
| } | |
| } | |
| pub trait AsnMapper { | |
| fn parse(path: &Path) -> Result<(AsnMap<u32>, AsnMap<u128>), Error>; | |
| } |