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::*,
|
||||
relation::Relations,
|
||||
state_key::EmptyStateKey,
|
||||
unsigned::{MessageLikeUnsigned, RedactedUnsigned, StateUnsigned},
|
||||
unsigned::{MessageLikeUnsigned, RedactedUnsigned, StateUnsigned, StateUnsignedFromParts},
|
||||
};
|
||||
|
||||
/// 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.
|
||||
///
|
||||
/// Needs to be public for UI tests.
|
||||
/// Needs to be public for state events defined outside ruma-common.
|
||||
#[doc(hidden)]
|
||||
impl<C: StateEventContent> StateUnsigned<C> {
|
||||
pub fn _from_parts(event_type: &str, object: &RawJsonValue) -> serde_json::Result<Self> {
|
||||
pub trait StateUnsignedFromParts: Sized {
|
||||
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)]
|
||||
#[serde(bound = "")] // Disable default C: Deserialize bound
|
||||
struct WithRawPrevContent<C> {
|
||||
|
@ -228,8 +228,10 @@ fn expand_deserialize_event(
|
||||
if has_prev_content(kind, var) {
|
||||
quote! {
|
||||
let unsigned = unsigned.map(|json| {
|
||||
#ruma_common::events::StateUnsigned::_from_parts(&event_type, &json)
|
||||
.map_err(#serde::de::Error::custom)
|
||||
#ruma_common::events::StateUnsignedFromParts::_from_parts(
|
||||
&event_type,
|
||||
&json,
|
||||
).map_err(#serde::de::Error::custom)
|
||||
}).transpose()?.unwrap_or_default();
|
||||
}
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user