Expand description
Weather data service with multi-provider support.
§Quick Start
use wayle_weather::WeatherService;
let weather = WeatherService::builder().build();
if let Some(data) = weather.weather.get().as_ref() {
let temp = data.current.temperature.celsius();
let cond = &data.current.condition;
println!("{temp}°C, {cond:?}");
}§Watching for Changes
use wayle_weather::WeatherService;
use tokio_stream::StreamExt;
let mut stream = weather.weather.watch();
while let Some(data) = stream.next().await {
if let Some(w) = data.as_ref() {
println!("Updated: {}°C", w.current.temperature.celsius());
}
}§Configuration
| Method | Effect |
|---|---|
poll_interval(Duration) | How often to fetch fresh data |
provider(WeatherProviderKind) | Which weather API to use |
location(LocationQuery) | City or coordinates for forecasts |
units(TemperatureUnit) | Celsius or Fahrenheit display |
visual_crossing_key(key) | API key for Visual Crossing |
weatherapi_key(key) | API key for WeatherAPI.com |
use wayle_weather::{WeatherService, WeatherProviderKind, LocationQuery, TemperatureUnit};
use std::time::Duration;
let weather = WeatherService::builder()
.provider(WeatherProviderKind::OpenMeteo)
.location(LocationQuery::city("Tokyo"))
.units(TemperatureUnit::Metric)
.poll_interval(Duration::from_secs(15 * 60))
.build();§Providers
| Provider | API Key |
|---|---|
OpenMeteo | No |
VisualCrossing | Yes |
WeatherApi | Yes |
§Reactive Properties
The weather field is a Property<Option<Arc<Weather>>>:
.get()- Current value snapshot.watch()- Stream yielding on changes
§Service Fields
| Field | Type | Description |
|---|---|---|
weather | Option<Arc<Weather>> | Latest weather data, None until first fetch |
§Runtime Updates
All settings can change after creation:
set_poll_interval()- Polling frequencyset_location()- Weather locationset_units()- Temperature displayset_provider()- Weather source
§Weather Data
The Weather struct contains:
current- Real-time conditions (CurrentWeather)hourly- Next 24+ hours (HourlyForecast)daily- Next 7+ days (DailyForecast)location- Resolved coordinatesastronomy- Sunrise/sunset times
Re-exports§
pub use error::Error;pub use error::Result;pub use model::Astronomy;pub use model::CurrentWeather;pub use model::DailyForecast;pub use model::HourlyForecast;pub use model::Location;pub use model::LocationQuery;pub use model::TemperatureUnit;pub use model::Weather;pub use model::WeatherCondition;pub use model::WeatherProviderKind;pub use provider::ProviderConfig;pub use provider::WeatherProvider;pub use provider::create_provider;pub use types::Distance;pub use types::Percentage;pub use types::Precipitation;pub use types::Pressure;pub use types::Speed;pub use types::Temperature;pub use types::UvIndex;pub use types::WindDirection;
Modules§
- error
- Weather service error types and result aliases.
- model
- Weather data models including forecasts, conditions, and location.
- provider
- Weather data provider implementations and configuration.
- types
- Domain-specific measurement types for weather data.
Structs§
- Weather
Service - Weather service for fetching and caching weather data.
- Weather
Service Builder - Builder for configuring a
WeatherService.
Enums§
- Weather
Error Kind - Categorized error for UI display without implementation details.
- Weather
Status - Fetch lifecycle state exposed to UI consumers.