YT
подскажите плиз как такой паттерн подругому написать чтоб ворнинга не было
let groups = ranks.into_iter().fold(HashMap::new(), |mut acc, x| {
match acc.get(&x) {
Some(n) => acc.insert(x, n + 1),
None => acc.insert(x, 1)
};
acc
});
Size: a a a
YT
let groups = ranks.into_iter().fold(HashMap::new(), |mut acc, x| {
match acc.get(&x) {
Some(n) => acc.insert(x, n + 1),
None => acc.insert(x, 1)
};
acc
});
YT
warning: cannot borrow `acc` as mutable because it is also borrowed as immutable
--> src/combination.rs:286:28
|
285 | match acc.get(&x) {
| --- immutable borrow occurs here
286 | Some(n) => acc.insert(x, n + 1),
| ^^^ - immutable borrow later used here
| |
| mutable borrow occurs here
|
= note: `#[warn(mutable_borrow_reservation_conflict)]` on by default
= warning: this borrowing pattern was not meant to be accepted, and may become a hard error in the future
= note: for more information, see issue #59159 <https://github.com/rust-lang/rust/issues/59159>
YT
YB
let groups = ranks.into_iter().fold(HashMap::new(), |mut acc, x| {
match acc.get(&x) {
Some(n) => acc.insert(x, n + 1),
None => acc.insert(x, 1)
};
acc
});
YT
YT
YB
YT
RP
let groups = ranks.into_iter().fold(HashMap::new(), |mut acc, x| {
match acc.get(&x) {
Some(n) => acc.insert(x, n + 1),
None => acc.insert(x, 1)
};
acc
});
RP
let mut letters = HashMap::new();
for ch in "a short treatise on fungi".chars() {
let counter = letters.entry(ch).or_insert(0);
*counter += 1;
}
RP
K
YB
RP
K
K
#[derive(StructOpt)]
struct Args {
x: bool,
y: bool
}
cargo r -- --x #<- ok
cargo r -- --y #<- ok
cargo r -- --x --y #<- ne ok
s
YB
#[derive(StructOpt)]
struct Args {
x: bool,
y: bool
}
cargo r -- --x #<- ok
cargo r -- --y #<- ok
cargo r -- --x --y #<- ne ok
K
use structopt::clap::ArgGroup;
use structopt::StructOpt;
#[derive(Debug, StructOpt)]
#[structopt(
group = ArgGroup::with_name("verbose"),
group = ArgGroup::with_name("quiet").conflicts_with("verbose"),
)]
struct Opt {
#[structopt(long, group = "verbose")]
verbose: bool,
#[structopt(long, group = "quiet")]
quiet: bool,
}
fn main() {
dbg!(Opt::from_args());
}
K