Skip to main content

Crate wayle_weather

Crate wayle_weather 

Source
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

MethodEffect
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

ProviderAPI Key
OpenMeteoNo
VisualCrossingYes
WeatherApiYes

§Reactive Properties

The weather field is a Property<Option<Arc<Weather>>>:

  • .get() - Current value snapshot
  • .watch() - Stream yielding on changes

§Service Fields

FieldTypeDescription
weatherOption<Arc<Weather>>Latest weather data, None until first fetch

§Runtime Updates

All settings can change after creation:

§Weather Data

The Weather struct contains:

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§

WeatherService
Weather service for fetching and caching weather data.
WeatherServiceBuilder
Builder for configuring a WeatherService.

Enums§

WeatherErrorKind
Categorized error for UI display without implementation details.
WeatherStatus
Fetch lifecycle state exposed to UI consumers.