Muhammad Hamza c28a71e78e
Use nightly for Rustfmt (#2630)
* add rustfmt.toml, use nightly in CI, update contributing docs

* run `cargo +nightly fmt`
2022-04-21 23:21:15 +05:00

69 lines
1.5 KiB
Rust

mod app;
mod header;
mod item;
mod list;
use std::cell::RefCell;
use std::fmt;
use std::ops::Deref;
use std::rc::Rc;
use yew::html::{Component, ImplicitClone, Scope};
pub struct WeakComponentLink<COMP: Component>(Rc<RefCell<Option<Scope<COMP>>>>);
impl<COMP: Component> Clone for WeakComponentLink<COMP> {
fn clone(&self) -> Self {
Self(Rc::clone(&self.0))
}
}
impl<COMP: Component> ImplicitClone for WeakComponentLink<COMP> {}
impl<COMP: Component> Default for WeakComponentLink<COMP> {
fn default() -> Self {
Self(Rc::default())
}
}
impl<COMP: Component> Deref for WeakComponentLink<COMP> {
type Target = Rc<RefCell<Option<Scope<COMP>>>>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl<COMP: Component> PartialEq for WeakComponentLink<COMP> {
fn eq(&self, other: &Self) -> bool {
Rc::ptr_eq(&self.0, &other.0)
}
}
#[derive(Debug)]
pub enum Hovered {
Header,
Item(String),
List,
None,
}
impl fmt::Display for Hovered {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"{}",
match self {
Hovered::Header => "Header",
Hovered::Item(name) => name,
Hovered::List => "List container",
Hovered::None => "Nothing",
}
)
}
}
fn main() {
wasm_logger::init(wasm_logger::Config::default());
yew::Renderer::<app::App>::new().render();
}