Geo
pub struct Geo { /* private fields */ }The geographic data associated with a particular IP address.
Methods
area_code
View sourcefn area_code(&self) -> u16The telephone area code associated with an IP address.
These are only available for IP addresses in the United States, its territories, and Canada.
Parameters
- self: &Self
Returns
as_name
View sourcefn as_name(&self) -> &strThe name of the organization associated with as_number.
For example, fastly is the value given for IP addresses under AS-54113.
Parameters
- self: &Self
Returns
as_number
View sourcefn as_number(&self) -> u32Autonomous system (AS) number.
Parameters
- self: &Self
Returns
country_code
View sourcefn country_code(&self) -> &strA two-character ISO 3166-1 country code for the country associated with an IP address.
The US country code is returned for IP addresses associated with overseas United States military bases.
These values include subdivisions that are assigned their own country codes in ISO 3166-1. For example, subdivisions NO-21 and NO-22 are presented with the country code SJ for Svalbard and the Jan Mayen Islands.
Parameters
- self: &Self
Returns
country_code3
View sourcefn country_code3(&self) -> &strA three-character ISO 3166-1 alpha-3 country code for the country associated with the IP address.
The USA country code is returned for IP addresses associated with overseas United States military bases.
Parameters
- self: &Self
Returns
country_name
View sourcefn country_name(&self) -> &strCountry name.
This field is the ISO 3166-1 English short name for a country.
Parameters
- self: &Self
Returns
latitude
View sourcefn latitude(&self) -> f64Latitude, in units of degrees from the equator.
Values range from -90.0 to +90.0 inclusive, and are based on the WGS 84 coordinate reference system.
Parameters
- self: &Self
Returns
longitude
View sourcefn longitude(&self) -> f64Longitude, in units of degrees from the IERS Reference Meridian.
Values range from -180.0 to +180.0 inclusive, and are based on the WGS 84 coordinate reference system.
Parameters
- self: &Self
Returns
metro_code
View sourcefn metro_code(&self) -> i64Metro code, representing designated market areas (DMAs) in the United States.
Parameters
- self: &Self
Returns
postal_code
View sourcefn postal_code(&self) -> &strThe postal code associated with the IP address.
These are available for some IP addresses in Australia, Canada, France, Germany, Italy, Spain, Switzerland, the United Kingdom, and the United States.
For Canadian postal codes, this is the first 3 characters. For the United Kingdom, this is the first 2-4 characters (outward code). For countries with alphanumeric postal codes, this field is a lowercase transliteration.
Parameters
- self: &Self
Returns
proxy_description
View sourcefn proxy_description(&self) -> ProxyDescriptionClient proxy description.
Parameters
- self: &Self
Returns
proxy_type
View sourcefn proxy_type(&self) -> ProxyTypeClient proxy type.
Parameters
- self: &Self
Returns
region
View sourceISO 3166-2 country subdivision code.
For countries with multiple levels of subdivision (for example, nations within the United Kingdom), this variable gives the more specific subdivision.
This field can be None for countries that do not have ISO country subdivision codes. For
example, None is given for IP addresses assigned to the Åland Islands (country code AX,
illustrated below).
Examples
Region values are the subdivision part only. For typical use, a subdivision is normally formatted with its associated country code. The following example illustrates constructing an ISO 3166-2 two-part country and subdivision code from the respective fields:
let code = if let Some(region) = geo.region() { format!("{}-{}", geo.country_code(), region)} else { format!("{}", geo.country_code())}; code | Region Name | Country | ISO 3166-2 subdivision |
|---|---|---|---|
AX | Ödkarby | Åland Islands | (none) |
DE-BE | Berlin | Germany | Land (State) |
GB-BNH | Brighton and Hove | United Kingdom | Unitary authority |
JP-13 | 東京都 (Tōkyō-to) | Japan | Prefecture |
RU-MOW | Москва́ (Moscow) | Russian Federation | Federal city |
SE-AB | Stockholms län | Sweden | Län (County) |
US-CA | California | United States | State |
Parameters
- self: &Self
Returns
utc_offset
View sourceTime zone offset from coordinated universal time (UTC) for city.
This is represented using the UtcOffset type from the time library. See
time's documentation for more details on how to format this type or use it in time
calculations.
Returns None if the geolocation database does not have a time zone offset for this IP
address.
Parameters
- self: &Self
Returns