Skip to content

doc: method-syntax.md: method chaining example doesn't show how to return self #25803

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

Closed
FluffyLlemon opened this issue May 26, 2015 · 0 comments

Comments

@FluffyLlemon
Copy link

In the method-syntax.md file:

This is called ‘method chaining’, and we can do it by returning self.

The example (copied below) that immediately follows this does not actually contain code returning self. Instead, a new Circle struct is built and returned.

The wording suggests that the next example is going to show how returning self can be done, but the example doesn't show that.

struct Circle {
    x: f64,
    y: f64,
    radius: f64,
}

impl Circle {
    fn area(&self) -> f64 {
        std::f64::consts::PI * (self.radius * self.radius)
    }

    fn grow(&self, increment: f64) -> Circle {
        Circle { x: self.x, y: self.y, radius: self.radius + increment }
    }
}

fn main() {
    let c = Circle { x: 0.0, y: 0.0, radius: 2.0 };
    println!("{}", c.area());

    let d = c.grow(2.0).area();
    println!("{}", d);
}
steveklabnik added a commit to steveklabnik/rust that referenced this issue Jun 9, 2015
As this example got changed, we stopped showing how to return self as
the first example, so this text is outdated.

Fixes rust-lang#25803
steveklabnik added a commit to steveklabnik/rust that referenced this issue Jun 9, 2015
As this example got changed, we stopped showing how to return self as
the first example, so this text is outdated.

Fixes rust-lang#25803
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

2 participants