Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Feed Builder in favor of Feed simple create function #72

Open
FreddieRidell opened this issue May 18, 2019 · 7 comments
Open

Remove Feed Builder in favor of Feed simple create function #72

FreddieRidell opened this issue May 18, 2019 · 7 comments

Comments

@FreddieRidell
Copy link
Contributor

/// Construct a new `Feed` instance.
// TODO: make this an actual builder pattern.
// https://deterministic.space/elegant-apis-in-rust.html#builder-pattern
#[derive(Debug)]
pub struct FeedBuilder<T>

The link referenced shows a crate that offers a macro to automatically derive builders for structs. It seems like it should be relatively easy to use derive_builder with Feed. Is the intention to use this macro, or write a custom builder?

@yoshuawuyts
Copy link
Contributor

@FreddieRidell I was thinking a custom builder, as we're able to have more control over it.

@FreddieRidell
Copy link
Contributor Author

Looking through the FeedBuilder, it seems that byte_length should be being set to the total number of bytes already recorded in the Storage? this can be done, but would require updating to the newest versions of update-random-access-*.

Have I understood this correctly?

@yoshuawuyts
Copy link
Contributor

it seems that byte_length should be being set to the total number of bytes already recorded in the Storage

Though my memory is a bit foggy on the matter, I believe that's accurate.

@ZhouHansen
Copy link
Member

ZhouHansen commented Jul 31, 2019

Is there an actual builder pattern? I tried to make it an Non-consuming builder, then we can write:

if partial_keypair.secret.is_some() {
    builder.secret_key(partial_keypair.secret.unwrap())
}

Ok(builder.build()?)

But the lifetime doesn't allow it. But it is ok:

Under the rubric of making easy things easy and hard things possible, all builder methods for a consuming builder should take and returned an owned self.

Builder-pattern is useful when build a object takes a lot of work. Maybe we can build feed directly here? I opened a pr for it.

@yoshuawuyts
Copy link
Contributor

@ZhouHansen I'm not sure I follow. The feed_builder is an "actual" builder. The way to write the code above is:

if partial_keypair.secret.is_some() {
    builder = builder.secret_key(partial_keypair.secret.unwrap())
}

Ok(builder.build()?)

Maybe I'm missing something. But whatever the problem is, it seems unlikely that removing the builder in its entirety would be the solution.

@ZhouHansen
Copy link
Member

ZhouHansen commented Aug 2, 2019

@yoshuawuyts I see the // TODO: in the comment, this misleads me that the current feed_builder is not an "actual" builder yet and there're more works to do here.

At the same time I feel it's unnecessary to use builder-pattern here, the building process of feed is not complex.

@bltavares
Copy link
Member

As part of the discussion, it seems like the Builder is an actual builder.

In regards to the Feed being simple: check my comment on the PR #80 (comment)

@bltavares bltavares changed the title update feed_builder to use actual builder pattern Remove Feed Builder in favor of Feed simple create function May 17, 2020
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

No branches or pull requests

4 participants