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 Forecast.

Datablock

A block of data within a Forecast, with potentially many Datapoints.

Datapoint

A datapoint within a Datablock, where there is usually multiple.

Flags

A set of flags for a forecast, such as the Units specified or the vector of DarkSky stations reporting.

Forecast

A full forecast returned from the get_forecast and get_forecast_with_options functions.

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 Datablock returned from the API. This can be used to exclude datablocks from being returned from the API, to reduce bandwidth.

Error

Common result type for the library's Result type. Includes errors for JSON decoding, Io errors, etc.

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 summary field.

PrecipitationType

The type of precipitation that is happening within a Datapoint.

Unit

The type of units that the API should send back. us is the default value, and does not need to be specified in that case.

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.