mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-09-12 04:32:58 +02:00
split up core/pdu
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
ee92a33a4d
commit
8742266ff0
7 changed files with 492 additions and 425 deletions
20
src/core/pdu/content.rs
Normal file
20
src/core/pdu/content.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
use serde::Deserialize;
|
||||
use serde_json::value::Value as JsonValue;
|
||||
|
||||
use crate::{err, implement, Result};
|
||||
|
||||
#[must_use]
|
||||
#[implement(super::PduEvent)]
|
||||
pub fn get_content_as_value(&self) -> JsonValue {
|
||||
self.get_content()
|
||||
.expect("pdu content must be a valid JSON value")
|
||||
}
|
||||
|
||||
#[implement(super::PduEvent)]
|
||||
pub fn get_content<T>(&self) -> Result<T>
|
||||
where
|
||||
T: for<'de> Deserialize<'de>,
|
||||
{
|
||||
serde_json::from_str(self.content.get())
|
||||
.map_err(|e| err!(Database("Failed to deserialize pdu content into type: {e}")))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue