Skip to content

Commit 41207ef

Browse files
DJMcNabxStrom
andauthored
Make Xilem Views must_use (#742)
Also fixes `unused_qualifications` as an easy fix. --------- Co-authored-by: Kaur Kuut <[email protected]>
1 parent 751bd62 commit 41207ef

24 files changed

+37
-23
lines changed

xilem/src/driver.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,10 @@ type MessagePackage = (Arc<[ViewId]>, DynMessage);
3333

3434
impl RawProxy for MasonryProxy {
3535
fn send_message(&self, path: Arc<[ViewId]>, message: DynMessage) -> Result<(), ProxyError> {
36-
match self
37-
.0
38-
.send_event(event_loop_runner::MasonryUserEvent::Action(
39-
async_action(path, message),
40-
ASYNC_MARKER_WIDGET,
41-
)) {
36+
match self.0.send_event(MasonryUserEvent::Action(
37+
async_action(path, message),
38+
ASYNC_MARKER_WIDGET,
39+
)) {
4240
Ok(()) => Ok(()),
4341
Err(err) => {
4442
let MasonryUserEvent::Action(masonry::Action::Other(res), _) = err.0 else {
@@ -74,7 +72,7 @@ where
7472
fn on_action(
7573
&mut self,
7674
masonry_ctx: &mut masonry::DriverCtx<'_>,
77-
widget_id: masonry::WidgetId,
75+
widget_id: WidgetId,
7876
action: masonry::Action,
7977
) {
8078
let message_result = if widget_id == ASYNC_MARKER_WIDGET {

xilem/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,13 @@
1818
)]
1919
// TODO: Remove any items listed as "Deferred"
2020
#![cfg_attr(not(debug_assertions), allow(unused))]
21-
#![expect(missing_debug_implementations, reason = "Deferred: Noisy")]
22-
#![expect(unused_qualifications, reason = "Deferred: Noisy")]
21+
#![expect(
22+
missing_debug_implementations,
23+
reason = "Deferred: Noisy. Requires same lint to be addressed in Masonry"
24+
)]
2325
#![expect(clippy::exhaustive_enums, reason = "Deferred: Noisy")]
2426
#![expect(clippy::match_same_arms, reason = "Deferred: Noisy")]
2527
#![expect(clippy::missing_assert_message, reason = "Deferred: Noisy")]
26-
#![expect(clippy::return_self_not_must_use, reason = "Deferred: Noisy")]
2728
#![expect(elided_lifetimes_in_paths, reason = "Deferred: Noisy")]
2829
#![expect(clippy::use_self, reason = "Deferred: Noisy")]
2930
// https://github.com/rust-lang/rust/pull/130025
@@ -65,6 +66,7 @@ pub mod view;
6566
pub use any_view::AnyWidgetView;
6667
pub use driver::{async_action, MasonryDriver, MasonryProxy, ASYNC_MARKER_WIDGET};
6768

69+
#[must_use = "A Xilem app does nothing unless ran."]
6870
pub struct Xilem<State, Logic> {
6971
state: State,
7072
logic: Logic,

xilem/src/view/button.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub fn button_any_pointer<State, Action>(
3535
}
3636
}
3737

38+
#[must_use = "View values do nothing unless provided to Xilem."]
3839
pub struct Button<F> {
3940
label: ArcStr,
4041
callback: F,

xilem/src/view/checkbox.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ where
2222
}
2323
}
2424

25+
#[must_use = "View values do nothing unless provided to Xilem."]
2526
pub struct Checkbox<F> {
2627
label: ArcStr,
2728
checked: bool,
@@ -38,10 +39,7 @@ where
3839

3940
fn build(&self, ctx: &mut ViewCtx) -> (Self::Element, Self::ViewState) {
4041
ctx.with_leaf_action_widget(|ctx| {
41-
ctx.new_pod(masonry::widget::Checkbox::new(
42-
self.checked,
43-
self.label.clone(),
44-
))
42+
ctx.new_pod(widget::Checkbox::new(self.checked, self.label.clone()))
4543
})
4644
}
4745

xilem/src/view/flex.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ pub fn flex<State, Action, Seq: FlexSequence<State, Action>>(
2727
}
2828
}
2929

30+
#[must_use = "View values do nothing unless provided to Xilem."]
3031
pub struct Flex<Seq, State, Action = ()> {
3132
sequence: Seq,
3233
axis: Axis,

xilem/src/view/grid.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn grid<State, Action, Seq: GridSequence<State, Action>>(
2626
}
2727
}
2828

29+
#[must_use = "View values do nothing unless provided to Xilem."]
2930
pub struct Grid<Seq, State, Action = ()> {
3031
sequence: Seq,
3132
spacing: f64,

xilem/src/view/image.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ pub fn image(image: &vello::peniko::Image) -> Image {
3131
/// The [`View`] created by [`image`].
3232
///
3333
/// See `image`'s docs for more details.
34+
#[must_use = "View values do nothing unless provided to Xilem."]
3435
pub struct Image {
3536
image: vello::peniko::Image,
3637
object_fit: ObjectFit,

xilem/src/view/label.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ pub fn label(label: impl Into<ArcStr>) -> Label {
1717
}
1818
}
1919

20+
#[must_use = "View values do nothing unless provided to Xilem."]
2021
pub struct Label {
2122
label: ArcStr,
2223

@@ -99,7 +100,7 @@ impl<State, Action> View<State, Action, ViewCtx> for Label {
99100
_id_path: &[ViewId],
100101
message: DynMessage,
101102
_app_state: &mut State,
102-
) -> crate::MessageResult<Action> {
103+
) -> MessageResult<Action> {
103104
tracing::error!("Message arrived in Label::message, but Label doesn't consume any messages, this is a bug");
104105
MessageResult::Stale(message)
105106
}

xilem/src/view/portal.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ where
2121
}
2222
}
2323

24+
#[must_use = "View values do nothing unless provided to Xilem."]
2425
pub struct Portal<V, State, Action> {
2526
child: V,
2627
phantom: PhantomData<(State, Action)>,

xilem/src/view/progress_bar.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ impl<State, Action> View<State, Action, ViewCtx> for ProgressBar {
2020
type ViewState = ();
2121

2222
fn build(&self, ctx: &mut ViewCtx) -> (Self::Element, Self::ViewState) {
23-
ctx.with_leaf_action_widget(|ctx| {
24-
ctx.new_pod(masonry::widget::ProgressBar::new(self.progress))
25-
})
23+
ctx.with_leaf_action_widget(|ctx| ctx.new_pod(widget::ProgressBar::new(self.progress)))
2624
}
2725

2826
fn rebuild(

0 commit comments

Comments
 (0)