"cargo clippy" (linter) fixes

This commit is contained in:
Stephen Seo 2022-02-28 16:53:01 +09:00
parent 0bedc34ac3
commit dd59bdb5f3

View file

@ -2,7 +2,7 @@ use std::cell::{Cell, RefCell};
use std::rc::Rc; use std::rc::Rc;
use yew::prelude::*; use yew::prelude::*;
const ROWS: u8 = 8; //const ROWS: u8 = 8;
const COLS: u8 = 7; const COLS: u8 = 7;
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
@ -58,7 +58,7 @@ impl Component for Slot {
BoardState::Cyan => "cyan", BoardState::Cyan => "cyan",
BoardState::Magenta => "magenta", BoardState::Magenta => "magenta",
}; };
let idx_copy = idx.clone(); let idx_copy = idx;
let onclick = ctx.link().callback(move |_| SlotMessage::Press(idx_copy)); let onclick = ctx.link().callback(move |_| SlotMessage::Press(idx_copy));
let col = idx % COLS; let col = idx % COLS;
let row = idx / COLS; let row = idx / COLS;
@ -71,11 +71,11 @@ impl Component for Slot {
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool { fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool {
match msg { match msg {
SlotMessage::Press(idx) => { SlotMessage::Press(idx) => {
let (mut shared, _) = ctx let (shared, _) = ctx
.link() .link()
.context::<SharedState>(Callback::noop()) .context::<SharedState>(Callback::noop())
.expect("shared to be set"); .expect("shared to be set");
let value_at_idx = shared.board.as_ref().borrow()[idx as usize].clone(); let value_at_idx = shared.board.as_ref().borrow()[idx as usize];
match value_at_idx { match value_at_idx {
BoardState::Empty => { BoardState::Empty => {
shared.board.as_ref().borrow_mut()[idx as usize] = BoardState::Cyan shared.board.as_ref().borrow_mut()[idx as usize] = BoardState::Cyan
@ -103,16 +103,15 @@ impl Component for Wrapper {
type Message = (); type Message = ();
type Properties = (); type Properties = ();
fn create(ctx: &Context<Self>) -> Self { fn create(_ctx: &Context<Self>) -> Self {
Self {} Self {}
} }
fn view(&self, ctx: &Context<Self>) -> Html { fn view(&self, ctx: &Context<Self>) -> Html {
let (mut shared, _) = ctx let (shared, _) = ctx
.link() .link()
.context::<SharedState>(Callback::noop()) .context::<SharedState>(Callback::noop())
.expect("state to be set"); .expect("state to be set");
let link = ctx.link();
html! { html! {
<div class="wrapper"> <div class="wrapper">
<Slot idx=0 state={Rc::new(Cell::new(shared.board.as_ref().borrow()[0]))} /> <Slot idx=0 state={Rc::new(Cell::new(shared.board.as_ref().borrow()[0]))} />
@ -175,9 +174,10 @@ impl Component for Wrapper {
} }
} }
} }
#[function_component(App)] #[function_component(App)]
fn app() -> Html { fn app() -> Html {
let ctx = use_state(|| SharedState::default()); let ctx = use_state(SharedState::default);
html! { html! {
<ContextProvider<SharedState> context={(*ctx).clone()}> <ContextProvider<SharedState> context={(*ctx).clone()}>
<Wrapper /> <Wrapper />