Crate darksky [−] [src]
An unofficial Rust wrapper for the DarkSky API.
While this documentation tries to stay as up-to-date as possible, refer to the official documentation for the latest, sanctioned information.
See the developer portal to sign up and obtain your token.
DarkSky has a status page here if you need to check its uptime.
Note: This package was previously named forecast_io
. Due to a
change in name, this package has been renamed to darksky
, and can be
found on crates.io by the same name.
Installation
Add the following dependency to your Cargo.toml
:
darksky = "0.6"
And include it in your project:
extern crate darksky;
Examples
Retrieve a forecast for the given latitude and longitude,
using a hyper client with a hyper_native_tls
connector:
extern crate darksky; extern crate hyper; extern crate hyper_native_tls; use darksky::{DarkskyRequester, Block}; use hyper::net::HttpsConnector; use hyper::Client; use hyper_native_tls::NativeTlsClient; use std::env; let tc = NativeTlsClient::new()?; let connector = HttpsConnector::new(tc); let client = Client::with_connector(connector); let token = env::var("FORECAST_TOKEN")?; let lat = 37.8267; let long = -122.423; match client.get_forecast(&token, lat, long) { Ok(forecast) => println!("{:?}", forecast), Err(why) => println!("Error getting forecast: {:?}", why), }
Features
hyper: Enables an implementation of DarkskyRequester
on hyper's
Client
(enabled by default).
Structs
Alert |
A textual, expiring severe weather warning issued for a location. There may
be multiple alerts per |
Datablock |
A block of data within a |
Datapoint |
A datapoint within a |
Flags |
A set of flags for a forecast, such as the |
Forecast |
A full forecast returned from the |
Options |
Build a list of options to send in the request, including the type of units that the API should return, the blocks to exclude, whether to extend the hourly forecast, and the language for the summary. |
Enums
Block |
A block is a name of a |
Error |
Common result type for the library's |
Icon |
A safe representation of the indicated weather. This is useful for matching and presenting an emoji or other weather symbol or representation. |
Language |
The language to return from the API for the |
PrecipitationType |
The type of precipitation that is happening within a |
Unit |
The type of units that the API should send back. |
Statics
API_URL |
Traits
DarkskyRequester |
The trait for implementations to different DarkSky routes. |
Type Definitions
Result |
A generic result type for all public-facing functions within the library. |