Struct Tag

Source
pub struct Tag { /* private fields */ }
Expand description

Tag

Implementations§

Source§

impl Tag

Source

pub fn parse<I, S>(tag: I) -> Result<Self, Error>
where I: IntoIterator<Item = S>, S: Into<String>,

Parse tag

Return error if the tag is empty!

Source

pub fn from_standardized(standardized: TagStandard) -> Self

Construct from standardized tag

Source

pub fn from_standardized_without_cell(standardized: TagStandard) -> Self

Construct from standardized tag without initialize cell (avoid a clone)

Source

pub fn kind(&self) -> TagKind<'_>

Get tag kind

Source

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

Return the first tag value (index 1), if exists.

Source

pub fn single_letter_tag(&self) -> Option<SingleLetterTag>

Source

pub fn as_standardized(&self) -> Option<&TagStandard>

Get reference of standardized tag

Source

pub fn to_standardized(self) -> Option<TagStandard>

Consume tag and get standardized tag

Source

pub fn len(&self) -> usize

Get tag len

Source

pub fn push<S>(&mut self, value: S)
where S: Into<String>,

Appends a value to the back of the Tag.

Check Vec::push doc to learn more.

This erases the TagStandard cell, if any.

Source

pub fn pop(&mut self) -> Option<String>

Removes the last value and returns it. If the Tag has only one value, returns None, since it can’t be empty.

Check Vec::pop doc to learn more.

This erases the TagStandard cell, if any.

Source

pub fn insert<S>(&mut self, index: usize, value: S) -> bool
where S: Into<String>,

Inserts a value at position index within the vector, shifting all other values after it to the right.

The value at index 0 and 1 can’t be empty. If an empty string is passed for those indexes, false is returned.

Returns true if the value has been inserted or updated successfully. Returns false if index > len.

Check Vec::insert doc to learn more.

This erases the TagStandard cell, if any.

Source

pub fn extend<I, S>(&mut self, iter: I)
where I: IntoIterator<Item = S>, S: Into<String>,

Extends the collection.

Check Vec::extend doc to learn more.

This erases the TagStandard cell, if any.

Source

pub fn as_slice(&self) -> &[String]

Get as slice of strings

Source

pub fn to_vec(self) -> Vec<String>

Consume tag and return array of strings

Source

pub fn event(event_id: EventId) -> Self

Source

pub fn public_key(public_key: PublicKey) -> Self

Source

pub fn identifier<T>(identifier: T) -> Self
where T: Into<String>,

Source

pub fn coordinate(coordinate: Coordinate, relay_url: Option<RelayUrl>) -> Self

Compose ["a", "<coordinate>", "<optional-relay-url>"] tag

https://github.com/nostr-protocol/nips/blob/master/01.md

Source

pub fn pow(nonce: u128, difficulty: u8) -> Self

Compose ["nonce", "<nonce>", "<difficulty>"] tag

https://github.com/nostr-protocol/nips/blob/master/13.md

Source

pub fn client<S>(name: S) -> Self
where S: Into<String>,

Source

pub fn expiration(timestamp: Timestamp) -> Self

Compose ["expiration", "<timestamp>"] tag

https://github.com/nostr-protocol/nips/blob/master/40.md

Source

pub fn event_report(event_id: EventId, report: Report) -> Self

Compose ["e", "<event-id>", "<report>"] tag

https://github.com/nostr-protocol/nips/blob/master/56.md

Source

pub fn public_key_report(public_key: PublicKey, report: Report) -> Self

Compose ["p", "<public-key>", "<report>"] tag

https://github.com/nostr-protocol/nips/blob/master/56.md

Source

pub fn relay_metadata( relay_url: RelayUrl, metadata: Option<RelayMetadata>, ) -> Self

Compose ["r", "<relay-url>", "<metadata>"] tag

https://github.com/nostr-protocol/nips/blob/master/65.md

Source

pub fn relay(url: RelayUrl) -> Self

Relay url

JSON: ["relay", "<relay-url>"]

Source

pub fn relays<I>(urls: I) -> Self
where I: IntoIterator<Item = RelayUrl>,

Relay URLs

JSON: ["relays", "<relay-url>", "<relay-url>"]

Source

pub fn all_relays() -> Self

All relays

JSON: ["relay", "ALL_RELAYS"]

https://github.com/nostr-protocol/nips/blob/master/62.md

Source

pub fn hashtag<T>(hashtag: T) -> Self
where T: AsRef<str>,

Compose ["t", "<hashtag>"] tag

This will convert the hashtag to lowercase.

Source

pub fn reference<T>(reference: T) -> Self
where T: Into<String>,

Compose ["r", "<value>"] tag

Source

pub fn title<T>(title: T) -> Self
where T: Into<String>,

Compose ["title", "<title>"] tag

Source

pub fn image(url: Url, dimensions: Option<ImageDimensions>) -> Self

Compose image tag

Source

pub fn description<T>(description: T) -> Self
where T: Into<String>,

Compose ["description", "<description>"] tag

Source

pub fn protected() -> Self

Source

pub fn alt<T>(summary: T) -> Self
where T: Into<String>,

A short human-readable plaintext summary of what that event is about

JSON: ["alt", "<summary>"]

https://github.com/nostr-protocol/nips/blob/master/31.md

Source

pub fn custom<I, S>(kind: TagKind<'_>, values: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Compose custom tag

JSON: ["<kind>", "<value-1>", "<value-2>", ...]

Source

pub fn is_root(&self) -> bool

Check if is a standard event tag with root marker

Source

pub fn is_reply(&self) -> bool

Check if is a standard event tag with reply marker

Source

pub fn is_protected(&self) -> bool

Check if it’s a protected event tag

https://github.com/nostr-protocol/nips/blob/master/70.md

Trait Implementations§

Source§

impl Clone for Tag

Source§

fn clone(&self) -> Tag

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Tag

Source§

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

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

impl<'de> Deserialize<'de> for Tag

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 From<Coordinate> for Tag

Source§

fn from(coordinate: Coordinate) -> Self

Converts to this type from the input type.
Source§

impl From<EventId> for Tag

Source§

fn from(event_id: EventId) -> Self

Converts to this type from the input type.
Source§

impl From<TagStandard> for Tag

Source§

fn from(standard: TagStandard) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<Tag> for Tags

Source§

fn from_iter<T>(iter: T) -> Self
where T: IntoIterator<Item = Tag>,

Creates a value from an iterator. Read more
Source§

impl Hash for Tag

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl IntoIterator for Tag

Source§

type Item = String

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<<Tag as IntoIterator>::Item>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl Ord for Tag

Source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Tag

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Tag

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for Tag

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

Auto Trait Implementations§

§

impl !Freeze for Tag

§

impl RefUnwindSafe for Tag

§

impl Send for Tag

§

impl Sync for Tag

§

impl Unpin for Tag

§

impl UnwindSafe for Tag

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<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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,