"cargo fmt" on front-end code

This commit is contained in:
Stephen Seo 2022-02-28 16:50:00 +09:00
parent d94f81d5c1
commit 0bedc34ac3

View file

@ -1,6 +1,6 @@
use yew::prelude::*;
use std::rc::Rc;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
use std::rc::Rc;
use yew::prelude::*;
const ROWS: u8 = 8; const ROWS: u8 = 8;
const COLS: u8 = 7; const COLS: u8 = 7;
@ -31,8 +31,7 @@ impl Default for SharedState {
} }
} }
struct Slot { struct Slot {}
}
enum SlotMessage { enum SlotMessage {
Press(u8), Press(u8),
@ -72,22 +71,33 @@ 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.link().context::<SharedState>(Callback::noop()).expect("shared to be set"); let (mut shared, _) = ctx
.link()
.context::<SharedState>(Callback::noop())
.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].clone();
match value_at_idx { match value_at_idx {
BoardState::Empty => shared.board.as_ref().borrow_mut()[idx as usize] = BoardState::Cyan, BoardState::Empty => {
BoardState::Cyan => shared.board.as_ref().borrow_mut()[idx as usize] = BoardState::Magenta, shared.board.as_ref().borrow_mut()[idx as usize] = BoardState::Cyan
BoardState::Magenta => shared.board.as_ref().borrow_mut()[idx as usize] = BoardState::Empty, }
BoardState::Cyan => {
shared.board.as_ref().borrow_mut()[idx as usize] = BoardState::Magenta
}
BoardState::Magenta => {
shared.board.as_ref().borrow_mut()[idx as usize] = BoardState::Empty
}
}
ctx.props()
.state
.as_ref()
.replace(shared.board.as_ref().borrow_mut()[idx as usize]);
} }
ctx.props().state.as_ref().replace(shared.board.as_ref().borrow_mut()[idx as usize]);
},
} }
true true
} }
} }
struct Wrapper { struct Wrapper {}
}
impl Component for Wrapper { impl Component for Wrapper {
type Message = (); type Message = ();
@ -98,7 +108,10 @@ impl Component for Wrapper {
} }
fn view(&self, ctx: &Context<Self>) -> Html { fn view(&self, ctx: &Context<Self>) -> Html {
let (mut shared, _) = ctx.link().context::<SharedState>(Callback::noop()).expect("state to be set"); let (mut shared, _) = ctx
.link()
.context::<SharedState>(Callback::noop())
.expect("state to be set");
let link = ctx.link(); let link = ctx.link();
html! { html! {
<div class="wrapper"> <div class="wrapper">