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.8"

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 futures;
extern crate hyper;
extern crate hyper_tls;
extern crate tokio_core;

use darksky::DarkskyHyperRequester;
use futures::Future;
use hyper::client::{Client, HttpConnector};
use hyper_tls::HttpsConnector;
use std::env;
use tokio_core::reactor::Core;

let core = Core::new()?;
let handle = core.handle();

let client = Client::configure()
    .connector(HttpsConnector::new(4, &handle)?)
    .build(&handle);

let token = env::var("FORECAST_TOKEN")?;
let lat = 37.8267;
let long = -122.423;

// We're waiting in this example, but you shouldn't in your code.
match client.get_forecast(&token, lat, long).wait() {
    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).

Re-exports

pub use bridge::DarkskyHyperRequester;

Modules

bridge

Bridged support for various HTTP clients.

constants

A set of constants used by the library.

models

A set of models representing data received by the API.

utils

Utilities that provide some basic functionality that may be useful, but are generally non-essential for usage of the library.

Structs

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.

Language

The language to return from the API for the summary field.

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.

Type Definitions

Result

A generic result type for all public-facing functions within the library.