openweathermap
This is a crate which lets you easily access current weather data from OpenWeatherMap.
How to use
First add this crate to your dependencies in you Cargo.toml
file:
[]
= "0.0.2"
Then use the crate in your rust source file by calling openweathermap::init()
which returns a receiver object which you can then use to call openweathermap::update()
to get weather updates like in the following example:
extern crate openweathermap;
openweathermap::init()
will spawn a thread which asks OpenWeatherMap for the current weather every 10 minutes.
Whenever there is an update you get will get it from openweathermap::update()
.
Within the 10 minutes waiting time you will get None
which tells you that there is no new update available (see the outer match
statement in the above example.
You may get an Err
object if an error has occurred.
Initially while waiting for the first update you will get an Err
that includes the String "loading..." but also http or json errors may occur.
For example if you use an invalid API key you will get 401 Unauthorized
.