Skip to content

Commit

Permalink
omit a drop impl
Browse files Browse the repository at this point in the history
this should shave some size from BaseComponent::create
  • Loading branch information
WorldSEnder committed May 15, 2022
1 parent 5dd862a commit 9deac03
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion examples/light_switch/src/main.rs
Expand Up @@ -35,7 +35,7 @@ impl ComponentWithRef for Light {
type Properties = ();
type Reference = Scope<Self>;

fn create(ctx: &Context<Self>, bindable_ref: BindableRef<Self::Reference>) -> Self {
fn create(ctx: &Context<Self>, bindable_ref: BindableRef<'_, Self::Reference>) -> Self {
bindable_ref.bind(ctx.link().clone());
Light { is_on: false }
}
Expand Down
2 changes: 1 addition & 1 deletion examples/nested_list/src/list.rs
Expand Up @@ -71,7 +71,7 @@ impl ComponentWithRef for List {
type Properties = Props;
type Reference = Scope<Self>;

fn create(ctx: &Context<Self>, bindable_ref: BindableRef<Self::Reference>) -> Self {
fn create(ctx: &Context<Self>, bindable_ref: BindableRef<'_, Self::Reference>) -> Self {
bindable_ref.bind(ctx.link().clone());
Self { inactive: false }
}
Expand Down
2 changes: 1 addition & 1 deletion packages/yew/src/dom_bundle/bcomp.rs
Expand Up @@ -201,7 +201,7 @@ mod tests {
type Properties = Props;
type Reference = ();

fn create(_: &Context<Self>, bindable_ref: BindableRef<()>) -> Self {
fn create(_: &Context<Self>, bindable_ref: BindableRef<'_, ()>) -> Self {
bindable_ref.bind(());
Comp
}
Expand Down
14 changes: 7 additions & 7 deletions packages/yew/src/functional/mod.rs
Expand Up @@ -72,7 +72,6 @@ pub(crate) trait Effect {
pub struct HookContext {
pub(crate) scope: AnyScope,
re_render: ReRender,
comp_ref: ErasedHtmlRef,

states: Vec<Rc<dyn Any>>,
effects: Vec<Rc<dyn Effect>>,
Expand All @@ -83,13 +82,12 @@ pub struct HookContext {
}

impl HookContext {
fn new(scope: AnyScope, re_render: ReRender, comp_ref: ErasedHtmlRef) -> RefCell<Self> {
fn new(scope: AnyScope, re_render: ReRender) -> RefCell<Self> {
RefCell::new(HookContext {
effects: Vec::new(),
scope,
re_render,
states: Vec::new(),
comp_ref,

counter: 0,
#[cfg(debug_assertions)]
Expand Down Expand Up @@ -202,7 +200,7 @@ pub trait FunctionProvider: BaseComponent<Message = ()> {
fn run(
ctx: &mut HookContext,
props: &Self::Properties,
bindable_ref: BindableRef<Self::Reference>,
bindable_ref: BindableRef<'_, Self::Reference>,
) -> HtmlResult;
}

Expand All @@ -218,14 +216,15 @@ pub trait FunctionProvider: BaseComponent<Message = ()> {
pub struct FunctionComponent<T> {
_never: std::marker::PhantomData<T>,
hook_ctx: RefCell<HookContext>,
bindable_ref: ErasedHtmlRef,
}

impl<T> FunctionComponent<T>
where
T: FunctionProvider,
{
/// Creates a new function component.
pub fn new(ctx: &Context<T>, bindable_ref: BindableRef<T::Reference>) -> Self {
pub fn new(ctx: &Context<T>, bindable_ref: BindableRef<'_, T::Reference>) -> Self {
let scope = AnyScope::from(ctx.link().clone());
let re_render = {
let link = ctx.link().clone();
Expand All @@ -235,7 +234,8 @@ where

Self {
_never: std::marker::PhantomData::default(),
hook_ctx: HookContext::new(scope, re_render, bindable_ref.forward().to_erased()),
hook_ctx: HookContext::new(scope, re_render),
bindable_ref: bindable_ref.forward().to_erased(),
}
}

Expand All @@ -245,7 +245,7 @@ where

hook_ctx.prepare_run();

let bindable_ref = BindableRef::for_ref(&hook_ctx.comp_ref);
let bindable_ref = BindableRef::for_ref(&self.bindable_ref);
#[allow(clippy::let_and_return)]
let result = T::run(&mut *hook_ctx, props, bindable_ref);

Expand Down
8 changes: 4 additions & 4 deletions packages/yew/src/html/component/mod.rs
Expand Up @@ -114,7 +114,7 @@ pub trait BaseComponent: Sized + 'static {
type Reference: 'static;

/// Creates a component.
fn create(ctx: &Context<Self>, bindable_ref: BindableRef<Self::Reference>) -> Self;
fn create(ctx: &Context<Self>, bindable_ref: BindableRef<'_, Self::Reference>) -> Self;

/// Updates component's internal state.
fn update(&mut self, ctx: &Context<Self>, msg: Self::Message) -> bool;
Expand Down Expand Up @@ -147,7 +147,7 @@ pub trait ComponentWithRef: Sized + 'static {
type Reference: 'static;

/// Creates a component.
fn create(ctx: &Context<Self>, bindable_ref: BindableRef<Self::Reference>) -> Self;
fn create(ctx: &Context<Self>, bindable_ref: BindableRef<'_, Self::Reference>) -> Self;

/// Updates component's internal state.
#[allow(unused_variables)]
Expand Down Expand Up @@ -243,7 +243,7 @@ where
type Properties = <T as Component>::Properties;
type Reference = NoReference;

fn create(ctx: &Context<Self>, bindable_ref: BindableRef<NoReference>) -> Self {
fn create(ctx: &Context<Self>, bindable_ref: BindableRef<'_, NoReference>) -> Self {
bindable_ref.fake_bind();
Component::create(ctx)
}
Expand Down Expand Up @@ -277,7 +277,7 @@ where
type Properties = <T as ComponentWithRef>::Properties;
type Reference = <T as ComponentWithRef>::Reference;

fn create(ctx: &Context<Self>, bindable_ref: BindableRef<Self::Reference>) -> Self {
fn create(ctx: &Context<Self>, bindable_ref: BindableRef<'_, Self::Reference>) -> Self {
ComponentWithRef::create(ctx, bindable_ref)
}

Expand Down
14 changes: 7 additions & 7 deletions packages/yew/src/html/html_ref.rs
Expand Up @@ -31,7 +31,7 @@ pub enum NoReference {}
/// type Properties = ();
/// type Reference = Scope<Self>;
///
/// fn create(ctx: &Context<Self>, bindable_ref: BindableRef<Self::Reference>) -> Self {
/// fn create(ctx: &Context<Self>, bindable_ref: BindableRef<'_, Self::Reference>) -> Self {
/// bindable_ref.bind(ctx.link().clone());
/// Self {
/// msg: "waiting...".to_string(),
Expand Down Expand Up @@ -302,15 +302,15 @@ impl NodeRef {

/// A ref that can be bound to. See also [`Component::bind_ref`].
#[derive(Debug)]
pub struct BindableRef<T> {
inner: ErasedHtmlRef,
pub struct BindableRef<'b, T> {
inner: &'b ErasedHtmlRef,
_phantom: PhantomData<T>,
}

impl<T: 'static> BindableRef<T> {
pub(crate) fn for_ref(inner: &ErasedHtmlRef) -> Self {
impl<'b, T: 'static> BindableRef<'b, T> {
pub(crate) fn for_ref(inner: &'b ErasedHtmlRef) -> Self {
Self {
inner: inner.clone(),
inner,
_phantom: PhantomData,
}
}
Expand All @@ -336,7 +336,7 @@ impl<T: 'static> BindableRef<T> {
}

#[doc(hidden)]
impl BindableRef<NoReference> {
impl<'r> BindableRef<'r, NoReference> {
pub fn fake_bind(self) {
let this = self.inner;
this.debug_assert_internal_type::<NoReference>();
Expand Down

0 comments on commit 9deac03

Please sign in to comment.