Skip to content

nostr: add more NIP-specific builders#1369

Draft
yukibtc wants to merge 8 commits into
rust-nostr:masterfrom
yukibtc:more-nips-builders
Draft

nostr: add more NIP-specific builders#1369
yukibtc wants to merge 8 commits into
rust-nostr:masterfrom
yukibtc:more-nips-builders

Conversation

@yukibtc

@yukibtc yukibtc commented May 27, 2026

Copy link
Copy Markdown
Member

Checklist

yukibtc added 8 commits May 27, 2026 15:02
…nt traits

Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
Signed-off-by: Yuki Kishimoto <yukikishimoto@protonmail.com>
@yukibtc yukibtc requested a review from TheAwiteb as a code owner May 27, 2026 13:40
@codecov

codecov Bot commented May 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 69.36937% with 34 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.51%. Comparing base (ff5be7d) to head (82b5668).

Files with missing lines Patch % Lines
crates/nostr/src/event/builder.rs 25.00% 18 Missing ⚠️
crates/nostr/src/nips/nip88.rs 0.00% 4 Missing ⚠️
crates/nostr/src/nips/nip34.rs 75.00% 3 Missing ⚠️
crates/nostr/src/nips/nip35.rs 0.00% 2 Missing ⚠️
crates/nostr/src/nips/nipb0.rs 0.00% 2 Missing ⚠️
crates/nostr/src/nips/nipc0.rs 0.00% 2 Missing ⚠️
rfs/nostr-blossom/src/bud01.rs 0.00% 2 Missing ⚠️
crates/nostr/src/nips/nip17.rs 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1369      +/-   ##
==========================================
+ Coverage   72.44%   72.51%   +0.07%     
==========================================
  Files         202      202              
  Lines       33143    33138       -5     
==========================================
+ Hits        24011    24031      +20     
+ Misses       9132     9107      -25     
Flag Coverage Δ
rust 72.51% <69.36%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@TheAwiteb TheAwiteb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK.

I see why you added the Error type to the traits. But I really think it should be handled by the builder and not the trait. For example, the issue builder should not take an invalid coordinate in the first place.

#1358 (comment)

@TheAwiteb

Copy link
Copy Markdown
Member

But I really think it should be handled by the builder and not the trait. For example, the issue builder should not take an invalid coordinate in the first place.

Something like this

pub struct GitIssue {
    /// The repository address
    repository: Coordinate,
    /// The issue content (markdown)
    content: String,
    /// Subject
    subject: Option<String>,
    /// Labels
    labels: Vec<String>,
}

pub struct GitIssueBuilder {
    /// The repository address
    pub repository: Coordinate,
    /// The issue content (markdown)
    pub content: String,
    /// Subject
    pub subject: Option<String>,
    /// Labels
    pub labels: Vec<String>,
}

impl GitIssueBuilder {
    pub fn new(repository: Coordinate, content: String) -> Self {
        Self {
            repository,
            content,
        }
    }

    // .. reset of the functions, like `subject`, `label`, `extend_labels` and `label`

    pub fn build(self) -> Result<GitIssue, Error> {
        // Check here

        Ok(GitIssue {
            // ..
        })
    }
}

// Impl the finalizer to `GitIssue`

@TheAwiteb

TheAwiteb commented May 30, 2026

Copy link
Copy Markdown
Member

perhaps we can use https://bon-rs.com for this? https://crates.io/crates/bon


Check this https://bon-rs.com/guide/patterns/fallible-builders

pub struct User {
    id: u32,
    name: String,
}

#[bon]
impl User {
    #[builder]
    pub fn new(id: u32, name: String) -> Result<Self, Error> {
        if name.is_empty() {
            return Err(anyhow::anyhow!("Empty name is disallowed"));
        }

        Ok(Self { id, name })
    }
}

// The `build()` method returns a `Result`
let result = User::builder()
    .id(42)
    .name(String::new())
    .build();

if let Err(error) = result {
    // Handle the error
}

@yukibtc yukibtc marked this pull request as draft June 3, 2026 09:54
@yukibtc yukibtc added this to the v0.45 milestone Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants