nostr: add more NIP-specific builders#1369
Conversation
…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>
Codecov Report❌ Patch coverage is 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
TheAwiteb
left a comment
There was a problem hiding this comment.
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.
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` |
|
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
} |
Checklist