Fix Message type to Never in UpdateFn for ()

This commit is contained in:
Héctor Ramón Jiménez 2025-12-07 01:42:42 +01:00
parent 92d08bcc10
commit 31fcaccf7d
No known key found for this signature in database
GPG key ID: 7CC46565708259A7
4 changed files with 11 additions and 9 deletions

View file

@ -85,13 +85,14 @@ pub use widget::Widget;
pub use bytes::Bytes; pub use bytes::Bytes;
pub use smol_str::SmolStr; pub use smol_str::SmolStr;
pub use std::convert::Infallible as Never;
/// A function that can _never_ be called. /// A function that can _never_ be called.
/// ///
/// This is useful to turn generic types into anything /// This is useful to turn generic types into anything
/// you want by coercing them into a type with no possible /// you want by coercing them into a type with no possible
/// values. /// values.
pub fn never<T>(never: std::convert::Infallible) -> T { pub fn never<T>(never: Never) -> T {
match never {} match never {}
} }

View file

@ -169,15 +169,15 @@ mod rainbow {
} }
} }
use iced::Element;
use iced::widget::{center_x, center_y, column, scrollable}; use iced::widget::{center_x, center_y, column, scrollable};
use iced::{Element, Never};
use rainbow::rainbow; use rainbow::rainbow;
pub fn main() -> iced::Result { pub fn main() -> iced::Result {
iced::run((), view) iced::run((), view)
} }
fn view(_state: &()) -> Element<'_, ()> { fn view(_state: &()) -> Element<'_, Never> {
let content = column![ let content = column![
rainbow(), rainbow(),
"In this example we draw a custom widget Rainbow, using \ "In this example we draw a custom widget Rainbow, using \

View file

@ -36,8 +36,8 @@ use crate::shell;
use crate::theme; use crate::theme;
use crate::window; use crate::window;
use crate::{ use crate::{
Element, Executor, Font, Preset, Result, Settings, Size, Subscription, Element, Executor, Font, Never, Preset, Result, Settings, Size,
Task, Theme, Subscription, Task, Theme,
}; };
use iced_debug as debug; use iced_debug as debug;
@ -600,8 +600,8 @@ pub trait UpdateFn<State, Message> {
fn update(&self, state: &mut State, message: Message) -> Task<Message>; fn update(&self, state: &mut State, message: Message) -> Task<Message>;
} }
impl<State, Message> UpdateFn<State, Message> for () { impl<State> UpdateFn<State, Never> for () {
fn update(&self, _state: &mut State, _message: Message) -> Task<Message> { fn update(&self, _state: &mut State, _message: Never) -> Task<Never> {
Task::none() Task::none()
} }
} }

View file

@ -533,8 +533,9 @@ pub use crate::core::padding;
pub use crate::core::theme; pub use crate::core::theme;
pub use crate::core::{ pub use crate::core::{
Alignment, Animation, Background, Border, Color, ContentFit, Degrees, Alignment, Animation, Background, Border, Color, ContentFit, Degrees,
Function, Gradient, Length, Padding, Pixels, Point, Radians, Rectangle, Function, Gradient, Length, Never, Padding, Pixels, Point, Radians,
Rotation, Settings, Shadow, Size, Theme, Transformation, Vector, never, Rectangle, Rotation, Settings, Shadow, Size, Theme, Transformation, Vector,
never,
}; };
pub use crate::program::Preset; pub use crate::program::Preset;
pub use crate::program::message; pub use crate::program::message;