m10_sdk/types/
account_metadata.rs

1use crate::collections::ResourceId;
2use crate::error::M10Error;
3use crate::types::PublicKey;
4use m10_protos::sdk;
5
6#[derive(Clone, Debug, serde::Serialize)]
7pub struct AccountMetadata {
8    pub id: ResourceId,
9    pub owner: PublicKey,
10    pub profile_image_url: String,
11    pub name: String,
12    pub public_name: String,
13}
14
15#[cfg(feature = "format")]
16impl std::fmt::Display for AccountMetadata {
17    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
18        let Self {
19            id,
20            owner,
21            profile_image_url,
22            name,
23            public_name,
24        } = self;
25        write!(f, "AccountSet{{ id={id} owner={owner} profile_image_url={profile_image_url} name={name} public_name={public_name} }}")
26    }
27}
28
29impl TryFrom<sdk::AccountMetadata> for AccountMetadata {
30    type Error = M10Error;
31
32    fn try_from(meta: sdk::AccountMetadata) -> Result<Self, Self::Error> {
33        Ok(Self {
34            id: ResourceId::try_from(meta.id.as_ref())?,
35            owner: PublicKey(meta.owner),
36            profile_image_url: meta.profile_image_url,
37            name: meta.name,
38            public_name: meta.public_name,
39        })
40    }
41}