diff --git a/ruma-client-api/src/r0/profile/get_avatar_url.rs b/ruma-client-api/src/r0/profile/get_avatar_url.rs index 504c02a4..81b9ebd0 100644 --- a/ruma-client-api/src/r0/profile/get_avatar_url.rs +++ b/ruma-client-api/src/r0/profile/get_avatar_url.rs @@ -13,12 +13,15 @@ ruma_api! { requires_authentication: false, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: { /// The user whose avatar URL will be retrieved. #[ruma_api(path)] - pub user_id: UserId + pub user_id: &'a UserId, } + #[derive(Default)] + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: { /// The user's avatar URL, if set. #[serde(skip_serializing_if = "Option::is_none")] @@ -27,3 +30,17 @@ ruma_api! { error: crate::Error } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given user ID. + pub fn new(user_id: &'a UserId) -> Self { + Self { user_id } + } +} + +impl Response { + /// Creates a new `Response` with the given avatar URL. + pub fn new(avatar_url: Option) -> Self { + Self { avatar_url } + } +} diff --git a/ruma-client-api/src/r0/profile/get_display_name.rs b/ruma-client-api/src/r0/profile/get_display_name.rs index 87d4c0bf..b20d9912 100644 --- a/ruma-client-api/src/r0/profile/get_display_name.rs +++ b/ruma-client-api/src/r0/profile/get_display_name.rs @@ -13,17 +13,34 @@ ruma_api! { requires_authentication: false, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: { /// The user whose display name will be retrieved. #[ruma_api(path)] - pub user_id: UserId + pub user_id: &'a UserId, } + #[derive(Default)] + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: { /// The user's display name, if set. #[serde(skip_serializing_if = "Option::is_none")] - pub displayname: Option + pub displayname: Option, } error: crate::Error } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given user ID. + pub fn new(user_id: &'a UserId) -> Self { + Self { user_id } + } +} + +impl Response { + /// Creates a new `Response` with the given display name. + pub fn new(displayname: Option) -> Self { + Self { displayname } + } +} diff --git a/ruma-client-api/src/r0/profile/get_profile.rs b/ruma-client-api/src/r0/profile/get_profile.rs index 77957740..1eaa48ce 100644 --- a/ruma-client-api/src/r0/profile/get_profile.rs +++ b/ruma-client-api/src/r0/profile/get_profile.rs @@ -13,12 +13,15 @@ ruma_api! { requires_authentication: false, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: { /// The user whose profile will be retrieved. #[ruma_api(path)] - pub user_id: UserId, + pub user_id: &'a UserId, } + #[derive(Default)] + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: { /// The user's avatar URL, if set. #[serde(skip_serializing_if = "Option::is_none")] @@ -31,3 +34,17 @@ ruma_api! { error: crate::Error } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given user ID. + pub fn new(user_id: &'a UserId) -> Self { + Self { user_id } + } +} + +impl Response { + /// Creates a new `Response` with the given avatar URL and display name. + pub fn new(avatar_url: Option, displayname: Option) -> Self { + Self { avatar_url, displayname } + } +} diff --git a/ruma-client-api/src/r0/profile/set_avatar_url.rs b/ruma-client-api/src/r0/profile/set_avatar_url.rs index 8b7ba642..66f5a4a6 100644 --- a/ruma-client-api/src/r0/profile/set_avatar_url.rs +++ b/ruma-client-api/src/r0/profile/set_avatar_url.rs @@ -13,18 +13,35 @@ ruma_api! { requires_authentication: true, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: { /// The user whose avatar URL will be set. #[ruma_api(path)] - pub user_id: UserId, + pub user_id: &'a UserId, /// The new avatar URL for the user. /// /// `None` is used to unset the avatar. - pub avatar_url: Option, + pub avatar_url: Option<&'a str>, } + #[derive(Default)] + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: {} error: crate::Error } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given user ID and avatar URL. + pub fn new(user_id: &'a UserId, avatar_url: Option<&'a str>) -> Self { + Self { user_id, avatar_url } + } +} + +impl Response { + /// Creates an empty `Response`. + pub fn new() -> Self { + Self + } +} diff --git a/ruma-client-api/src/r0/profile/set_display_name.rs b/ruma-client-api/src/r0/profile/set_display_name.rs index b9a2ed15..c109240b 100644 --- a/ruma-client-api/src/r0/profile/set_display_name.rs +++ b/ruma-client-api/src/r0/profile/set_display_name.rs @@ -13,17 +13,34 @@ ruma_api! { requires_authentication: true, } + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] request: { /// The user whose display name will be set. #[ruma_api(path)] - pub user_id: UserId, + pub user_id: &'a UserId, /// The new display name for the user. #[serde(skip_serializing_if = "Option::is_none")] - pub displayname: Option, + pub displayname: Option<&'a str>, } + #[derive(Default)] + #[cfg_attr(not(feature = "unstable-exhaustive-types"), non_exhaustive)] response: {} error: crate::Error } + +impl<'a> Request<'a> { + /// Creates a new `Request` with the given user ID and display name. + pub fn new(user_id: &'a UserId, displayname: Option<&'a str>) -> Self { + Self { user_id, displayname } + } +} + +impl Response { + /// Creates an empty `Response`. + pub fn new() -> Self { + Self + } +}