Switch todo!() to unreachable!/unimplemented! where it matters

This commit is contained in:
Jonathan Kelley 2024-01-31 16:26:12 -08:00
parent a14789eebc
commit 8f07d881a6
No known key found for this signature in database
GPG key ID: 1FBB50F7EB0A08BE
27 changed files with 73 additions and 180 deletions

View file

@ -8,7 +8,6 @@ fn app() -> Element {
let mut value = use_signal(|| 0);
let mut depth = use_signal(|| 0_usize);
let items = use_memo(move || (0..depth()).map(|f| f as _).collect::<Vec<isize>>());
let state = use_memo(move || value() + 1);
println!("rendering app");

View file

@ -25,14 +25,12 @@ fn app() -> Element {
}
#[component]
fn Component(a: i32, b: i32, c: i32, children: Element, onclick: EventHandler<()>) -> Element {
fn Component(a: i32, b: i32, c: i32, children: Element, onclick: EventHandler) -> Element {
rsx! {
div { "{a}" }
div { "{b}" }
div { "{c}" }
div { {children} }
div {
onclick: move |_| onclick.call(()),
}
div { onclick: move |_| onclick.call(()) }
}
}

View file

@ -15,7 +15,7 @@ fn app() -> Element {
// use_effect will subscribe to any changes in the signal values it captures
// effects will always run after first mount and then whenever the signal values change
use_effect(move || println!("Count changed to {}", count()));
use_effect(move || println!("Count changed to {count}"));
// We can do early returns and conditional rendering which will pause all futures that haven't been polled
if count() > 30 {
@ -49,7 +49,7 @@ fn app() -> Element {
button { onclick: move |_| count += 1, "Up high!" }
button { onclick: move |_| count -= 1, "Down low!" }
button { onclick: move |_| running.toggle(), "Toggle counter" }
button { onclick: move |_| saved_values.push(count().to_string()), "Save this value" }
button { onclick: move |_| saved_values.push(count.to_string()), "Save this value" }
button { onclick: move |_| saved_values.clear(), "Clear saved values" }
// We can do boolean operations on the current signal value
@ -71,6 +71,7 @@ fn app() -> Element {
// You can pass a value directly to any prop that accepts a signal
Child { count: doubled_count() }
Child { count: doubled_count }
}
}

View file

@ -22,7 +22,7 @@ fn app() -> Element {
// use a for loop where the body itself is RSX
for name in 0..10 {
div {"{name}"}
div { "{name}" }
}
// Or even use an unterminated conditional

View file

@ -4,7 +4,7 @@ use syn::spanned::Spanned;
use syn::{parse_quote, Expr, Lit, Meta, Token, Type};
const FORMATTED_TYPE_START: &str = "static TY_AFTER_HERE:";
const FORMATTED_TYPE_END: &str = "= todo!();";
const FORMATTED_TYPE_END: &str = "= unreachable!();";
/// Attempts to convert the given literal to a string.
/// Converts ints and floats to their base 10 counterparts.

View file

@ -17,7 +17,7 @@ loop {
}
# fn app() -> Element { None }
# struct SomeRenderer; impl SomeRenderer { fn new() -> SomeRenderer { SomeRenderer; } async fn event() -> () { todo!() } }
# struct SomeRenderer; impl SomeRenderer { fn new() -> SomeRenderer { SomeRenderer; } async fn event() -> () { unimplemented!() } }
```
## Features

View file

@ -150,8 +150,8 @@ impl<T: std::fmt::Debug> std::fmt::Debug for Event<T> {
/// }
///
/// #[derive(Props)]
/// struct MyProps<'a> {
/// onclick: EventHandler<'a, MouseEvent>,
/// struct MyProps {
/// onclick: EventHandler<MouseEvent>,
/// }
///
/// fn MyComponent(cx: MyProps) -> Element {

View file

@ -72,7 +72,7 @@ where
{
type Builder = P;
fn builder() -> Self::Builder {
todo!()
unreachable!("Root props technically are never built")
}
fn memoize(&mut self, _other: &Self) -> bool {
true

View file

@ -77,100 +77,3 @@ fn events_generate() {
]
)
}
// #[test]
// fn components_generate() {
// fn app() -> Element {
// let render_phase = use_hook(|| 0);
// *render_phase += 1;
// match *render_phase {
// 1 => rsx_without_templates!("Text0"),
// 2 => rsx_without_templates!(div {}),
// 3 => rsx_without_templates!("Text2"),
// 4 => rsx_without_templates!(Child {}),
// 5 => rsx_without_templates!({ None as Option<()> }),
// 6 => rsx_without_templates!("text 3"),
// 7 => rsx_without_templates!({ (0..2).map(|f| rsx_without_templates!("text {f}")) }),
// 8 => rsx_without_templates!(Child {}),
// _ => todo!(),
// })
// };
// fn Child() -> Element {
// println!("Running child");
// render_without_templates! {
// h1 {}
// })
// }
// let mut dom = VirtualDom::new(app);
// let edits = dom.rebuild_to_vec();
// assert_eq!(
// edits.edits,
// [
// CreateTextNode { root: Some(1), text: "Text0" },
// AppendChildren { root: Some(0), children: vec![1] }
// ]
// );
// assert_eq!(
// dom.hard_diff(ScopeId::ROOT).edits,
// [
// CreateElement { root: Some(2), tag: "div", children: 0 },
// ReplaceWith { root: Some(1), nodes: vec![2] }
// ]
// );
// assert_eq!(
// dom.hard_diff(ScopeId::ROOT).edits,
// [
// CreateTextNode { root: Some(1), text: "Text2" },
// ReplaceWith { root: Some(2), nodes: vec![1] }
// ]
// );
// // child {}
// assert_eq!(
// dom.hard_diff(ScopeId::ROOT).edits,
// [
// CreateElement { root: Some(2), tag: "h1", children: 0 },
// ReplaceWith { root: Some(1), nodes: vec![2] }
// ]
// );
// // placeholder
// assert_eq!(
// dom.hard_diff(ScopeId::ROOT).edits,
// [
// CreatePlaceholder { root: Some(1) },
// ReplaceWith { root: Some(2), nodes: vec![1] }
// ]
// );
// assert_eq!(
// dom.hard_diff(ScopeId::ROOT).edits,
// [
// CreateTextNode { root: Some(2), text: "text 3" },
// ReplaceWith { root: Some(1), nodes: vec![2] }
// ]
// );
// assert_eq!(
// dom.hard_diff(ScopeId::ROOT).edits,
// [
// CreateTextNode { text: "text 0", root: Some(1) },
// CreateTextNode { text: "text 1", root: Some(3) },
// ReplaceWith { root: Some(2), nodes: vec![1, 3] },
// ]
// );
// assert_eq!(
// dom.hard_diff(ScopeId::ROOT).edits,
// [
// CreateElement { tag: "h1", root: Some(2), children: 0 },
// ReplaceWith { root: Some(1), nodes: vec![2] },
// Remove { root: Some(3) },
// ]
// );
// }

View file

@ -95,7 +95,7 @@ fn diffing_drops_old() {
match generation() % 2 {
0 => rsx!( ChildComp1 { name: "asdasd".to_string() }),
1 => rsx!( ChildComp2 { name: "asdasd".to_string() }),
_ => todo!()
_ => unreachable!()
}
}
}

View file

@ -97,14 +97,6 @@ fn memo_works_properly() {
let mut dom = VirtualDom::new(app);
dom.rebuild(&mut dioxus_core::NoOpMutations);
// todo!()
// dom.hard_diff(ScopeId::ROOT);
// dom.hard_diff(ScopeId::ROOT);
// dom.hard_diff(ScopeId::ROOT);
// dom.hard_diff(ScopeId::ROOT);
// dom.hard_diff(ScopeId::ROOT);
// dom.hard_diff(ScopeId::ROOT);
// dom.hard_diff(ScopeId::ROOT);
}
#[test]

View file

@ -184,7 +184,7 @@ pub trait DioxusRouterExt<S> {
/// }
///
/// fn app() -> Element {
/// todo!()
/// unimplemented!()
/// }
/// ```
fn serve_static_assets(self, assets_path: impl Into<std::path::PathBuf>) -> Self;
@ -213,7 +213,7 @@ pub trait DioxusRouterExt<S> {
/// }
///
/// fn app() -> Element {
/// todo!()
/// unimplemented!()
/// }
/// ```
fn serve_dioxus_application(

View file

@ -200,7 +200,7 @@ pub trait DioxusRouterExt {
/// .await;
/// }
///
/// fn app() -> Element {todo!()}
/// fn app() -> Element {unimplemented!() }
/// ```
fn serve_dioxus_application(
self,

View file

@ -177,7 +177,7 @@ pub fn register_server_fns(server_fn_route: &'static str) -> BoxedFilter<(impl R
/// }
///
/// fn app() -> Element {
/// todo!()
/// None
/// }
/// ```
pub fn serve_dioxus_application(

View file

@ -16,7 +16,7 @@ use serde::{de::DeserializeOwned, Serialize};
/// 1234
/// }));
///
/// todo!()
/// None
/// }
/// ```
pub fn server_cached<O: 'static + Serialize + DeserializeOwned>(server_fn: impl Fn() -> O) -> O {

View file

@ -470,7 +470,7 @@ pub fn apply_layout_attributes_cfg(
fn extract_px_value(length_value: LengthValue) -> f32 {
match length_value {
LengthValue::Px(value) => value,
_ => todo!(),
_ => todo!("Only px values are supported"),
}
}
@ -480,7 +480,7 @@ fn convert_length_percentage(
match dimension_percentage {
DimensionPercentage::Dimension(value) => LengthPercentage::Points(extract_px_value(value)),
DimensionPercentage::Percentage(percentage) => LengthPercentage::Percent(percentage.0),
DimensionPercentage::Calc(_) => todo!(),
DimensionPercentage::Calc(_) => todo!("Calc is not supported yet"),
}
}
@ -492,7 +492,7 @@ fn convert_padding(dimension_percentage: LengthPercentageOrAuto) -> LengthPercen
LengthPercentage::Points(extract_px_value(value))
}
DimensionPercentage::Percentage(percentage) => LengthPercentage::Percent(percentage.0),
DimensionPercentage::Calc(_) => unimplemented!(),
DimensionPercentage::Calc(_) => unimplemented!("Calc is not supported yet"),
},
}
}
@ -509,7 +509,7 @@ fn convert_length_percentage_or_auto(
DimensionPercentage::Percentage(percentage) => {
LengthPercentageAuto::Percent(percentage.0)
}
DimensionPercentage::Calc(_) => todo!(),
DimensionPercentage::Calc(_) => todo!("Calc is not supported yet"),
},
}
}
@ -518,7 +518,7 @@ fn convert_dimension(dimension_percentage: DimensionPercentage<LengthValue>) ->
match dimension_percentage {
DimensionPercentage::Dimension(value) => Dimension::Points(extract_px_value(value)),
DimensionPercentage::Percentage(percentage) => Dimension::Percent(percentage.0),
DimensionPercentage::Calc(_) => todo!(),
DimensionPercentage::Calc(_) => todo!("Calc is not supported yet"),
}
}
@ -533,7 +533,7 @@ fn convert_border_side_width(
border::BorderSideWidth::Thick => LengthPercentage::Points(border_width_config.thick),
border::BorderSideWidth::Medium => LengthPercentage::Points(border_width_config.medium),
border::BorderSideWidth::Thin => LengthPercentage::Points(border_width_config.thin),
border::BorderSideWidth::Length(_) => unimplemented!(),
border::BorderSideWidth::Length(_) => todo!("Only Length::Value is supported"),
}
}

View file

@ -210,7 +210,7 @@ impl RinkWidget for NodeRef<'_> {
[1, -1] => [points_history[1][0], points_history[1][1] - 1],
[-1, 1] => [points_history[1][0], points_history[1][1] + 1],
[-1, -1] => [points_history[1][0] - 1, points_history[1][1]],
_ => todo!(),
_ => unreachable!(),
};
draw(
buf,
@ -253,7 +253,7 @@ impl RinkWidget for NodeRef<'_> {
_ => match border.radius {
Dimension::Percent(p) => p * area.width as f32 / 100.0,
Dimension::Points(p) => p,
_ => todo!(),
_ => unreachable!(),
}
.abs()
.min((area.width as f32 / RADIUS_MULTIPLIER[0]) / 2.0)

View file

@ -384,7 +384,7 @@ fn apply_border(name: &str, value: &str, style: &mut StyleModifier) {
"outset" => BorderStyle::Outset,
"none" => BorderStyle::None,
"hidden" => BorderStyle::Hidden,
_ => todo!(),
_ => todo!("Implement other border styles"),
}
}
match name {
@ -582,7 +582,7 @@ fn apply_font(name: &str, value: &str, style: &mut StyleModifier) {
"oblique" => style.core = style.core.add_modifier(Modifier::ITALIC),
_ => (),
},
"font-variant" => todo!(),
"font-variant" => todo!("Implement font-variant"),
"font-weight" => match value {
"bold" => style.core = style.core.add_modifier(Modifier::BOLD),
"normal" => style.core = style.core.remove_modifier(Modifier::BOLD),
@ -596,8 +596,8 @@ fn apply_text(name: &str, value: &str, style: &mut StyleModifier) {
use ratatui::style::Modifier;
match name {
"text-align" => todo!(),
"text-align-last" => todo!(),
"text-align" => todo!("Implement text-align"),
"text-align-last" => todo!("text-Implement align-last"),
"text-decoration" | "text-decoration-line" => {
for v in value.split(' ') {
match v {
@ -607,19 +607,19 @@ fn apply_text(name: &str, value: &str, style: &mut StyleModifier) {
}
}
}
"text-decoration-color" => todo!(),
"text-decoration-style" => todo!(),
"text-indent" => todo!(),
"text-justify" => todo!(),
"text-overflow" => todo!(),
"text-shadow" => todo!(),
"text-transform" => todo!(),
_ => todo!(),
"text-decoration-color" => todo!("text-Implement decoration-color"),
"text-decoration-style" => todo!("text-Implement decoration-style"),
"text-indent" => todo!("Implement text-indent"),
"text-justify" => todo!("Implement text-justify"),
"text-overflow" => todo!("Implement text-overflow"),
"text-shadow" => todo!("Implement text-shadow"),
"text-transform" => todo!("Implement text-transform"),
_ => todo!("Implement other text attributes"),
}
}
fn apply_transition(_name: &str, _value: &str, _style: &mut StyleModifier) {
todo!()
todo!("Implement transitions")
}
const SORTED_STYLE_ATTRS: &[&str] = &[

View file

@ -21,9 +21,9 @@ where
/// # use dioxus_router::prelude::*;
/// # use dioxus::prelude::*;
/// # #[component]
/// # fn Index() -> Element { todo!() }
/// # fn Index() -> Element { None }
/// # #[component]
/// # fn OtherPage() -> Element { todo!() }
/// # fn OtherPage() -> Element { None }
/// #[derive(Clone, Routable, Debug, PartialEq)]
/// enum Route {
/// #[route("/")]

View file

@ -54,9 +54,9 @@ pub trait HistoryProvider<R: Routable> {
/// # use dioxus_router::prelude::*;
/// # use dioxus::prelude::*;
/// # #[component]
/// # fn Index() -> Element { todo!() }
/// # fn Index() -> Element { None }
/// # #[component]
/// # fn OtherPage() -> Element { todo!() }
/// # fn OtherPage() -> Element { None }
/// #[derive(Clone, Routable, Debug, PartialEq)]
/// enum Route {
/// #[route("/")]
@ -92,8 +92,8 @@ pub trait HistoryProvider<R: Routable> {
/// # use dioxus_router::prelude::*;
/// # use dioxus::prelude::*;
/// # #[component]
/// # fn Index() -> Element { todo!() }
/// # fn Other() -> Element { todo!() }
/// # fn Index() -> Element { None }
/// # fn Other() -> Element { None }
/// #[derive(Clone, Routable, Debug, PartialEq)]
/// enum Route {
/// #[route("/")]
@ -121,9 +121,9 @@ pub trait HistoryProvider<R: Routable> {
/// # use dioxus_router::prelude::*;
/// # use dioxus::prelude::*;
/// # #[component]
/// # fn Index() -> Element { todo!() }
/// # fn Index() -> Element { None }
/// # #[component]
/// # fn OtherPage() -> Element { todo!() }
/// # fn OtherPage() -> Element { None }
/// #[derive(Clone, Routable, Debug, PartialEq)]
/// enum Route {
/// #[route("/")]
@ -153,9 +153,9 @@ pub trait HistoryProvider<R: Routable> {
/// # use dioxus_router::prelude::*;
/// # use dioxus::prelude::*;
/// # #[component]
/// # fn Index() -> Element { todo!() }
/// # fn Index() -> Element { None }
/// # #[component]
/// # fn OtherPage() -> Element { todo!() }
/// # fn OtherPage() -> Element { None }
/// #[derive(Clone, Routable, Debug, PartialEq)]
/// enum Route {
/// #[route("/")]
@ -186,9 +186,9 @@ pub trait HistoryProvider<R: Routable> {
/// # use dioxus_router::prelude::*;
/// # use dioxus::prelude::*;
/// # #[component]
/// # fn Index() -> Element { todo!() }
/// # fn Index() -> Element { None }
/// # #[component]
/// # fn OtherPage() -> Element { todo!() }
/// # fn OtherPage() -> Element { None }
/// #[derive(Clone, Routable, Debug, PartialEq)]
/// enum Route {
/// #[route("/")]
@ -219,9 +219,9 @@ pub trait HistoryProvider<R: Routable> {
/// # use dioxus_router::prelude::*;
/// # use dioxus::prelude::*;
/// # #[component]
/// # fn Index() -> Element { todo!() }
/// # fn Index() -> Element { None }
/// # #[component]
/// # fn OtherPage() -> Element { todo!() }
/// # fn OtherPage() -> Element { None }
/// #[derive(Clone, Routable, Debug, PartialEq)]
/// enum Route {
/// #[route("/")]
@ -248,9 +248,9 @@ pub trait HistoryProvider<R: Routable> {
/// # use dioxus_router::prelude::*;
/// # use dioxus::prelude::*;
/// # #[component]
/// # fn Index() -> Element { todo!() }
/// # fn Index() -> Element { None }
/// # #[component]
/// # fn OtherPage() -> Element { todo!() }
/// # fn OtherPage() -> Element { None }
/// #[derive(Clone, Routable, Debug, PartialEq)]
/// enum Route {
/// #[route("/")]

View file

@ -20,7 +20,7 @@ pub enum NavigationTarget<R> {
/// # use dioxus_router::navigation::NavigationTarget;
/// # #[component]
/// # fn Index() -> Element {
/// # todo!()
/// # unreachable!()
/// # }
/// #[derive(Clone, Routable, PartialEq, Debug)]
/// enum Route {
@ -40,7 +40,7 @@ pub enum NavigationTarget<R> {
/// # use dioxus_router::navigation::NavigationTarget;
/// # #[component]
/// # fn Index() -> Element {
/// # todo!()
/// # unreachable!()
/// # }
/// #[derive(Clone, Routable, PartialEq, Debug)]
/// enum Route {

View file

@ -213,9 +213,9 @@ pub trait Routable: FromStr + Display + Clone + 'static {
/// use dioxus::prelude::*;
///
/// #[component]
/// fn Home() -> Element { todo!() }
/// fn Home() -> Element { None }
/// #[component]
/// fn About() -> Element { todo!() }
/// fn About() -> Element { None }
///
/// #[derive(Routable, Clone, PartialEq, Debug)]
/// enum Route {
@ -255,9 +255,9 @@ pub trait Routable: FromStr + Display + Clone + 'static {
/// use dioxus::prelude::*;
///
/// #[component]
/// fn Home() -> Element { todo!() }
/// fn Home() -> Element { None }
/// #[component]
/// fn About() -> Element { todo!() }
/// fn About() -> Element { None }
///
/// #[derive(Routable, Clone, PartialEq, Debug)]
/// enum Route {

View file

@ -15,7 +15,7 @@ use crate::prelude::*;
/// # use dioxus::prelude::*;
/// # #[component]
/// # fn Index() -> Element {
/// # todo!()
/// # None
/// # }
/// #[derive(Clone, Routable)]
/// enum Route {

View file

@ -60,7 +60,7 @@ fn href_internal() {
#[component]
fn Test() -> Element {
todo!()
unimplemented!()
}
#[component]
@ -94,7 +94,7 @@ fn href_external() {
#[component]
fn Test() -> Element {
todo!()
unimplemented!()
}
#[component]
@ -129,7 +129,7 @@ fn with_class() {
#[component]
fn Test() -> Element {
todo!()
unimplemented!()
}
#[component]
@ -195,7 +195,7 @@ fn with_active_class_inactive() {
#[component]
fn Test() -> Element {
todo!()
unimplemented!()
}
#[component]
@ -232,7 +232,7 @@ fn with_id() {
#[component]
fn Test() -> Element {
todo!()
unimplemented!()
}
#[component]
@ -268,7 +268,7 @@ fn with_new_tab() {
#[component]
fn Test() -> Element {
todo!()
unimplemented!()
}
#[component]
@ -334,7 +334,7 @@ fn with_rel() {
#[component]
fn Test() -> Element {
todo!()
unimplemented!()
}
#[component]

View file

@ -169,7 +169,7 @@ impl ToTokens for ElementAttrNamed {
dioxus_elements::events::#name(#tokens)
}
}
ElementAttrName::Custom(_) => todo!(),
ElementAttrName::Custom(_) => unreachable!("Handled elsewhere in the macro"),
},
_ => {
quote! { dioxus_elements::events::#value(#value) }
@ -338,7 +338,7 @@ impl ElementAttrValue {
}
})
}
_ => todo!(),
_ => unreachable!("Invalid combination of attributes"),
}
}
}

View file

@ -40,7 +40,7 @@ use syn::{
/// #[server(ReadPosts, "/api")]
/// pub async fn read_posts(how_many: u8, query: String) -> Result<Vec<Post>, ServerFnError> {
/// // do some work on the server to access the database
/// todo!()
/// # unimplemented!()
/// }
/// ```
///

View file

@ -35,7 +35,7 @@ fn Read() -> Element {
let _write = signal.write();
let _read = signal.read();
todo!()
unreachable!()
}
#[component]
@ -45,7 +45,7 @@ fn ReadMut() -> Element {
let _read = signal.read();
let _write = signal.write();
todo!()
unreachable!()
}
#[component]