Skip to main content

ruma_common/profile/
static_profile_field.rs

1//! Types for common user profile fields.
2
3#![allow(clippy::exhaustive_structs)]
4
5use ruma_common::OwnedMxcUri;
6#[cfg(feature = "unstable-msc4426")]
7use ruma_common::profile::{CallProfileField, StatusProfileField};
8use serde::{Serialize, de::DeserializeOwned};
9
10/// Trait implemented by types representing a field in a user's [profile] having a statically-known
11/// name.
12///
13/// [profile]: https://spec.matrix.org/v1.18/client-server-api/#profiles
14pub trait StaticProfileField {
15    /// The type for the value of the field.
16    type Value: Sized + Serialize + DeserializeOwned;
17
18    /// The string representation of this field.
19    const NAME: &str;
20}
21
22/// The user's avatar URL.
23#[derive(Debug, Clone, Copy)]
24pub struct AvatarUrl;
25
26impl StaticProfileField for AvatarUrl {
27    type Value = OwnedMxcUri;
28    const NAME: &str = "avatar_url";
29}
30
31/// The user's display name.
32#[derive(Debug, Clone, Copy)]
33pub struct DisplayName;
34
35impl StaticProfileField for DisplayName {
36    type Value = String;
37    const NAME: &str = "displayname";
38}
39
40/// The user's time zone.
41#[derive(Debug, Clone, Copy)]
42pub struct TimeZone;
43
44impl StaticProfileField for TimeZone {
45    type Value = String;
46    const NAME: &str = "m.tz";
47}
48
49/// The user's current status.
50#[cfg(feature = "unstable-msc4426")]
51#[derive(Debug, Clone, Copy)]
52pub struct Status;
53
54#[cfg(feature = "unstable-msc4426")]
55impl StaticProfileField for Status {
56    type Value = StatusProfileField;
57    const NAME: &str = "org.matrix.msc4426.status";
58}
59
60/// The user's call indicator.
61#[cfg(feature = "unstable-msc4426")]
62#[derive(Debug, Clone, Copy)]
63pub struct Call;
64
65#[cfg(feature = "unstable-msc4426")]
66impl StaticProfileField for Call {
67    type Value = CallProfileField;
68    const NAME: &str = "org.matrix.msc4426.call";
69}