alpine-protocol-sdk 0.2.4

High-level SDK on top of the ALPINE protocol layer.
Documentation
use crate::error::{AlpineSdkError, SdkErrorContext};

fn describe_error(error: &AlpineSdkError) -> String {
    if let Some(hint) = error.user_hint() {
        hint.to_string()
    } else {
        error.to_string()
    }
}

pub fn format_preflight_summary(errors: &[SdkErrorContext]) -> String {
    if errors.is_empty() {
        return "Preflight checks passed.".to_string();
    }
    let mut sentences = Vec::new();
    for ctx in errors {
        let mut sentence = describe_error(&ctx.error);
        let mut meta = Vec::new();
        if let Some(device_id) = ctx.device_id.as_ref() {
            meta.push(format!("device_id {}", device_id));
        }
        if let Some(ip) = ctx.ip.as_ref() {
            meta.push(format!("ip {}", ip));
        }
        if let Some(port) = ctx.port {
            meta.push(format!("port {}", port));
        }
        if let Some(operation) = ctx.operation.as_ref() {
            meta.push(format!("op {}", operation));
        }
        if !meta.is_empty() {
            sentence.push_str(&format!(" ({})", meta.join(", ")));
        }
        sentences.push(sentence);
    }
    sentences.join(". ") + "."
}