summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2024-02-02 17:31:08 +0200
committerLars Wirzenius <liw@liw.fi>2024-02-02 17:38:26 +0200
commitfbd1911e2fa6d97e8efa66afb14b162c00d59700 (patch)
tree8c5f403e2cb798d94a7343c123240d1973a55485
parent1321c25f296ccf6ef80c7eeb1136d9bbd786af86 (diff)
downloadradicle-ci-broker-fbd1911e2fa6d97e8efa66afb14b162c00d59700.tar.gz
feat(src/msg.rs): add a Response constructor from string slice
This will make it easier to process adapter output line by line. Signed-off-by: Lars Wirzenius <liw@liw.fi>
-rw-r--r--src/msg.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/msg.rs b/src/msg.rs
index 94c523d..071bc0a 100644
--- a/src/msg.rs
+++ b/src/msg.rs
@@ -522,6 +522,15 @@ impl Response {
Ok(Some(req))
}
}
+
+ /// Read a response from a string slice. This is meant for the
+ /// broker to use.
+ #[allow(clippy::should_implement_trait)]
+ pub fn from_str(line: &str) -> Result<Self, MessageError> {
+ let req: Self =
+ serde_json::from_slice(line.as_bytes()).map_err(MessageError::DeserializeResponse)?;
+ Ok(req)
+ }
}
/// All possible errors from the CI broker messages.