events: Remove unused util module
This commit is contained in:
parent
d78cd2ed15
commit
8195496cfd
@ -134,8 +134,6 @@ mod error;
|
||||
mod event_kinds;
|
||||
mod event_type;
|
||||
mod json;
|
||||
#[doc(hidden)] // only public for external tests
|
||||
pub mod util;
|
||||
|
||||
// Hack to allow both ruma-events itself and external crates (or tests) to use procedural macros
|
||||
// that expect `ruma_events` to exist in the prelude.
|
||||
|
@ -1,23 +0,0 @@
|
||||
use serde::de::DeserializeOwned;
|
||||
use serde_json::Value as JsonValue;
|
||||
|
||||
pub fn try_variant_from_value<T, U, E>(value: JsonValue, variant: fn(T) -> U) -> Result<U, E>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
E: serde::de::Error,
|
||||
{
|
||||
serde_json::from_value(value).map(variant).map_err(serde_json_error_to_generic_de_error)
|
||||
}
|
||||
|
||||
pub fn serde_json_error_to_generic_de_error<E: serde::de::Error>(error: serde_json::Error) -> E {
|
||||
E::custom(error.to_string())
|
||||
}
|
||||
|
||||
pub fn get_field<T, E>(value: &JsonValue, field: &'static str) -> Result<T, E>
|
||||
where
|
||||
T: DeserializeOwned,
|
||||
E: serde::de::Error,
|
||||
{
|
||||
serde_json::from_value(value.get(field).cloned().ok_or_else(|| E::missing_field(field))?)
|
||||
.map_err(serde_json_error_to_generic_de_error)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user