From 4c854dbccb1e96a78cf198a0ab165649d82563d7 Mon Sep 17 00:00:00 2001 From: Andreas Neuhaus Date: Sat, 21 Dec 2024 11:14:19 +0100 Subject: [PATCH] Support to write error messages directly to JSON --- firmware/src/error.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/firmware/src/error.rs b/firmware/src/error.rs index bbda73a..3fbbb88 100644 --- a/firmware/src/error.rs +++ b/firmware/src/error.rs @@ -1,7 +1,10 @@ +use crate::json::{self, ToJson}; use crate::user::UserId; use crate::{display, nfc, vereinsflieger}; +use alloc::string::ToString; use core::fmt; use core::future::Future; +use embedded_io_async::Write; /// Main error type #[derive(Debug)] @@ -126,3 +129,12 @@ impl fmt::Display for ErrorKind { } } } + +impl ToJson for ErrorKind { + async fn to_json( + &self, + json: &mut json::Writer, + ) -> Result<(), json::Error> { + json.write(self.to_string()).await + } +}