Skip to content

Commit

Permalink
Implement From instead of Into for widgets
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Oct 12, 2022
1 parent e98d12c commit fd26202
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 63 deletions.
8 changes: 4 additions & 4 deletions pure/src/widget/button.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,14 @@ where
}
}

impl<'a, Message, Renderer> Into<Element<'a, Message, Renderer>>
for Button<'a, Message, Renderer>
impl<'a, Message, Renderer> From<Button<'a, Message, Renderer>>
for Element<'a, Message, Renderer>
where
Message: Clone + 'a,
Renderer: iced_native::Renderer + 'a,
Renderer::Theme: StyleSheet,
{
fn into(self) -> Element<'a, Message, Renderer> {
Element::new(self)
fn from(button: Button<'a, Message, Renderer>) -> Self {
Self::new(button)
}
}
12 changes: 7 additions & 5 deletions pure/src/widget/checkbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,16 @@ where
}
}

impl<'a, Message, Renderer> Into<Element<'a, Message, Renderer>>
for Checkbox<'a, Message, Renderer>
impl<'a, Message, Renderer> From<Checkbox<'a, Message, Renderer>>
for Element<'a, Message, Renderer>
where
Message: 'a,
Renderer: text::Renderer + 'a,
Renderer: 'a + text::Renderer,
Renderer::Theme: StyleSheet + widget::text::StyleSheet,
{
fn into(self) -> Element<'a, Message, Renderer> {
Element::new(self)
fn from(
checkbox: Checkbox<'a, Message, Renderer>,
) -> Element<'a, Message, Renderer> {
Element::new(checkbox)
}
}
8 changes: 4 additions & 4 deletions pure/src/widget/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,13 @@ where
}
}

impl<'a, Message, Renderer> Into<Element<'a, Message, Renderer>>
for Column<'a, Message, Renderer>
impl<'a, Message, Renderer> From<Column<'a, Message, Renderer>>
for Element<'a, Message, Renderer>
where
Message: 'a,
Renderer: iced_native::Renderer + 'a,
{
fn into(self) -> Element<'a, Message, Renderer> {
Element::new(self)
fn from(column: Column<'a, Message, Renderer>) -> Self {
Self::new(column)
}
}
11 changes: 5 additions & 6 deletions pure/src/widget/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ where
}
}

impl<'a, Message, Renderer, Handle> Into<Element<'a, Message, Renderer>>
for Image<Handle>
impl<'a, Message, Renderer, Handle> From<Image<Handle>>
for Element<'a, Message, Renderer>
where
Message: Clone + 'a,
Renderer: iced_native::image::Renderer<Handle = Handle> + 'a,
Renderer: iced_native::image::Renderer<Handle = Handle>,
Handle: Clone + Hash + 'a,
{
fn into(self) -> Element<'a, Message, Renderer> {
Element::new(self)
fn from(image: Image<Handle>) -> Element<'a, Message, Renderer> {
Element::new(image)
}
}
8 changes: 4 additions & 4 deletions pure/src/widget/pick_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,16 @@ where
}
}

impl<'a, T: 'a, Message, Renderer> Into<Element<'a, Message, Renderer>>
for PickList<'a, T, Message, Renderer>
impl<'a, T: 'a, Message, Renderer> From<PickList<'a, T, Message, Renderer>>
for Element<'a, Message, Renderer>
where
T: Clone + ToString + Eq + 'static,
[T]: ToOwned<Owned = Vec<T>>,
Message: 'a,
Renderer: text::Renderer + 'a,
Renderer::Theme: StyleSheet,
{
fn into(self) -> Element<'a, Message, Renderer> {
Element::new(self)
fn from(pick_list: PickList<'a, T, Message, Renderer>) -> Self {
Self::new(pick_list)
}
}
13 changes: 8 additions & 5 deletions pure/src/widget/progress_bar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,16 @@ where
}
}

impl<'a, Message, Renderer> Into<Element<'a, Message, Renderer>>
for ProgressBar<Renderer>
impl<'a, Message, Renderer> From<ProgressBar<Renderer>>
for Element<'a, Message, Renderer>
where
Renderer: iced_native::Renderer + 'a,
Message: 'a,
Renderer: 'a + iced_native::Renderer,
Renderer::Theme: StyleSheet,
{
fn into(self) -> Element<'a, Message, Renderer> {
Element::new(self)
fn from(
progress_bar: ProgressBar<Renderer>,
) -> Element<'a, Message, Renderer> {
Element::new(progress_bar)
}
}
10 changes: 5 additions & 5 deletions pure/src/widget/radio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ where
}
}

