Skip to main content

Draft

Struct Draft 

Source
pub struct Draft {
    pub timeline_event_type: TimelineEventType,
    pub content: Box<RawValue>,
    pub state_key: Option<String>,
    pub(crate) sender: OwnedUserId,
    pub(crate) redacts: Option<OwnedEventId>,
}
Expand description

State representing a draft event containing only user intent.

A draft is the initial state of an event,

Fields§

§timeline_event_type: TimelineEventType

Matrix timeline event type.

§content: Box<RawValue>

Raw JSON event content.

§state_key: Option<String>

State key for state events (Some), or None for message-like events. State events may carry an empty-string state key (e.g. m.room.create).

§sender: OwnedUserId

The user that sent the event

§redacts: Option<OwnedEventId>

Redacted event id for redaction events

Implementations§

Source§

impl Draft

Source

pub fn new( event_type: TimelineEventType, content: Box<RawValue>, state_key: Option<String>, sender: OwnedUserId, redacts: Option<OwnedEventId>, ) -> Result<Self, Error>

Initializes a Draft from, validating content shape.

§Errors

Returns a serde_json::Error if the content does not have the format expected of the event_type

“Re-fried deep fried beans!”

Source

pub(crate) fn from_signed( event_type: TimelineEventType, content: Box<RawValue>, state_key: Option<String>, sender: OwnedUserId, redacts: Option<OwnedEventId>, ) -> Result<Self, Error>

Initializes a Draft from the content of a federation PDU, tolerating redacted content.

Unlike Draft::new, empty ({}) message-like content is accepted rather than rejected, since a redacted event may have had its content stripped to {}. This is only appropriate for already-signed events received over federation, never for client-originated content, which must go through Draft::new.

This constructor lives on Draft rather than on Signed because it runs while a PDU is being parsed into a Signed, before that value exists.

§Errors

Returns a serde_json::Error if the content does not have the format expected of the event_type.

Source

fn build( event_type: TimelineEventType, content: Box<RawValue>, state_key: Option<String>, sender: OwnedUserId, redacts: Option<OwnedEventId>, allow_redacted_content: bool, ) -> Result<Self, Error>

Shared constructor validating content shape.

When allow_redacted_content is set, empty ({}) message-like content is accepted instead of being validated, to allow loading redacted events.

Source

pub fn redact(&mut self, redacted_content: Box<RawValue>) -> Result<(), Error>

Initialize a new Draft state, assuming it has been redacted.

This function assumes that the event content is correct event content, which has passed through the Draft::new, and subsequently the redaction module. Therefore, no explicit verification is made

§Errors

Returns a serde_json::Error if, for a room-create event, the redacted content cannot be parsed as m.room.create content.

Source

pub(crate) fn content_to_map(&self) -> Map<String, Value>

Get the event content as a JSON object map.

§Panics

Panics if the content is not a valid JSON object. crate::states::Draft::new guarantees that the content is valid, so this is only reachable for events constructed bypassing that constructor.

Trait Implementations§

Source§

impl Clone for Draft

Source§

fn clone(&self) -> Draft

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Draft

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Draft

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Draft

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl Freeze for Draft

§

impl RefUnwindSafe for Draft

§

impl Send for Draft

§

impl Sync for Draft

§

impl Unpin for Draft

§

impl UnsafeUnpin for Draft

§

impl UnwindSafe for Draft

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> DropFlavorWrapper<T> for T

§

type Flavor = MayDrop

The DropFlavor that [wrap]s T into Self
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

§

const WITNESS: W = W::MAKE

A constant of the type witness
§

impl<T> Identity for T
where T: ?Sized,

§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> JsonCastable<CanonicalJsonValue> for T

§

impl<T> JsonCastable<Value> for T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more