Skip to content

Commit 69ddd0b

Browse files
committed
nostr: improve docs of Kind struct methods
Signed-off-by: Yuki Kishimoto <[email protected]>
1 parent f7d45d7 commit 69ddd0b

File tree

3 files changed

+85
-53
lines changed

3 files changed

+85
-53
lines changed

bindings/nostr-ffi/src/event/kind.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,6 @@ impl Kind {
4949
self.inner.into()
5050
}
5151

52-
/// Check if it's a NIP90 job request
53-
///
54-
/// <https://github.com/nostr-protocol/nips/blob/master/90.md>
55-
#[inline]
56-
pub fn is_job_request(&self) -> bool {
57-
self.inner.is_job_request()
58-
}
59-
60-
/// Check if it's a NIP90 job result
61-
///
62-
/// <https://github.com/nostr-protocol/nips/blob/master/90.md>
63-
#[inline]
64-
pub fn is_job_result(&self) -> bool {
65-
self.inner.is_job_result()
66-
}
67-
6852
/// Check if it's regular
6953
///
7054
/// Regular means that event is expected to be stored by relays.
@@ -77,6 +61,9 @@ impl Kind {
7761

7862
/// Check if it's replaceable
7963
///
64+
/// Replaceable means that, for each combination of `pubkey` and `kind`,
65+
/// only the latest event MUST be stored by relays, older versions MAY be discarded.
66+
///
8067
/// <https://github.com/nostr-protocol/nips/blob/master/01.md>
8168
#[inline]
8269
pub fn is_replaceable(&self) -> bool {
@@ -85,6 +72,8 @@ impl Kind {
8572

8673
/// Check if it's ephemeral
8774
///
75+
/// Ephemeral means that event is not expected to be stored by relays.
76+
///
8877
/// <https://github.com/nostr-protocol/nips/blob/master/01.md>
8978
#[inline]
9079
pub fn is_ephemeral(&self) -> bool {
@@ -93,11 +82,30 @@ impl Kind {
9382

9483
/// Check if it's parameterized replaceable
9584
///
85+
/// Parametrized replaceable means that, for each combination of `pubkey`, `kind` and the `d` tag's first value,
86+
/// only the latest event MUST be stored by relays, older versions MAY be discarded.
87+
///
9688
/// <https://github.com/nostr-protocol/nips/blob/master/01.md>
9789
#[inline]
9890
pub fn is_parameterized_replaceable(&self) -> bool {
9991
self.inner.is_parameterized_replaceable()
10092
}
93+
94+
/// Check if it's a NIP-90 job request
95+
///
96+
/// <https://github.com/nostr-protocol/nips/blob/master/90.md>
97+
#[inline]
98+
pub fn is_job_request(&self) -> bool {
99+
self.inner.is_job_request()
100+
}
101+
102+
/// Check if it's a NIP-90 job result
103+
///
104+
/// <https://github.com/nostr-protocol/nips/blob/master/90.md>
105+
#[inline]
106+
pub fn is_job_result(&self) -> bool {
107+
self.inner.is_job_result()
108+
}
101109
}
102110

103111
#[derive(Enum)]

bindings/nostr-js/src/event/kind.rs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,6 @@ impl JsKind {
4242
self.inner.as_u16()
4343
}
4444

45-
/// Check if it's a NIP90 job request
46-
///
47-
/// <https://github.com/nostr-protocol/nips/blob/master/90.md>
48-
#[wasm_bindgen(js_name = isJobRequest)]
49-
pub fn is_job_request(&self) -> bool {
50-
self.inner.is_job_request()
51-
}
52-
53-
/// Check if it's a NIP90 job result
54-
///
55-
/// <https://github.com/nostr-protocol/nips/blob/master/90.md>
56-
#[wasm_bindgen(js_name = isJobResult)]
57-
pub fn is_job_result(&self) -> bool {
58-
self.inner.is_job_result()
59-
}
60-
6145
/// Check if it's regular
6246
///
6347
/// Regular means that event is expected to be stored by relays.
@@ -70,6 +54,9 @@ impl JsKind {
7054

7155
/// Check if it's replaceable
7256
///
57+
/// Replaceable means that, for each combination of `pubkey` and `kind`,
58+
/// only the latest event MUST be stored by relays, older versions MAY be discarded.
59+
///
7360
/// <https://github.com/nostr-protocol/nips/blob/master/01.md>
7461
#[wasm_bindgen(js_name = isReplaceable)]
7562
pub fn is_replaceable(&self) -> bool {
@@ -78,6 +65,8 @@ impl JsKind {
7865

7966
/// Check if it's ephemeral
8067
///
68+
/// Ephemeral means that event is not expected to be stored by relays.
69+
///
8170
/// <https://github.com/nostr-protocol/nips/blob/master/01.md>
8271
#[wasm_bindgen(js_name = isEphemeral)]
8372
pub fn is_ephemeral(&self) -> bool {
@@ -86,9 +75,28 @@ impl JsKind {
8675

8776
/// Check if it's parameterized replaceable
8877
///
78+
/// Parametrized replaceable means that, for each combination of `pubkey`, `kind` and the `d` tag's first value,
79+
/// only the latest event MUST be stored by relays, older versions MAY be discarded.
80+
///
8981
/// <https://github.com/nostr-protocol/nips/blob/master/01.md>
9082
#[wasm_bindgen(js_name = isParametrizedReplaceable)]
9183
pub fn is_parameterized_replaceable(&self) -> bool {
9284
self.inner.is_parameterized_replaceable()
9385
}
86+
87+
/// Check if it's a NIP-90 job request
88+
///
89+
/// <https://github.com/nostr-protocol/nips/blob/master/90.md>
90+
#[wasm_bindgen(js_name = isJobRequest)]
91+
pub fn is_job_request(&self) -> bool {
92+
self.inner.is_job_request()
93+
}
94+
95+
/// Check if it's a NIP-90 job result
96+
///
97+
/// <https://github.com/nostr-protocol/nips/blob/master/90.md>
98+
#[wasm_bindgen(js_name = isJobResult)]
99+
pub fn is_job_result(&self) -> bool {
100+
self.inner.is_job_result()
101+
}
94102
}

crates/nostr/src/event/kind.rs

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ use core::str::FromStr;
1414
use serde::de::{Deserialize, Deserializer, Error, Visitor};
1515
use serde::ser::{Serialize, Serializer};
1616

17-
/// NIP90 - Job request range
17+
/// NIP-90 - Job request range
1818
pub const NIP90_JOB_REQUEST_RANGE: Range<u16> = 5_000..5_999;
19-
/// NIP90 - Job result range
19+
/// NIP-90 - Job result range
2020
pub const NIP90_JOB_RESULT_RANGE: Range<u16> = 6_000..6_999;
2121
/// Regular range
2222
pub const REGULAR_RANGE: Range<u16> = 1_000..10_000;
@@ -219,25 +219,11 @@ impl Kind {
219219
self.as_u16() as u64
220220
}
221221

222-
/// Check if [`Kind`] is a NIP90 job request
223-
///
224-
/// <https://github.com/nostr-protocol/nips/blob/master/90.md>
225-
#[inline]
226-
pub fn is_job_request(&self) -> bool {
227-
NIP90_JOB_REQUEST_RANGE.contains(&self.as_u16())
228-
}
229-
230-
/// Check if [`Kind`] is a NIP90 job result
231-
///
232-
/// <https://github.com/nostr-protocol/nips/blob/master/90.md>
233-
#[inline]
234-
pub fn is_job_result(&self) -> bool {
235-
NIP90_JOB_RESULT_RANGE.contains(&self.as_u16())
236-
}
237-
238222
/// Check if it's regular
239223
///
240224
/// Regular means that event is expected to be stored by relays.
225+
///
226+
/// <https://github.com/nostr-protocol/nips/blob/master/01.md>
241227
pub fn is_regular(&self) -> bool {
242228
let kind: u16 = self.as_u16();
243229

@@ -250,7 +236,12 @@ impl Kind {
250236
REGULAR_RANGE.contains(&kind) || !self.is_replaceable()
251237
}
252238

253-
/// Check if [`Kind`] is `Replaceable`
239+
/// Check if it's replaceable
240+
///
241+
/// Replaceable means that, for each combination of `pubkey` and `kind`,
242+
/// only the latest event MUST be stored by relays, older versions MAY be discarded.
243+
///
244+
/// <https://github.com/nostr-protocol/nips/blob/master/01.md>
254245
#[inline]
255246
pub fn is_replaceable(&self) -> bool {
256247
matches!(self, Kind::Metadata)
@@ -259,17 +250,42 @@ impl Kind {
259250
|| REPLACEABLE_RANGE.contains(&self.as_u16())
260251
}
261252

262-
/// Check if [`Kind`] is `Ephemeral`
253+
/// Check if it's ephemeral
254+
///
255+
/// Ephemeral means that event is not expected to be stored by relays.
256+
///
257+
/// <https://github.com/nostr-protocol/nips/blob/master/01.md>
263258
#[inline]
264259
pub fn is_ephemeral(&self) -> bool {
265260
EPHEMERAL_RANGE.contains(&self.as_u16())
266261
}
267262

268-
/// Check if [`Kind`] is `Parameterized replaceable`
263+
/// Check if it's parameterized replaceable
264+
///
265+
/// Parametrized replaceable means that, for each combination of `pubkey`, `kind` and the `d` tag's first value,
266+
/// only the latest event MUST be stored by relays, older versions MAY be discarded.
267+
///
268+
/// <https://github.com/nostr-protocol/nips/blob/master/01.md>
269269
#[inline]
270270
pub fn is_parameterized_replaceable(&self) -> bool {
271271
PARAMETERIZED_REPLACEABLE_RANGE.contains(&self.as_u16())
272272
}
273+
274+
/// Check if it's a NIP-90 job request
275+
///
276+
/// <https://github.com/nostr-protocol/nips/blob/master/90.md>
277+
#[inline]
278+
pub fn is_job_request(&self) -> bool {
279+
NIP90_JOB_REQUEST_RANGE.contains(&self.as_u16())
280+
}
281+
282+
/// Check if it's a NIP-90 job result
283+
///
284+
/// <https://github.com/nostr-protocol/nips/blob/master/90.md>
285+
#[inline]
286+
pub fn is_job_result(&self) -> bool {
287+
NIP90_JOB_RESULT_RANGE.contains(&self.as_u16())
288+
}
273289
}
274290

275291
impl fmt::Display for Kind {

0 commit comments

Comments
 (0)