impl<'a, Message, Renderer> Into<Element<'a, Message, Renderer>>
for Radio<Message, Renderer>
impl<'a, Message, Renderer> From<Radio<Message, Renderer>>
for Element<'a, Message, Renderer>
where
Message: 'a + Clone,
Renderer: text::Renderer + 'a,
Renderer: 'a + text::Renderer,
Renderer::Theme: StyleSheet + widget::text::StyleSheet,
{
fn into(self) -> Element<'a, Message, Renderer> {
Element::new(self)
fn from(radio: Radio<Message, Renderer>) -> Element<'a, Message, Renderer> {
Element::new(radio)
}
}
8 changes: 4 additions & 4 deletions pure/src/widget/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,13 @@ where
}
}

impl<'a, Message, Renderer> Into<Element<'a, Message, Renderer>>
for Row<'a, Message, Renderer>
impl<'a, Message, Renderer> From<Row<'a, Message, Renderer>>
for Element<'a, Message, Renderer>
where
Message: 'a,
Renderer: iced_native::Renderer + 'a,
{
fn into(self) -> Element<'a, Message, Renderer> {
Element::new(self)
fn from(row: Row<'a, Message, Renderer>) -> Self {
Self::new(row)
}
}
11 changes: 6 additions & 5 deletions pure/src/widget/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ where
}
}

impl<'a, Message, Renderer> Into<Element<'a, Message, Renderer>>
for Rule<Renderer>
impl<'a, Message, Renderer> From<Rule<Renderer>>
for Element<'a, Message, Renderer>
where
Renderer: iced_native::Renderer + 'a,
Message: 'a,
Renderer: 'a + iced_native::Renderer,
Renderer::Theme: StyleSheet,
{
fn into(self) -> Element<'a, Message, Renderer> {
Element::new(self)
fn from(rule: Rule<Renderer>) -> Element<'a, Message, Renderer> {
Element::new(rule)
}
}
9 changes: 5 additions & 4 deletions pure/src/widget/space.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,12 @@ where
}
}

impl<'a, Message, Renderer> Into<Element<'a, Message, Renderer>> for Space
impl<'a, Message, Renderer> From<Space> for Element<'a, Message, Renderer>
where
Renderer: iced_native::Renderer + 'a,
Renderer: iced_native::Renderer,
Message: 'a,
{
fn into(self) -> Element<'a, Message, Renderer> {
Element::new(self)
fn from(space: Space) -> Element<'a, Message, Renderer> {
Element::new(space)
}
}
9 changes: 4 additions & 5 deletions pure/src/widget/svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,11 @@ where
}
}

impl<'a, Message, Renderer> Into<Element<'a, Message, Renderer>> for Svg
impl<'a, Message, Renderer> From<Svg> for Element<'a, Message, Renderer>
where
Message: Clone + 'a,
Renderer: iced_native::svg::Renderer + 'a,
Renderer: iced_native::svg::Renderer,
{
fn into(self) -> Element<'a, Message, Renderer> {
Element::new(self)
fn from(icon: Svg) -> Element<'a, Message, Renderer> {
Element::new(icon)
}
}
14 changes: 7 additions & 7 deletions pure/src/widget/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,23 @@ where
}
}

impl<'a, Message, Renderer> Into<Element<'a, Message, Renderer>>
for Text<Renderer>
impl<'a, Message, Renderer> From<Text<Renderer>>
for Element<'a, Message, Renderer>
where
Renderer: text::Renderer + 'a,
Renderer::Theme: widget::text::StyleSheet,
{
fn into(self) -> Element<'a, Message, Renderer> {
Element::new(self)
fn from(text: Text<Renderer>) -> Self {
Self::new(text)
}
}

impl<'a, Message, Renderer> Into<Element<'a, Message, Renderer>> for &'a str
impl<'a, Message, Renderer> From<&'a str> for Element<'a, Message, Renderer>
where
Renderer: text::Renderer + 'a,
Renderer::Theme: widget::text::StyleSheet,
{
fn into(self) -> Element<'a, Message, Renderer> {
Text::new(self).into()
fn from(content: &'a str) -> Self {
Element::from(Text::new(content))
}
}
12 changes: 7 additions & 5 deletions pure/src/widget/toggler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,16 @@ where
}
}

impl<'a, Message, Renderer> Into<Element<'a, Message, Renderer>>
for Toggler<'a, Message, Renderer>
impl<'a, Message, Renderer> From<Toggler<'a, Message, Renderer>>
for Element<'a, Message, Renderer>
where
Message: 'a,
Renderer: text::Renderer + 'a,
Renderer: 'a + text::Renderer,
Renderer::Theme: StyleSheet + widget::text::StyleSheet,
{
fn into(self) -> Element<'a, Message, Renderer> {
Element::new(self)
fn from(
toggler: Toggler<'a, Message, Renderer>,
) -> Element<'a, Message, Renderer> {
Element::new(toggler)
}
}

0 comments on commit fd26202

Please sign in to comment.