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

replace BitAndAssign example with something more evocative #35927

Merged
merged 1 commit into from
Sep 1, 2016

Conversation

matthew-piziak
Copy link
Contributor

This is the augmented-assignment version of PR #35809.

r? @GuillaumeGomez

@GuillaumeGomez
Copy link
Member

Like discussed on IRC, please write simpler examples.

@matthew-piziak
Copy link
Contributor Author

Copy-pasting the IRC discussion here. I'd link to the logs, but I can't prevent them from truncating prematurely.

https://gist.github.com/matthew-piziak/a2dd18e897eb3d4113459a945d85296b

@ollie27
Copy link
Member

ollie27 commented Aug 25, 2016

I like this example, however it's not clear what should happen if the Vecs are not the same length. I think the easiest thing to do is use an array instead. Doing that and simplifying the implementation gives something like the following:

use std::ops::BitAndAssign;

#[derive(Debug, PartialEq)]
struct BooleanVector {
    value: [bool; 4],
}

impl BitAndAssign for BooleanVector {
    fn bitand_assign(&mut self, rhs: Self) {
        for (x, y) in self.value.iter_mut().zip(&rhs.value) {
            *x &= *y;
        }
    }
}

fn main() {
    let mut bv = BooleanVector { value: [true, true, false, false] };
    bv &= BooleanVector { value: [true, false, true, false] };
    let expected = BooleanVector { value: [true, false, false, false] };
    assert_eq!(bv, expected);
}

matthew-piziak added a commit to matthew-piziak/rust that referenced this pull request Aug 26, 2016
This pull request is based on the discussion in PR rust-lang#35927.

Add a module-level note that `&&` and `||` are short-circuiting operators and not overloadable.

Add a simple `Scalar` example that lifts the `&` operator to a trivial struct tuple.

Make `BooleanVector` a struct tuple.

Derive `PartialEq` for `BooleanVector` instead of implementing it.

Adds a `fn main` wrapper so that the example can integrate with Rust Playground.

simplified bitand expression

add a comment explaining what "rhs" means
steveklabnik added a commit to steveklabnik/rust that referenced this pull request Aug 26, 2016
…=GuillaumeGomez

improve `BitAnd` trait documentation

This pull request is based on the discussion in PR rust-lang#35927.

Add a module-level note that `&&` and `||` are short-circuiting operators and not overloadable.

Add a simple `Scalar` example that lifts the `&` operator to a trivial struct tuple.

Make `BooleanVector` a struct tuple.

Derive `PartialEq` for `BooleanVector` instead of implementing it.

Adds a `fn main` wrapper so that the example can integrate with Rust Playground.
@matthew-piziak
Copy link
Contributor Author

I've taken the improvements in #35993 and applied them to this PR. I figured that a simple assert_eq! was cleaner than enforcing a particular length in the struct, but let me know what you think.

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Aug 29, 2016
…=GuillaumeGomez

improve `BitAnd` trait documentation

This pull request is based on the discussion in PR rust-lang#35927.

Add a module-level note that `&&` and `||` are short-circuiting operators and not overloadable.

Add a simple `Scalar` example that lifts the `&` operator to a trivial struct tuple.

Make `BooleanVector` a struct tuple.

Derive `PartialEq` for `BooleanVector` instead of implementing it.

Adds a `fn main` wrapper so that the example can integrate with Rust Playground.
@matthew-piziak
Copy link
Contributor Author

@bors retry

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Aug 30, 2016
…=GuillaumeGomez

improve `BitAnd` trait documentation

This pull request is based on the discussion in PR rust-lang#35927.

Add a module-level note that `&&` and `||` are short-circuiting operators and not overloadable.

Add a simple `Scalar` example that lifts the `&` operator to a trivial struct tuple.

Make `BooleanVector` a struct tuple.

Derive `PartialEq` for `BooleanVector` instead of implementing it.

Adds a `fn main` wrapper so that the example can integrate with Rust Playground.
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Aug 30, 2016
…=GuillaumeGomez

improve `BitAnd` trait documentation

This pull request is based on the discussion in PR rust-lang#35927.

Add a module-level note that `&&` and `||` are short-circuiting operators and not overloadable.

Add a simple `Scalar` example that lifts the `&` operator to a trivial struct tuple.

Make `BooleanVector` a struct tuple.

Derive `PartialEq` for `BooleanVector` instead of implementing it.

Adds a `fn main` wrapper so that the example can integrate with Rust Playground.
This is the augmented-assignment version of PR rust-lang#35809.

r? @GuillaumeGomez

improved documentation a la PR rust-lang#35993
@GuillaumeGomez
Copy link
Member

Thanks!

@bors: r+ rollup

@bors
Copy link
Contributor

bors commented Aug 31, 2016

📌 Commit ba69bc8 has been approved by GuillaumeGomez

sophiajt pushed a commit to sophiajt/rust that referenced this pull request Aug 31, 2016
…, r=GuillaumeGomez

replace `BitAndAssign` example with something more evocative

This is the augmented-assignment version of PR rust-lang#35809.

r? @GuillaumeGomez
bors added a commit that referenced this pull request Sep 1, 2016
@bors bors merged commit ba69bc8 into rust-lang:master Sep 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet