Skip to main content

Metadata

Struct Metadata 

Source
pub struct Metadata {
    pub name: Option<String>,
    pub display_name: Option<String>,
    pub about: Option<String>,
    pub website: Option<Url>,
    pub picture: Option<Url>,
    pub banner: Option<Url>,
    pub nip05: Option<String>,
    pub lud06: Option<String>,
    pub lud16: Option<String>,
    pub bot: Option<bool>,
    pub birthday: Option<Birthday>,
    pub custom: Map<String, Value>,
}
Expand description

User profile metadata published as the content of a kind: 0 event.

Every field is optional; unknown JSON properties survive a round-trip via Metadata::custom.

Fields§

§name: Option<String>

Short username, e.g. alice.

§display_name: Option<String>

Display name (NIP-24).

§about: Option<String>

Biographical description.

§website: Option<Url>

Personal web site (NIP-24).

§picture: Option<Url>

Profile picture URL.

§banner: Option<Url>

Banner image URL (NIP-24).

§nip05: Option<String>

NIP-05 verification identifier (alice@example.com).

§lud06: Option<String>

LNURL-pay identifier (legacy LUD-06).

§lud16: Option<String>

Lightning Address (LUD-16).

§bot: Option<bool>

NIP-24 bot flag: true if the profile is fully or partially automated (chatbots, newsfeeds, AI agents).

§birthday: Option<Birthday>

NIP-24 birthday object. Every component (year / month / day) is individually optional so partial dates (e.g. month-and-day only) round-trip cleanly.

§custom: Map<String, Value>

Forward-compatible escape hatch: any property the spec adds (or any project-specific custom property) is preserved verbatim here.

Two NIP-24 deprecated fields intentionally land here rather than in dedicated fields:

Access them via Self::legacy_display_name and Self::legacy_username when a caller needs to migrate an old profile without dropping bytes.

Implementations§

Source§

impl Metadata

Source

pub fn new() -> Self

Construct an empty profile.

Source

pub fn with_name<S: Into<String>>(self, name: S) -> Self

Set the name field.

Source

pub fn with_display_name<S: Into<String>>(self, name: S) -> Self

Set the display_name field (NIP-24).

Source

pub fn with_about<S: Into<String>>(self, about: S) -> Self

Set the about field.

Source

pub fn with_website(self, website: Url) -> Self

Set the website field.

Source

pub fn with_picture(self, picture: Url) -> Self

Set the picture field.

Source

pub fn with_banner(self, banner: Url) -> Self

Set the banner field (NIP-24).

Source

pub fn with_nip05<S: Into<String>>(self, nip05: S) -> Self

Set the nip05 field.

Source

pub fn with_lud06<S: Into<String>>(self, lud06: S) -> Self

Set the lud06 field (legacy LNURL-pay).

Source

pub fn with_lud16<S: Into<String>>(self, lud16: S) -> Self

Set the lud16 field (Lightning Address).

Source

pub const fn with_bot(self, bot: bool) -> Self

Set the NIP-24 bot flag.

Source

pub const fn with_birthday(self, birthday: Birthday) -> Self

Set the NIP-24 birthday object.

Source

pub fn legacy_display_name(&self) -> Option<&str>

Return the deprecated NIP-24 displayName value if the profile was produced by an older client. Prefer Self::display_name for every new write path.

Source

pub fn legacy_username(&self) -> Option<&str>

Return the deprecated NIP-24 username value. Prefer Self::name for every new write path.

Source

pub fn with_custom<S, V>(self, key: S, value: V) -> Self
where S: Into<String>, V: Into<JsonValue>,

Insert a custom JSON property.

Useful for extensions defined by future NIPs that this crate has not modelled yet.

Source

pub fn to_event_content(&self) -> Result<String, Error>

Render self as the JSON string that goes into a kind: 0 event’s content field.

§Errors

Returns the underlying serde_json error if the metadata cannot be serialized (in practice impossible for user metadata, but serde_json keeps the type fallible).

Source

pub fn from_event_content(content: &str) -> Result<Self, Error>

Parse the content of a kind: 0 event into a Metadata.

§Errors

Returns a serde_json error if content is not a JSON object.

Trait Implementations§

Source§

impl Clone for Metadata

Source§

fn clone(&self) -> Metadata

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 Metadata

Source§

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

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

impl Default for Metadata

Source§

fn default() -> Metadata

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Metadata

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 Eq for Metadata

Source§

impl PartialEq for Metadata

Source§

fn eq(&self, other: &Metadata) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Metadata

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
Source§

impl StructuralPartialEq for Metadata

Auto Trait Implementations§

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

impl<T> JsonUtil for T

Source§

fn try_to_json(&self) -> Result<String, Error>

Serialize to a compact JSON String. Read more
Source§

fn try_to_pretty_json(&self) -> Result<String, Error>

Serialize to a pretty-printed JSON String. Read more
Source§

fn from_json<S>(json: S) -> Result<Self, Error>
where S: AsRef<str>,

Deserialize from JSON. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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