federation: Remove ctor in favor of Init struct

This commit is contained in:
Devin Ragotzy 2021-06-18 14:50:34 -04:00 committed by Jonas Platte
parent 030f23b9e9
commit 6d0ff8b876
3 changed files with 52 additions and 25 deletions

View File

@ -110,7 +110,7 @@ pub struct RequestInit<'a> {
} }
impl<'a> From<RequestInit<'a>> for Request<'a> { impl<'a> From<RequestInit<'a>> for Request<'a> {
/// Creates a new `Request` with the given parameters. /// Creates a new `Request` from `RequestInit`.
fn from(init: RequestInit<'a>) -> Self { fn from(init: RequestInit<'a>) -> Self {
Self { Self {
room_id: init.room_id, room_id: init.room_id,

View File

@ -41,7 +41,8 @@ ruma_api! {
} }
impl Request { impl Request {
/// Creates a new `Request` with the given parameters. /// Creates a new `Request` with the given room ID, event ID, room version, event and invite
/// room state.
pub fn new( pub fn new(
room_id: RoomId, room_id: RoomId,
event_id: EventId, event_id: EventId,

View File

@ -68,29 +68,55 @@ ruma_api! {
} }
} }
impl<'a> Request<'a> { /// Initial set of fields of `Request`.
/// Creates a new `Request` with: ///
/// * the room ID that is about to be left. /// This struct will not be updated even if additional fields are added to `Request` in a
/// * the event ID for the leave event. /// new (non-breaking) release of the Matrix specification.
/// * the user ID of the leaving member. #[derive(Debug)]
/// * the name of the leaving homeserver. #[allow(clippy::exhaustive_structs)]
/// * a timestamp added by the leaving homeserver. pub struct RequestInit<'a> {
/// * the value `m.room.member`. /// The room ID that is about to be left.
/// * the user ID of the leaving member. pub room_id: &'a RoomId,
/// * the content of the event.
/// * this field must be present but is ignored; it may be 0. /// The event ID for the leave event.
#[allow(clippy::too_many_arguments)] pub event_id: &'a EventId,
pub fn new(
room_id: &'a RoomId, /// The user ID of the leaving member.
event_id: &'a EventId, pub sender: &'a UserId,
sender: &'a UserId,
origin: &'a ServerName, /// The name of the leaving homeserver.
origin_server_ts: MilliSecondsSinceUnixEpoch, pub origin: &'a ServerName,
event_type: EventType,
state_key: &'a str, /// A timestamp added by the leaving homeserver.
content: Raw<MemberEventContent>, pub origin_server_ts: MilliSecondsSinceUnixEpoch,
depth: UInt,
) -> Self { /// The value `m.room.member`.
pub event_type: EventType,
/// The user ID of the leaving member.
pub state_key: &'a str,
/// The content of the event.
pub content: Raw<MemberEventContent>,
/// This field must be present but is ignored; it may be 0.
pub depth: UInt,
}
impl<'a> From<RequestInit<'a>> for Request<'a> {
/// Creates a new `Request` from `RequestInit`.
fn from(init: RequestInit<'a>) -> Self {
let RequestInit {
room_id,
event_id,
sender,
origin,
origin_server_ts,
event_type,
state_key,
content,
depth,
} = init;
Self { Self {
room_id, room_id,
event_id, event_id,