Introduce state lifetime for style_sheet in Rule

This commit is contained in:
Héctor Ramón Jiménez 2021-10-31 17:34:58 +07:00
parent bd7b086ec1
commit 48490c3d87
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
2 changed files with 9 additions and 9 deletions

View file

@ -12,14 +12,14 @@ pub use iced_style::rule::{FillMode, Style, StyleSheet};
/// Display a horizontal or vertical rule for dividing content. /// Display a horizontal or vertical rule for dividing content.
#[allow(missing_debug_implementations)] #[allow(missing_debug_implementations)]
pub struct Rule { pub struct Rule<'a> {
width: Length, width: Length,
height: Length, height: Length,
is_horizontal: bool, is_horizontal: bool,
style_sheet: Box<dyn StyleSheet>, style_sheet: Box<dyn StyleSheet + 'a>,
} }
impl Rule { impl<'a> Rule<'a> {
/// Creates a horizontal [`Rule`] for dividing content by the given vertical spacing. /// Creates a horizontal [`Rule`] for dividing content by the given vertical spacing.
pub fn horizontal(spacing: u16) -> Self { pub fn horizontal(spacing: u16) -> Self {
Rule { Rule {
@ -43,14 +43,14 @@ impl Rule {
/// Sets the style of the [`Rule`]. /// Sets the style of the [`Rule`].
pub fn style( pub fn style(
mut self, mut self,
style_sheet: impl Into<Box<dyn StyleSheet>>, style_sheet: impl Into<Box<dyn StyleSheet + 'a>>,
) -> Self { ) -> Self {
self.style_sheet = style_sheet.into(); self.style_sheet = style_sheet.into();
self self
} }
} }
impl<Message, Renderer> Widget<Message, Renderer> for Rule impl<'a, Message, Renderer> Widget<Message, Renderer> for Rule<'a>
where where
Renderer: crate::Renderer, Renderer: crate::Renderer,
{ {
@ -131,12 +131,12 @@ where
} }
} }
impl<'a, Message, Renderer> From<Rule> for Element<'a, Message, Renderer> impl<'a, Message, Renderer> From<Rule<'a>> for Element<'a, Message, Renderer>
where where
Renderer: 'a + crate::Renderer, Renderer: 'a + crate::Renderer,
Message: 'a, Message: 'a,
{ {
fn from(rule: Rule) -> Element<'a, Message, Renderer> { fn from(rule: Rule<'a>) -> Element<'a, Message, Renderer> {
Element::new(rule) Element::new(rule)
} }
} }

View file

@ -110,9 +110,9 @@ impl std::default::Default for Box<dyn StyleSheet> {
} }
} }
impl<T> From<T> for Box<dyn StyleSheet> impl<'a, T> From<T> for Box<dyn StyleSheet + 'a>
where where
T: 'static + StyleSheet, T: 'a + StyleSheet,
{ {
fn from(style: T) -> Self { fn from(style: T) -> Self {
Box::new(style) Box::new(style)