See 'Is there a way to make this work?' in the following code:
#[derive(Copy, Clone, Eq, Hash, Debug, PartialEq)]
pub enum ChessPiece {
WhiteKing,
WhiteQueen,
WhiteRook,
WhiteKnight,
WhiteBishop,
WhitePawn,
BlackKing,
BlackQueen,
BlackRook,
BlackKnight,
BlackBishop,
BlackPawn,
NoPiece,
}
pub fn get_clicked_square_id(x: f64, y: f64, scalar: f64) -> (f64, f64) {
let board_width_height = 8f64;
let range = 0f64..(scalar * board_width_height as f64);
if !range.contains(&x) && range.contains(&y) {
panic!("No Square ID")
}
(
(x.div_euclid(scalar) * scalar),
(y.div_euclid(scalar) * scalar),
)
}
pub fn main() {
let mut tuple_vec2: Vec<_> = vec![
(29.0, 29.0, ChessPiece::WhiteRook, "a1"),
(86.0, 0.0, ChessPiece::WhiteRook, "h1"),
];
println!(
"tuple_vec2[1].0 = {:?}, tuple_vec2[1].1 = {:?}",
tuple_vec2[1].0, tuple_vec2[1].1
);
// ============================Is there a way to make this work in one line like this?
(tuple_vec2[1].0, tuple_vec2[1].1) = get_clicked_square_id(100f64, 100f64, 57f64);
// rather than
let (x, y) = get_clicked_square_id(100f64, 100f64, 57f64);
tuple_vec2[1].0 = x;
tuple_vec2[1].1 = y;
// ============================
println!(
"tuple_vec2[1].0 = {:?}, tuple_vec2[1].1 = {:?}",
tuple_vec2[1].0, tuple_vec2[1].1
);
}