Skip to content

Commit

Permalink
Hide Box allocation in component::view
Browse files Browse the repository at this point in the history
... we may be able to avoid it with generics in the future.
  • Loading branch information
hecrj committed Nov 29, 2021
1 parent 010b62b commit f7792d8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion examples/component/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ mod numeric_input {
Renderer: text::Renderer + 'a,
{
fn from(numeric_input: NumericInput<'a, Message>) -> Self {
component::view(Box::new(numeric_input))
component::view(numeric_input)
}
}
}
8 changes: 4 additions & 4 deletions lazy/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ use iced_native::{
use ouroboros::self_referencing;
use std::marker::PhantomData;

pub fn view<'a, Event, Message, Renderer>(
component: Box<dyn Component<Message, Renderer, Event = Event> + 'a>,
pub fn view<'a, C, Message, Renderer>(
component: C,
) -> Element<'a, Message, Renderer>
where
C: Component<Message, Renderer> + 'a,
Message: 'a,
Event: 'a,
Renderer: iced_native::Renderer + 'a,
{
Element::new(Instance {
state: Some(
StateBuilder {
component,
component: Box::new(component),
cache_builder: |state| Cache {
element: state.view(),
message: PhantomData,
Expand Down

0 comments on commit f7792d8

Please sign in to comment.