### Using AsnInfo Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.AsnInfo.html Demonstrates cloning an AsnInfo instance returned from a lookup. ```rust let ip: IpAddr = "1.0.0.1".parse().unwrap(); let owned_info = map.lookup_owned(ip).unwrap(); // You can clone it, hash it, sort it, etc. let cloned_info = owned_info.clone(); assert_eq!(owned_info, cloned_info); ``` -------------------------------- ### Builder::new Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.Builder.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new instance of the Builder with default settings. ```APIDOC ## pub fn new() -> Self ### Description Creates a new builder with default settings. ``` -------------------------------- ### Builder::new Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.Builder.html?search=u32+-%3E+bool Creates a new instance of the Builder with default settings. ```APIDOC ### pub fn new() -> Self Creates a new builder with default settings. ``` -------------------------------- ### Initialize and query an IpAsnMap Source: https://docs.rs/ip2asn/0.1.2/ip2asn/index.html Demonstrates building an IpAsnMap from a TSV data source and performing an IP lookup. Requires the ip-network crate for network type handling. ```rust use ip2asn::{Builder, IpAsnMap}; use ip_network::IpNetwork; use std::net::IpAddr; fn main() -> Result<(), ip2asn::Error> { // A small, in-memory TSV data source for the example. let data = "31.13.64.0\t31.13.127.255\t32934\tUS\tFACEBOOK-AS"; // Build the map from a source that implements `io::Read`. let map = Builder::new() .with_source(data.as_bytes())? .build()?; // Perform a lookup. let ip: IpAddr = "31.13.100.100".parse().unwrap(); if let Some(info) = map.lookup(ip) { assert_eq!(info.network, "31.13.64.0/18".parse::().unwrap()); assert_eq!(info.asn, 32934); assert_eq!(info.country_code, "US"); assert_eq!(info.organization, "FACEBOOK-AS"); println!( "{} -> AS{} {} ({}) in {}", ip, info.asn, info.organization, info.country_code, info.network ); } Ok(()) } ``` -------------------------------- ### Create a new IpAsnMap Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.IpAsnMap.html?search= Initialize an empty map using the new constructor. ```rust use ip2asn::IpAsnMap; let map = IpAsnMap::new(); assert!(map.lookup("1.1.1.1".parse().unwrap()).is_none()); ``` -------------------------------- ### IpAsnMap::new Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.IpAsnMap.html?search= Creates a new, empty IpAsnMap instance. ```APIDOC ## pub fn new() -> Self ### Description Creates a new, empty `IpAsnMap`. This is a convenience method equivalent to `IpAsnMap::default()`. ``` -------------------------------- ### IpAsnMap::new Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.IpAsnMap.html Creates a new, empty IpAsnMap instance. ```APIDOC ## pub fn new() -> Self ### Description Creates a new, empty `IpAsnMap` instance. This is a convenience method equivalent to `IpAsnMap::default()`. ``` -------------------------------- ### Builder::with_source Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.Builder.html?search=u32+-%3E+bool Configures the builder to load data from a source implementing BufRead. ```APIDOC ### pub fn with_source(self, source: impl BufRead + Send + 'a) -> Result Configures the builder to load data from a source implementing `BufRead`. This accepts any reader, such as an in-memory buffer or a network stream, and handles Gzip decompression automatically. ``` -------------------------------- ### Builder::with_source Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.Builder.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Configures the builder to load data from a source implementing BufRead. ```APIDOC ## pub fn with_source(self, source: impl BufRead + Send + 'a) -> Result ### Description Configures the builder to load data from a source implementing `BufRead`. This accepts any reader, such as an in-memory buffer or a network stream, and handles Gzip decompression automatically. ``` -------------------------------- ### Builder::from_path Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.Builder.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Configures the builder to load data from a specified file path, with automatic Gzip decompression. ```APIDOC ## pub fn from_path>(self, path: P) -> Result ### Description Configures the builder to load data from a file path. Gzip decompression is handled automatically by inspecting the file’s magic bytes. ``` -------------------------------- ### Builder::from_path Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.Builder.html?search=u32+-%3E+bool Configures the builder to load data from a specified file path, with automatic Gzip decompression. ```APIDOC ### pub fn from_path>(self, path: P) -> Result Configures the builder to load data from a file path. Gzip decompression is handled automatically by inspecting the file’s magic bytes. ``` -------------------------------- ### Builder::build Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.Builder.html?search=u32+-%3E+bool Builds the IpAsnMap and consumes the builder. ```APIDOC ### pub fn build(self) -> Result Builds the `IpAsnMap`, consuming the builder. This method reads from the source, parses each line, interns strings, converts IP ranges to CIDRs, and inserts them into the final lookup table. ``` -------------------------------- ### Builder::build Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.Builder.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Consumes the builder and constructs the IpAsnMap. ```APIDOC ## pub fn build(self) -> Result ### Description Builds the `IpAsnMap`, consuming the builder. This method reads from the source, parses each line, interns strings, converts IP ranges to CIDRs, and inserts them into the final lookup table. ``` -------------------------------- ### Builder Methods Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.Builder.html?search= Methods available for configuring and building an IpAsnMap. ```APIDOC ## Builder::new() Creates a new builder with default settings. ## Builder::from_path>(path: P) -> Result Configures the builder to load data from a file path. Gzip decompression is handled automatically. ## Builder::with_source(source: impl BufRead + Send + 'a) -> Result Configures the builder to load data from a source implementing BufRead. Gzip decompression is handled automatically. ## Builder::strict() Enables strict parsing mode. If called, build() will return an Err on the first parse failure. ## Builder::on_warning(callback: F) -> Self Sets a callback function to be invoked for each skipped line in resilient mode. ## Builder::build() -> Result Builds the IpAsnMap, consuming the builder. This method reads from the source, parses lines, and constructs the lookup table. ``` -------------------------------- ### Builder Source: https://docs.rs/ip2asn/0.1.2/ip2asn/index.html Configures and constructs an IpAsnMap instance from a data source. ```APIDOC ## Builder ### Description A builder pattern implementation used to configure and load data into an IpAsnMap. It supports reading from various sources implementing io::Read. ### Methods - **new()** - Creates a new Builder instance. - **with_source(source: R)** - Configures the data source for the builder. - **build()** - Constructs the IpAsnMap from the configured source. ``` -------------------------------- ### Displaying AsnInfo Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.AsnInfo.html Converts an AsnInfo instance to a string representation using the Display trait. ```rust let ip: IpAddr = "1.0.0.1".parse().unwrap(); let info = map.lookup_owned(ip).unwrap(); let display_str = info.to_string(); assert_eq!(display_str, "AS13335 CLOUDFLARENET (AU) in 1.0.0.0/24"); ``` -------------------------------- ### Builder::strict Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.Builder.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Enables strict parsing mode for the builder. ```APIDOC ## pub fn strict(self) -> Self ### Description Enables strict parsing mode. If called, `build()` will return an `Err` on the first parse failure. ``` -------------------------------- ### Builder::strict Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.Builder.html?search=u32+-%3E+bool Enables strict parsing mode for the builder. ```APIDOC ### pub fn strict(self) -> Self Enables strict parsing mode. If called, `build()` will return an `Err` on the first parse failure. ``` -------------------------------- ### Builder::on_warning Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.Builder.html?search=u32+-%3E+bool Sets a callback function to be invoked for each skipped line in resilient mode. ```APIDOC ### pub fn on_warning(self, callback: F) -> Self where F: Fn(Warning) + Send + 'a Sets a callback function to be invoked for each skipped line in resilient mode. ``` -------------------------------- ### Builder::on_warning Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.Builder.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Sets a callback function to be invoked for each skipped line in resilient mode. ```APIDOC ## pub fn on_warning(self, callback: F) -> Self where F: Fn(Warning) + Send + 'a ### Description Sets a callback function to be invoked for each skipped line in resilient mode. ``` -------------------------------- ### Define AsnInfoView struct Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.AsnInfoView.html The structure definition for AsnInfoView, marked as non-exhaustive to allow for future field additions. ```rust #[non_exhaustive] pub struct AsnInfoView<'a> { pub network: IpNetwork, pub asn: u32, pub country_code: &'a str, pub organization: &'a str, } ``` -------------------------------- ### IpAsnMap::builder Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.IpAsnMap.html?search= Creates a new Builder for constructing an IpAsnMap. ```APIDOC ## pub fn builder() -> Builder<'static> ### Description Creates a new `Builder` for constructing an `IpAsnMap`. This is a convenience method equivalent to `Builder::new()`. ``` -------------------------------- ### AsnInfo Struct Definition Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.AsnInfo.html The definition of the AsnInfo struct, which is marked as non-exhaustive. ```rust #[non_exhaustive] pub struct AsnInfo { pub network: IpNetwork, pub asn: u32, pub country_code: String, pub organization: String, } ``` -------------------------------- ### IpAsnMap::lookup_owned Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.IpAsnMap.html Looks up an IP address and returns an owned AsnInfo struct. ```APIDOC ## pub fn lookup_owned(&self, ip: IpAddr) -> Option ### Description Looks up an IP address, returning an owned `AsnInfo` struct if found. This method is useful in async contexts or when the result needs to be stored or sent across threads. ``` -------------------------------- ### pub fn parse_line(line: &str) -> Result, ParseErrorKind> Source: https://docs.rs/ip2asn/0.1.2/ip2asn/parser/fn.parse_line.html Parses a single line of tab-separated ip2asn data. The expected format is: START_IP\tEND_IP\tASN\tCOUNTRY_CODE\tORGANIZATION. ```APIDOC ## Function: parse_line ### Description Parses a single line of tab-separated ip2asn data. The expected format is: START_IP\tEND_IP\tASN\tCOUNTRY_CODE\tORGANIZATION. ### Signature `pub fn parse_line(line: &str) -> Result, ParseErrorKind>` ### Parameters - **line** (&str) - The tab-separated string containing ip2asn data. ### Returns - **Result, ParseErrorKind>** - Returns a `ParsedLine` struct on success, or a `ParseErrorKind` if the line is malformed (e.g., incorrect number of columns, invalid IP addresses, or invalid range). ``` -------------------------------- ### pub fn parse_line(line: &str) -> Result, ParseErrorKind> Source: https://docs.rs/ip2asn/0.1.2/ip2asn/parser/fn.parse_line.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Parses a single line of tab-separated ip2asn data. The expected format is: START_IP\tEND_IP\tASN\tCOUNTRY_CODE\tORGANIZATION. ```APIDOC ## Function: parse_line ### Description Parses a single line of tab-separated `ip2asn` data. The expected format is: `START_IP\tEND_IP\tASN\tCOUNTRY_CODE\tORGANIZATION`. ### Signature `pub fn parse_line(line: &str) -> Result, ParseErrorKind>` ### Parameters - **line** (&str) - The tab-separated string to parse. ### Returns - **Result, ParseErrorKind>** - Returns a `ParsedLine` on success, or a `ParseErrorKind` if the line is malformed (e.g., incorrect number of columns, invalid IP addresses, or invalid range). ``` -------------------------------- ### range_to_cidrs Source: https://docs.rs/ip2asn/0.1.2/ip2asn/range/index.html Converts an inclusive IP address range into the smallest possible set of CIDR network blocks. ```APIDOC ## range_to_cidrs ### Description Converts an inclusive IP address range into the smallest possible set of CIDR network blocks. ### Signature `pub fn range_to_cidrs(start: IpAddr, end: IpAddr) -> Vec` ``` -------------------------------- ### range_to_cidrs Source: https://docs.rs/ip2asn/0.1.2/ip2asn/range/index.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Converts an inclusive IP address range into the smallest possible set of CIDR network blocks. ```APIDOC ## Function: range_to_cidrs ### Description Converts an inclusive IP address range into the smallest possible set of CIDR network blocks. ### Signature `range_to_cidrs(start: IpAddr, end: IpAddr) -> Vec` ``` -------------------------------- ### range_to_cidrs Source: https://docs.rs/ip2asn/0.1.2/ip2asn/range/index.html?search= Converts an inclusive IP address range into the smallest possible set of CIDR network blocks. ```APIDOC ## Function: range_to_cidrs ### Description Converts an inclusive IP address range into the smallest possible set of CIDR network blocks. ### Signature `pub fn range_to_cidrs(start: IpAddr, end: IpAddr) -> Vec` ``` -------------------------------- ### IpAsnMap::lookup_owned Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.IpAsnMap.html?search= Performs a lookup for an IP address and returns an owned AsnInfo struct. ```APIDOC ## pub fn lookup_owned(&self, ip: IpAddr) -> Option ### Description Looks up an IP address, returning an owned `AsnInfo` struct if found. This is useful in async contexts or when the result needs to be stored or sent across threads. ``` -------------------------------- ### IpAsnMap::lookup Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.IpAsnMap.html?search= Performs a longest-prefix match lookup for an IP address. ```APIDOC ## pub fn lookup(&self, ip: IpAddr) -> Option> ### Description Looks up an IP address, returning a view into its ASN information if found. The lookup is a longest-prefix match, ensuring the most specific network range is returned. ``` -------------------------------- ### Builder Struct Definition Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.Builder.html?search=u32+-%3E+bool The internal structure of the Builder, which manages the configuration state for building an IpAsnMap. ```rust pub struct Builder<'a> { /* private fields */ } ``` -------------------------------- ### Define IpAsnMap struct Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.IpAsnMap.html?search= The internal structure definition for IpAsnMap. ```rust pub struct IpAsnMap { /* private fields */ } ``` -------------------------------- ### Perform an owned lookup Source: https://docs.rs/ip2asn/0.1.2/ip2asn/struct.IpAsnMap.html?search= Retrieve an owned AsnInfo struct, suitable for use in async contexts or cross-thread communication. ```rust let ip: IpAddr = "1.0.0.1".parse().unwrap(); if let Some(info) = map.lookup_owned(ip) { // The `info` object is owned and can be stored or sent across threads. assert_eq!(info.asn, 13335); println!("Owned info: {}", info); } ``` -------------------------------- ### parse_line function signature Source: https://docs.rs/ip2asn/0.1.2/ip2asn/parser/fn.parse_line.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E The function signature for parsing tab-separated ip2asn data lines. ```rust pub fn parse_line(line: &str) -> Result, ParseErrorKind> ``` -------------------------------- ### IpAsnMap::lookup Source: https://docs.rs/ip2asn/0.1.2/ip2asn/index.html Performs a lookup for a given IP address to retrieve its associated ASN information. ```APIDOC ## fn lookup(&self, ip: IpAddr) -> Option ### Description Performs a sub-microsecond lookup for the provided IP address within the IpAsnMap. Returns an AsnInfoView containing the ASN details if the IP is found, otherwise returns None. ### Parameters - **ip** (IpAddr) - Required - The IP address to query. ### Response - **Option** - Returns an optional view containing the network, asn, country_code, and organization fields. ``` -------------------------------- ### parse_line Source: https://docs.rs/ip2asn/0.1.2/ip2asn/parser/fn.parse_line.html?search= Parses a single line of tab-separated ip2asn data. The expected format is: START_IP\tEND_IP\tASN\tCOUNTRY_CODE\tORGANIZATION. ```APIDOC ## Function: parse_line ### Description Parses a single line of tab-separated `ip2asn` data. The expected format is: `START_IP\tEND_IP\tASN\tCOUNTRY_CODE\tORGANIZATION`. ### Signature `pub fn parse_line(line: &str) -> Result, ParseErrorKind>` ### Parameters - **line** (&str) - The tab-separated string to parse. ### Returns - **Result, ParseErrorKind>** - Returns a `ParsedLine` on success, or a `ParseErrorKind` if the line is malformed (e.g., incorrect column count, invalid IP addresses, or invalid range). ``` -------------------------------- ### parse_line Source: https://docs.rs/ip2asn/0.1.2/ip2asn/parser/fn.parse_line.html?search=std%3A%3Avec Parses a single line of tab-separated ip2asn data. The expected format is: START_IP\tEND_IP\tASN\tCOUNTRY_CODE\tORGANIZATION. ```APIDOC ## Function: parse_line ### Signature `pub fn parse_line(line: &str) -> Result, ParseErrorKind>` ### Description Parses a single line of tab-separated `ip2asn` data. The expected format is: `START_IP\tEND_IP\tASN\tCOUNTRY_CODE\tORGANIZATION`. ### Parameters - **line** (&str) - The input string containing the tab-separated data. ### Returns - **Result, ParseErrorKind>** - Returns a `ParsedLine` struct on success, or a `ParseErrorKind` if the line is malformed (e.g., incorrect number of columns, invalid IP addresses, or invalid range). ``` -------------------------------- ### AsnRecord Struct Definition Source: https://docs.rs/ip2asn/0.1.2/ip2asn/types/struct.AsnRecord.html The definition of the AsnRecord struct, highlighting its memory-efficient fields. ```rust pub struct AsnRecord { pub asn: u32, pub country_code: [u8; 2], pub organization_idx: u32, } ``` -------------------------------- ### range_to_cidrs function signature Source: https://docs.rs/ip2asn/0.1.2/ip2asn/range/fn.range_to_cidrs.html?search=u32+-%3E+bool The function signature for converting an IP range into a vector of IpNetwork blocks. ```rust pub fn range_to_cidrs(start: IpAddr, end: IpAddr) -> Vec ``` -------------------------------- ### ParsedLine Struct Definition Source: https://docs.rs/ip2asn/0.1.2/ip2asn/parser/struct.ParsedLine.html?search= Defines the structure for holding parsed IP range information, including lifetime-bound organization strings. ```rust pub struct ParsedLine<'a> { pub start_ip: IpAddr, pub end_ip: IpAddr, pub asn: u32, pub country_code: [u8; 2], pub organization: &'a str, } ``` -------------------------------- ### parse_line Source: https://docs.rs/ip2asn/0.1.2/ip2asn/parser/index.html Parses a single line of tab-separated ip2asn data into a ParsedLine struct. ```APIDOC ## parse_line ### Description Parses a single line of tab-separated `ip2asn` data. ### Signature `pub fn parse_line(line: &str) -> Result` ### Parameters - **line** (&str) - The tab-separated string containing IP-to-ASN data to be parsed. ``` -------------------------------- ### Define Warning enum Source: https://docs.rs/ip2asn/0.1.2/ip2asn/enum.Warning.html The Warning enum structure used to capture details about skipped lines during parsing. ```rust #[non_exhaustive] pub enum Warning { Parse { line_number: usize, line_content: String, message: String, }, IpFamilyMismatch { line_number: usize, line_content: String, }, } ``` -------------------------------- ### Error Enum Definition Source: https://docs.rs/ip2asn/0.1.2/ip2asn/enum.Error.html?search= The primary error type for the crate, containing variants for I/O and parsing errors. Because it is non-exhaustive, matching against it requires a wildcard arm. ```rust #[non_exhaustive] pub enum Error { Io(Error), Parse { line_number: usize, line_content: String, kind: ParseErrorKind, }, } ``` -------------------------------- ### ParseErrorKind Enum Definition Source: https://docs.rs/ip2asn/0.1.2/ip2asn/enum.ParseErrorKind.html?search=u32+-%3E+bool The non-exhaustive enum representing various parsing error conditions. Requires a wildcard arm when matching due to its non-exhaustive nature. ```rust #[non_exhaustive] pub enum ParseErrorKind { IncorrectColumnCount { expected: usize, found: usize, }, InvalidIpAddress { field: String, value: String, }, InvalidAsnNumber { value: String, }, InvalidRange { start_ip: IpAddr, end_ip: IpAddr, }, IpFamilyMismatch, InvalidCountryCode { value: String, }, } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.