s2-kit 0.4.0

The S2 energy flexibility standard (EN 50491-12-2) in Rust: the S2 JSON data model, a semantic validator, sans-IO Resource Manager and Customer Energy Manager session engines, and S2 Connect
Documentation
//! The website's code blocks, as doctests.
//!
//! Generated by `cargo xtask gen-site-examples` from `site/content/**/*.md` — do
//! not edit. Every ```` ```rust ```` block on the website that is not marked
//! `ignore` appears here, so a guide cannot drift away from the API it teaches.
//! Fix the Markdown, then re-run the generator.
//!
//! The module is `cfg(doctest)`, so it costs a normal build nothing: rustdoc is
//! the only thing that ever compiles it. A block that needs a feature carries the
//! `#[cfg]` for it, so `cargo test --doc` runs whatever the enabled features can
//! actually compile and skips the rest.

// Each carrier is named after the file and block it came from, so a failure names
// the Markdown to fix. That is worth more here than the casing convention.
#![allow(non_camel_case_types)]

/// From [`site/content/_index.md`], block 0.
///
/// ```
/// use s2_kit::prelude::*;
///
/// let details = ResourceManagerDetails::builder()
///     .resource_id(Id::new_const("battery-1"))
///     .roles(vec![Role::new(RoleType::EnergyStorage, Commodity::Electricity)])
///     .instruction_processing_delay(Duration::from_millis(500))
///     .available_control_types(vec![ControlType::FillRateBasedControl])
///     .provides_forecast(false)
///     .provides_power_measurement_types(vec![CommodityQuantity::ElectricPower3PhaseSymmetric])
///     .build();
///
/// let mut rm = RmSession::new(RmConfig::default(), details);
/// rm.open(Timestamp::now());
///
/// // Everything the session wants to say is waiting here; a driver writes it to a socket.
/// let hello = rm.poll_transmit().expect("the Resource Manager speaks first");
/// assert_eq!(hello.kind, MessageKind::Handshake);
/// ```
#[allow(non_snake_case, dead_code)]
struct site_content__index_md_0;

/// From [`site/content/docs/getting-started.md`], block 0.
///
/// ```
/// use s2_kit::prelude::*;
///
/// let details = ResourceManagerDetails::builder()
///     .resource_id(Id::new_const("battery-1"))
///     .roles(vec![Role::new(RoleType::EnergyStorage, Commodity::Electricity)])
///     .instruction_processing_delay(Duration::from_millis(500))
///     .available_control_types(vec![ControlType::FillRateBasedControl])
///     .provides_forecast(false)
///     .provides_power_measurement_types(vec![CommodityQuantity::ElectricPower3PhaseSymmetric])
///     .build();
///
/// let mut rm = RmSession::new(RmConfig::default(), details);
/// rm.open(Timestamp::now());
///
/// let hello = rm.poll_transmit().expect("the Resource Manager speaks first");
/// assert_eq!(hello.kind, MessageKind::Handshake);
/// ```
#[allow(non_snake_case, dead_code)]
struct site_content_docs_getting_started_md_0;

/// From [`site/content/docs/getting-started.md`], block 1.
///
/// ```
/// use s2_kit::prelude::*;
/// use s2_kit::testing::Conversation;
///
/// let mut c = Conversation::battery();
/// c.open();
///
/// // Every message that crossed, except the acknowledgements, earned exactly one.
/// let sent = c.transcript().iter().filter(|e| e.kind != MessageKind::ReceptionStatus).count();
/// let acks = c.transcript().iter().filter(|e| e.kind == MessageKind::ReceptionStatus).count();
/// assert_eq!(sent, acks);
/// ```
#[cfg(feature = "testing")]
#[allow(non_snake_case, dead_code)]
struct site_content_docs_getting_started_md_1;

/// From [`site/content/docs/sessions.md`], block 0.
///
/// ```
/// use s2_kit::prelude::*;
/// use s2_kit::session::SessionSet;
///
/// let mut fleet: SessionSet<String, CemSession> = SessionSet::new();
/// fleet.insert("battery".into(), CemSession::new(CemConfig::default()));
/// fleet.insert("heatpump".into(), CemSession::new(CemConfig::default()));
/// fleet.open_all(Timestamp::now());
///
/// // One deadline for the whole fleet, and one sweep that serves every session due.
/// if let Some(deadline) = fleet.poll_timeout() {
///     fleet.handle_timeout(deadline);
/// }
/// // The key is cloned, so a drain can be acted on: write the frame to the socket you
/// // look up by that key, or close the session that just emitted it.
/// for (device, out) in fleet.drain_transmit() {
///     let _ = fleet.get_mut(&device);
///     let _ = out;
/// }
/// ```
#[allow(non_snake_case, dead_code)]
struct site_content_docs_sessions_md_0;