mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-15 21:26:50 +00:00
Abstract and simplify serde_json round-trip to Ruma Raw.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
1 parent
27222f23d2
commit
f32b6ae17d
2 files changed
+19
-9
No files matched your search
@@ -1,9 +1,17 @@
|
||||
use std::{fmt, marker::PhantomData, str::FromStr};
|
||||
|
||||
use ruma::{CanonicalJsonError, CanonicalJsonObject, canonical_json::try_from_json_map};
|
||||
use ruma::{
|
||||
CanonicalJsonError, CanonicalJsonObject, canonical_json::try_from_json_map, serde::Raw,
|
||||
};
|
||||
|
||||
use crate::Result;
|
||||
|
||||
/// Perform a round-trip through serde_json starting with a native type T and
|
||||
/// ending with a Ruma Raw<U> which is usually just T.
|
||||
pub fn to_raw<T: serde::Serialize, U>(input: T) -> Result<Raw<U>> {
|
||||
Ok(serde_json::from_value(serde_json::to_value(input)?)?)
|
||||
}
|
||||
|
||||
/// Fallible conversion from any value that implements `Serialize` to a
|
||||
/// `CanonicalJsonObject`.
|
||||
///
|
||||
|
||||
Reference in new issue
Block a user