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

Fluent interface methods should move the receiver #146

Open
Inityx opened this issue Oct 6, 2019 · 0 comments
Open

Fluent interface methods should move the receiver #146

Inityx opened this issue Oct 6, 2019 · 0 comments

Comments

@Inityx
Copy link

Inityx commented Oct 6, 2019

Many structs such as SendMessage implement a fluent interface for customization. The methods mutate in place, taking &mut self and returning &mut self. This forces a mutable binding of the original:

fn message() -> SendMessage {
    let mut message = SendMessage(CHAT, "<b>Hello</b>");
    message.parse_mode(ParseMode::Html);
    message
}

let mut message = message();
api.send(message.disable_notification()).await

These methods should instead move self, and allow chaining the methods in a single expression:

fn message() -> SendMessage {
    SendMessage(CHAT, "<b>Hello</b>").parse_mode(ParseMode::Html)
}

let message = message().disable_notification();
api.send(message).await
@Inityx Inityx changed the title Fluent interfaces should move the receiver Fluent interface methods should move the receiver Oct 6, 2019
@knsd knsd self-assigned this Oct 7, 2019
@gugahoa gugahoa added this to the 0.7.0 milestone Oct 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants