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

Use of mut self in builders #54

Closed
Restioson opened this issue Sep 10, 2017 · 4 comments
Closed

Use of mut self in builders #54

Restioson opened this issue Sep 10, 2017 · 4 comments

Comments

@Restioson
Copy link

Restioson commented Sep 10, 2017

Hi! It seems like log4rs uses mut self for many of the config builder methods (such as .appender). It seems that it is preffered to use &mut self for builders: https://aturon.github.io/ownership/builders.html#non-consuming-builders-(preferred):

@sfackler
Copy link
Collaborator

You can use them in separate statements:

let mut builder = Config::builder()
    .test_on_check_out(false);
builder = builder.helper_threads(10);
let config = builder.build();

The config contains a couple of bits of owned/non-cloneable data so build can't take &self as the bottom of the section you linked discusses: https://aturon.github.io/ownership/builders.html#consuming-builders:

@Restioson
Copy link
Author

Restioson commented Sep 10, 2017

Yeah, sorry, got muddled on that bit 😅 (really sorry for the mistake!) The article still seems to reccomend the &mut pattern though. I think this is what derive-builder uses too

@Restioson
Copy link
Author

This would remove the need to keep setting the builder in statement form

@estk
Copy link
Owner

estk commented Oct 11, 2019

Not sure this is still relevant in 2019... the blog post is gone though.

@estk estk closed this as completed Oct 11, 2019
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

3 participants