events: Move StateUnsigned::_from_parts into a trait
This commit is contained in:
parent
9b5b5e7797
commit
35d8bdd5a1
@ -174,7 +174,7 @@ pub use self::{
|
|||||||
kinds::*,
|
kinds::*,
|
||||||
relation::Relations,
|
relation::Relations,
|
||||||
state_key::EmptyStateKey,
|
state_key::EmptyStateKey,
|
||||||
unsigned::{MessageLikeUnsigned, RedactedUnsigned, StateUnsigned},
|
unsigned::{MessageLikeUnsigned, RedactedUnsigned, StateUnsigned, StateUnsignedFromParts},
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Trait to define the behavior of redacting an event.
|
/// Trait to define the behavior of redacting an event.
|
||||||
|
@ -101,10 +101,14 @@ impl<C: StateEventContent> CanBeEmpty for StateUnsigned<C> {
|
|||||||
|
|
||||||
/// Helper functions for proc-macro code.
|
/// Helper functions for proc-macro code.
|
||||||
///
|
///
|
||||||
/// Needs to be public for UI tests.
|
/// Needs to be public for state events defined outside ruma-common.
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
impl<C: StateEventContent> StateUnsigned<C> {
|
pub trait StateUnsignedFromParts: Sized {
|
||||||
pub fn _from_parts(event_type: &str, object: &RawJsonValue) -> serde_json::Result<Self> {
|
fn _from_parts(event_type: &str, object: &RawJsonValue) -> serde_json::Result<Self>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<C: StateEventContent> StateUnsignedFromParts for StateUnsigned<C> {
|
||||||
|
fn _from_parts(event_type: &str, object: &RawJsonValue) -> serde_json::Result<Self> {
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
#[serde(bound = "")] // Disable default C: Deserialize bound
|
#[serde(bound = "")] // Disable default C: Deserialize bound
|
||||||
struct WithRawPrevContent<C> {
|
struct WithRawPrevContent<C> {
|
||||||
|
@ -228,8 +228,10 @@ fn expand_deserialize_event(
|
|||||||
if has_prev_content(kind, var) {
|
if has_prev_content(kind, var) {
|
||||||
quote! {
|
quote! {
|
||||||
let unsigned = unsigned.map(|json| {
|
let unsigned = unsigned.map(|json| {
|
||||||
#ruma_common::events::StateUnsigned::_from_parts(&event_type, &json)
|
#ruma_common::events::StateUnsignedFromParts::_from_parts(
|
||||||
.map_err(#serde::de::Error::custom)
|
&event_type,
|
||||||
|
&json,
|
||||||
|
).map_err(#serde::de::Error::custom)
|
||||||
}).transpose()?.unwrap_or_default();
|
}).transpose()?.unwrap_or_default();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user