Skip to content

Commit

Permalink
deny bare_trait_objects
Browse files Browse the repository at this point in the history
  • Loading branch information
chpio committed Aug 22, 2018
1 parent 8de5182 commit eda346f
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 29 deletions.
18 changes: 9 additions & 9 deletions src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl HandlerId {
/// This traits allow to get addres or register worker.
pub trait Bridged: Agent + Sized + 'static {
/// Creates a messaging bridge between a worker and the component.
fn bridge(callback: Callback<Self::Output>) -> Box<Bridge<Self>>;
fn bridge(callback: Callback<Self::Output>) -> Box<dyn Bridge<Self>>;
}

/// Implements rules to register a worker in a separate thread.
Expand Down Expand Up @@ -144,7 +144,7 @@ impl<T> Bridged for T
where
T: Agent,
{
fn bridge(callback: Callback<Self::Output>) -> Box<Bridge<Self>> {
fn bridge(callback: Callback<Self::Output>) -> Box<dyn Bridge<Self>> {
Self::Reach::spawn_or_join(callback)
}
}
Expand All @@ -153,7 +153,7 @@ where
#[doc(hidden)]
pub trait Discoverer {
/// Spawns an agent and returns `Bridge` implementation.
fn spawn_or_join<AGN: Agent>(_callback: Callback<AGN::Output>) -> Box<Bridge<AGN>> {
fn spawn_or_join<AGN: Agent>(_callback: Callback<AGN::Output>) -> Box<dyn Bridge<AGN>> {
unimplemented!();
}
}
Expand Down Expand Up @@ -209,7 +209,7 @@ thread_local! {
pub struct Context;

impl Discoverer for Context {
fn spawn_or_join<AGN: Agent>(callback: Callback<AGN::Output>) -> Box<Bridge<AGN>> {
fn spawn_or_join<AGN: Agent>(callback: Callback<AGN::Output>) -> Box<dyn Bridge<AGN>> {
let mut scope_to_init = None;
let bridge = LOCAL_AGENTS_POOL.with(|pool| {
match pool.borrow_mut().entry::<LocalAgent<AGN>>() {
Expand Down Expand Up @@ -289,7 +289,7 @@ impl<AGN: Agent> Drop for ContextBridge<AGN> {
pub struct Job;

impl Discoverer for Job {
fn spawn_or_join<AGN: Agent>(callback: Callback<AGN::Output>) -> Box<Bridge<AGN>> {
fn spawn_or_join<AGN: Agent>(callback: Callback<AGN::Output>) -> Box<dyn Bridge<AGN>> {
let scope = AgentScope::<AGN>::new();
let responder = CallbackResponder { callback };
let agent_link = AgentLink::connect(&scope, responder);
Expand Down Expand Up @@ -341,7 +341,7 @@ impl<AGN: Agent> Drop for JobBridge<AGN> {
pub struct Private;

impl Discoverer for Private {
fn spawn_or_join<AGN: Agent>(callback: Callback<AGN::Output>) -> Box<Bridge<AGN>> {
fn spawn_or_join<AGN: Agent>(callback: Callback<AGN::Output>) -> Box<dyn Bridge<AGN>> {
let handler = move |data: Vec<u8>| {
let msg = FromWorker::<AGN::Output>::unpack(&data);
match msg {
Expand Down Expand Up @@ -436,7 +436,7 @@ thread_local! {
pub struct Public;

impl Discoverer for Public {
fn spawn_or_join<AGN: Agent>(callback: Callback<AGN::Output>) -> Box<Bridge<AGN>> {
fn spawn_or_join<AGN: Agent>(callback: Callback<AGN::Output>) -> Box<dyn Bridge<AGN>> {
let bridge = REMOTE_AGENTS_POOL.with(|pool| {
match pool.borrow_mut().entry::<RemoteAgent<AGN>>() {
Entry::Occupied(mut entry) => {
Expand Down Expand Up @@ -598,7 +598,7 @@ impl<AGN: Agent> AgentScope<AGN> {
shared_agent: self.shared_agent.clone(),
message: Some(update),
};
let runnable: Box<Runnable> = Box::new(envelope);
let runnable: Box<dyn Runnable> = Box::new(envelope);
scheduler().put_and_try_run(runnable);
}
}
Expand All @@ -624,7 +624,7 @@ impl<AGN: Agent> Responder<AGN> for WorkerResponder {
/// Link to agent's scope for creating callbacks.
pub struct AgentLink<AGN: Agent> {
scope: AgentScope<AGN>,
responder: Box<Responder<AGN>>,
responder: Box<dyn Responder<AGN>>,
}

impl<AGN: Agent> AgentLink<AGN> {
Expand Down
2 changes: 1 addition & 1 deletion src/callback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::rc::Rc;
/// </aside>
/// `Rc` wrapper used to make it clonable.
#[must_use]
pub struct Callback<IN>(Rc<Fn(IN)>);
pub struct Callback<IN>(Rc<dyn Fn(IN)>);

impl<IN, F: Fn(IN) + 'static> From<F> for Callback<IN> {
fn from(func: F) -> Self {
Expand Down
2 changes: 1 addition & 1 deletion src/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ where
shared_component: self.shared_component.clone(),
message: Some(update),
};
let runnable: Box<Runnable> = Box::new(envelope);
let runnable: Box<dyn Runnable> = Box::new(envelope);
scheduler().put_and_try_run(runnable);
}

Expand Down
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
//! #[macro_use]
//! extern crate yew;
//! use yew::prelude::*;
//!
//!
//! struct Model {
//! value: i64,
//! }
//!
//!
//! enum Msg {
//! DoIt,
//! }
//!
//!
//! impl Component for Model {
//! type Message = Msg;
//! type Properties = ();
Expand All @@ -28,15 +28,15 @@
//! value: 0,
//! }
//! }
//!
//!
//! fn update(&mut self, msg: Self::Message) -> ShouldRender {
//! match msg {
//! Msg::DoIt => self.value = self.value + 1
//! }
//! true
//! }
//! }
//!
//!
//! impl Renderable<Model> for Model {
//! fn view(&self) -> Html<Self> {
//! html! {
Expand All @@ -47,7 +47,7 @@
//! }
//! }
//! }
//!
//!
//! fn main() {
//! yew::initialize();
//! App::<Model>::new().mount_to_body();
Expand All @@ -56,7 +56,7 @@
//! ```
//!
#![deny(missing_docs)]
#![deny(missing_docs, bare_trait_objects)]
#![recursion_limit = "512"]

#[macro_use]
Expand Down
2 changes: 1 addition & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ pub fn set_classes<COMP: Component, T: AsRef<str>>(stack: &mut Stack<COMP>, clas
#[doc(hidden)]
pub fn attach_listener<COMP: Component>(
stack: &mut Stack<COMP>,
listener: Box<Listener<COMP>>,
listener: Box<dyn Listener<COMP>>,
) {
if let Some(&mut VNode::VTag(ref mut vtag)) = stack.last_mut() {
vtag.add_listener(listener);
Expand Down
4 changes: 2 additions & 2 deletions src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub(crate) trait Runnable {
/// This is a global scheduler suitable to schedule and run any tasks.
pub(crate) struct Scheduler {
lock: Rc<AtomicBool>,
sequence: Shared<VecDeque<Box<Runnable>>>,
sequence: Shared<VecDeque<Box<dyn Runnable>>>,
}

impl Clone for Scheduler {
Expand All @@ -46,7 +46,7 @@ impl Scheduler {
}
}

pub(crate) fn put_and_try_run(&self, runnable: Box<Runnable>) {
pub(crate) fn put_and_try_run(&self, runnable: Box<dyn Runnable>) {
self.sequence.borrow_mut().push_back(runnable);
if self.lock.compare_and_swap(false, true, Ordering::Relaxed) == false {
loop {
Expand Down
4 changes: 2 additions & 2 deletions src/virtual_dom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ pub trait Listener<COMP: Component> {
fn attach(&mut self, element: &Element, scope: Scope<COMP>) -> EventListenerHandle;
}

impl<COMP: Component> fmt::Debug for Listener<COMP> {
impl<COMP: Component> fmt::Debug for dyn Listener<COMP> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "Listener {{ kind: {} }}", self.kind())
}
}

/// A list of event listeners.
type Listeners<COMP> = Vec<Box<Listener<COMP>>>;
type Listeners<COMP> = Vec<Box<dyn Listener<COMP>>>;

/// A map of attributes.
type Attributes = HashMap<String, String>;
Expand Down
6 changes: 3 additions & 3 deletions src/virtual_dom/vcomp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use Hidden;
type AnyProps = (TypeId, *mut Hidden);

/// The method generates an instance of a (child) component.
type Generator = FnMut(Element, Option<Node>, AnyProps);
type Generator = dyn FnMut(Element, Option<Node>, AnyProps);

/// A reference to unknown activator which will be attached later with a generator function.
type LazyActivator<COMP> = Rc<RefCell<Option<Scope<COMP>>>>;
Expand All @@ -24,10 +24,10 @@ pub struct VComp<COMP: Component> {
type_id: TypeId,
cell: NodeCell,
props: Option<(TypeId, *mut Hidden)>,
blind_sender: Box<FnMut(AnyProps)>,
blind_sender: Box<dyn FnMut(AnyProps)>,
generator: Box<Generator>,
activators: Vec<LazyActivator<COMP>>,
destroyer: Box<Fn()>,
destroyer: Box<dyn Fn()>,
_parent: PhantomData<COMP>,
}

Expand Down
4 changes: 2 additions & 2 deletions src/virtual_dom/vnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ impl<COMP: Component, T: ToString> From<T> for VNode<COMP> {
}
}

impl<'a, COMP: Component> From<&'a Renderable<COMP>> for VNode<COMP> {
fn from(value: &'a Renderable<COMP>) -> Self {
impl<'a, COMP: Component> From<&'a dyn Renderable<COMP>> for VNode<COMP> {
fn from(value: &'a dyn Renderable<COMP>) -> Self {
value.view()
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/virtual_dom/vtag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl<COMP: Component> VTag<COMP> {
/// Adds new listener to the node.
/// It's boxed because we want to keep it in a single list.
/// Lates `Listener::attach` called to attach actual listener to a DOM node.
pub fn add_listener(&mut self, listener: Box<Listener<COMP>>) {
pub fn add_listener(&mut self, listener: Box<dyn Listener<COMP>>) {
self.listeners.push(listener);
}

Expand Down

0 comments on commit eda346f

Please sign in to comment.