From e19ec021db4661282b6b36543b8939935917448e Mon Sep 17 00:00:00 2001 From: Henry Zimmerman Date: Sun, 13 Oct 2019 19:47:56 -0400 Subject: [PATCH] Forbid missing Debug implementations (#673) * Forbid missing debug implementations * someday I'll remember to run cargo fmt before pushing the first time * add debug for other format types * derive debug for HandlerId --- src/agent.rs | 29 ++++++++++++++++++++++++++--- src/app.rs | 1 + src/components/select.rs | 4 +++- src/format/cbor.rs | 1 + src/format/json.rs | 1 + src/format/msgpack.rs | 1 + src/format/nothing.rs | 1 + src/format/toml.rs | 1 + src/format/yaml.rs | 1 + src/html/listener.rs | 1 + src/html/mod.rs | 1 + src/html/scope.rs | 6 ++++++ src/lib.rs | 1 + src/services/console.rs | 2 +- src/services/dialog.rs | 2 +- src/services/fetch.rs | 19 +++++++++++++------ src/services/interval.rs | 9 ++++++++- src/services/keyboard.rs | 8 ++++++++ src/services/reader.rs | 9 ++++++++- src/services/render.rs | 9 ++++++++- src/services/resize.rs | 10 +++++++++- src/services/storage.rs | 8 ++++++++ src/services/timeout.rs | 9 ++++++++- src/services/websocket.rs | 11 +++++++++-- src/virtual_dom/vcomp.rs | 13 +++++++++++++ src/virtual_dom/vlist.rs | 1 + 26 files changed, 140 insertions(+), 19 deletions(-) diff --git a/src/agent.rs b/src/agent.rs index b5f595e782a..421b93b7858 100644 --- a/src/agent.rs +++ b/src/agent.rs @@ -52,7 +52,7 @@ impl Deserialize<'de>> Packed for T { type SharedOutputSlab = Shared::Output>>>>; /// Id of responses handler. -#[derive(Serialize, Deserialize, Eq, PartialEq, Hash, Clone, Copy)] +#[derive(Debug, Serialize, Deserialize, Eq, PartialEq, Hash, Clone, Copy)] pub struct HandlerId(usize, bool); impl HandlerId { @@ -249,6 +249,7 @@ thread_local! { } /// Create a single instance in the current thread. +#[allow(missing_debug_implementations)] pub struct Context; impl Discoverer for Context { @@ -344,6 +345,7 @@ impl Drop for ContextBridge { } /// Create an instance in the current thread. +#[allow(missing_debug_implementations)] pub struct Job; impl Discoverer for Job { @@ -397,6 +399,7 @@ impl Drop for JobBridge { // <<< SEPARATE THREAD >>> /// Create a new instance for every bridge. +#[allow(missing_debug_implementations)] pub struct Private; impl Discoverer for Private { @@ -438,6 +441,12 @@ pub struct PrivateBridge { _agent: PhantomData, } +impl fmt::Debug for PrivateBridge { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("PrivateBridge<_>") + } +} + impl Bridge for PrivateBridge { fn send(&mut self, msg: AGN::Input) { // TODO Important! Implement. @@ -494,6 +503,7 @@ thread_local! { } /// Create a single instance in a tab. +#[allow(missing_debug_implementations)] pub struct Public; impl Discoverer for Public { @@ -555,10 +565,16 @@ impl Discoverer for Public { impl Dispatchable for Public {} /// A connection manager for components interaction with workers. -pub struct PublicBridge { +pub struct PublicBridge { worker: Value, id: HandlerId, - _agent: PhantomData, + _agent: PhantomData, +} + +impl fmt::Debug for PublicBridge { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("PublicBridge<_>") + } } impl PublicBridge { @@ -636,6 +652,7 @@ impl Drop for PublicBridge { } /// Create a single instance in a browser. +#[allow(missing_debug_implementations)] pub struct Global; impl Discoverer for Global {} @@ -681,6 +698,12 @@ pub struct AgentScope { shared_agent: Shared>, } +impl fmt::Debug for AgentScope { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("AgentScope<_>") + } +} + impl Clone for AgentScope { fn clone(&self) -> Self { AgentScope { diff --git a/src/app.rs b/src/app.rs index be50f848dd6..c44d8494898 100644 --- a/src/app.rs +++ b/src/app.rs @@ -5,6 +5,7 @@ use crate::html::{Component, Scope}; use stdweb::web::{document, Element, INode, IParentNode}; /// An application instance. +#[derive(Debug)] pub struct App { /// `Scope` holder scope: Scope, diff --git a/src/components/select.rs b/src/components/select.rs index 68549e23028..b762a01789e 100644 --- a/src/components/select.rs +++ b/src/components/select.rs @@ -37,18 +37,20 @@ use crate::html::{ChangeData, Component, ComponentLink, Html, ShouldRender}; use crate::macros::{html, Properties}; /// `Select` component. +#[derive(Debug)] pub struct Select { props: Props, } /// Internal message of the component. +#[derive(Debug)] pub enum Msg { /// This message indicates the option with id selected. Selected(Option), } /// Properties of `Select` component. -#[derive(PartialEq, Properties)] +#[derive(PartialEq, Properties, Debug)] pub struct Props { /// Initially selected value. pub selected: Option, diff --git a/src/format/cbor.rs b/src/format/cbor.rs index 7705f74257a..f2cd3e05568 100644 --- a/src/format/cbor.rs +++ b/src/format/cbor.rs @@ -16,6 +16,7 @@ use serde_cbor; /// let Cbor(data) = dump; ///# } /// ``` +#[derive(Debug)] pub struct Cbor(pub T); binary_format!(Cbor based on serde_cbor); diff --git a/src/format/json.rs b/src/format/json.rs index 9bed4ad38d6..c9473d500aa 100644 --- a/src/format/json.rs +++ b/src/format/json.rs @@ -12,6 +12,7 @@ /// // Converts JSON string to a data (lazy). /// let Json(data) = dump; /// ``` +#[derive(Debug)] pub struct Json(pub T); text_format!(Json based on serde_json); diff --git a/src/format/msgpack.rs b/src/format/msgpack.rs index 355d47c23c6..679610c77fa 100644 --- a/src/format/msgpack.rs +++ b/src/format/msgpack.rs @@ -17,6 +17,7 @@ use rmp_serde; /// let MsgPack(data) = dump; ///# } /// ``` +#[derive(Debug)] pub struct MsgPack(pub T); binary_format!(MsgPack based on rmp_serde); diff --git a/src/format/nothing.rs b/src/format/nothing.rs index 09cc080e536..01b6d5d171d 100644 --- a/src/format/nothing.rs +++ b/src/format/nothing.rs @@ -4,6 +4,7 @@ use super::{Binary, Text}; use failure::err_msg; /// A representation of an empty data. Nothing stored. Nothing restored. +#[derive(Debug)] pub struct Nothing; impl Into for Nothing { diff --git a/src/format/toml.rs b/src/format/toml.rs index 807de8f3f57..99cbe04164f 100644 --- a/src/format/toml.rs +++ b/src/format/toml.rs @@ -16,6 +16,7 @@ use toml; /// let Toml(data) = dump; /// } /// ``` +#[derive(Debug)] pub struct Toml(pub T); text_format!(Toml based on toml); diff --git a/src/format/yaml.rs b/src/format/yaml.rs index 72fd5c5a313..6202742d393 100644 --- a/src/format/yaml.rs +++ b/src/format/yaml.rs @@ -17,6 +17,7 @@ use serde_yaml; /// let Yaml(data) = dump; ///# } /// ``` +#[derive(Debug)] pub struct Yaml(pub T); text_format!(Yaml based on serde_yaml); diff --git a/src/html/listener.rs b/src/html/listener.rs index 63483c01569..dffe7900d92 100644 --- a/src/html/listener.rs +++ b/src/html/listener.rs @@ -17,6 +17,7 @@ macro_rules! impl_action { /// A wrapper for a callback. /// Listener extracted from here when attached. + #[allow(missing_debug_implementations)] pub struct Wrapper(Option); /// And event type which keeps the returned type. diff --git a/src/html/mod.rs b/src/html/mod.rs index 5a016453338..1a9f9b9677c 100644 --- a/src/html/mod.rs +++ b/src/html/mod.rs @@ -282,6 +282,7 @@ pub trait Properties { } /// Builder for when a component has no properties +#[derive(Debug)] pub struct EmptyBuilder; impl Properties for () { diff --git a/src/html/scope.rs b/src/html/scope.rs index 40305815fe2..6df98c76657 100644 --- a/src/html/scope.rs +++ b/src/html/scope.rs @@ -25,6 +25,12 @@ pub struct Scope { shared_state: Shared>, } +impl fmt::Debug for Scope { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("Scope<_>") + } +} + impl Clone for Scope { fn clone(&self) -> Self { Scope { diff --git a/src/lib.rs b/src/lib.rs index 5370a862d28..35fbd194087 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -55,6 +55,7 @@ #![deny( missing_docs, + missing_debug_implementations, bare_trait_objects, anonymous_parameters, elided_lifetimes_in_paths diff --git a/src/services/console.rs b/src/services/console.rs index 57090322296..47d441a9df4 100644 --- a/src/services/console.rs +++ b/src/services/console.rs @@ -5,7 +5,7 @@ use stdweb::{_js_impl, js}; /// A service to use methods of a /// [Console](https://developer.mozilla.org/en-US/docs/Web/API/Console). -#[derive(Default)] +#[derive(Default, Debug)] pub struct ConsoleService {} impl ConsoleService { diff --git a/src/services/dialog.rs b/src/services/dialog.rs index 0d42fb656b3..8410d6ce7c1 100644 --- a/src/services/dialog.rs +++ b/src/services/dialog.rs @@ -6,7 +6,7 @@ use stdweb::Value; use stdweb::{_js_impl, js}; /// A dialog service. -#[derive(Default)] +#[derive(Default, Debug)] pub struct DialogService {} impl DialogService { diff --git a/src/services/fetch.rs b/src/services/fetch.rs index 0a7fe4e87aa..82616ab4588 100644 --- a/src/services/fetch.rs +++ b/src/services/fetch.rs @@ -6,6 +6,7 @@ use crate::format::{Binary, Format, Text}; use failure::Fail; use serde::Serialize; use std::collections::HashMap; +use std::fmt; use stdweb::serde::Serde; use stdweb::unstable::{TryFrom, TryInto}; use stdweb::web::ArrayBuffer; @@ -16,7 +17,7 @@ use stdweb::{_js_impl, js}; pub use http::{HeaderMap, Method, Request, Response, StatusCode, Uri}; /// Type to set cache for fetch. -#[derive(Serialize)] +#[derive(Serialize, Debug)] #[serde(rename_all = "kebab-case")] pub enum Cache { /// `default` value of cache. @@ -35,7 +36,7 @@ pub enum Cache { } /// Type to set credentials for fetch. -#[derive(Serialize)] +#[derive(Serialize, Debug)] #[serde(rename_all = "kebab-case")] pub enum Credentials { /// `omit` value of credentials. @@ -47,7 +48,7 @@ pub enum Credentials { } /// Type to set mode for fetch. -#[derive(Serialize)] +#[derive(Serialize, Debug)] #[serde(rename_all = "kebab-case")] pub enum Mode { /// `same-origin` value of mode. @@ -59,7 +60,7 @@ pub enum Mode { } /// Type to set redirect behaviour for fetch. -#[derive(Serialize)] +#[derive(Serialize, Debug)] #[serde(rename_all = "kebab-case")] pub enum Redirect { /// `follow` value of redirect. @@ -72,7 +73,7 @@ pub enum Redirect { /// Init options for `fetch()` function call. /// https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/fetch -#[derive(Serialize, Default)] +#[derive(Serialize, Default, Debug)] pub struct FetchOptions { /// Cache of a fetch request. #[serde(skip_serializing_if = "Option::is_none")] @@ -99,8 +100,14 @@ enum FetchError { #[must_use] pub struct FetchTask(Option); +impl fmt::Debug for FetchTask { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("FetchTask") + } +} + /// A service to fetch resources. -#[derive(Default)] +#[derive(Default, Debug)] pub struct FetchService {} impl FetchService { diff --git a/src/services/interval.rs b/src/services/interval.rs index c43d9407249..b2cf7810b49 100644 --- a/src/services/interval.rs +++ b/src/services/interval.rs @@ -3,6 +3,7 @@ use super::{to_ms, Task}; use crate::callback::Callback; +use std::fmt; use std::time::Duration; use stdweb::Value; #[allow(unused_imports)] @@ -13,8 +14,14 @@ use stdweb::{_js_impl, js}; #[must_use] pub struct IntervalTask(Option); +impl fmt::Debug for IntervalTask { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("IntervalTask") + } +} + /// A service to send messages on every elapsed interval. -#[derive(Default)] +#[derive(Default, Debug)] pub struct IntervalService {} impl IntervalService { diff --git a/src/services/keyboard.rs b/src/services/keyboard.rs index fb58bd77feb..ba4938a700d 100644 --- a/src/services/keyboard.rs +++ b/src/services/keyboard.rs @@ -1,5 +1,6 @@ //! Service to register key press event listeners on elements. use crate::callback::Callback; +use std::fmt; use stdweb::web::event::{KeyDownEvent, KeyPressEvent, KeyUpEvent}; use stdweb::web::{EventListenerHandle, IEventTarget}; @@ -12,6 +13,7 @@ use stdweb::web::{EventListenerHandle, IEventTarget}; /// /// This service is for adding key event listeners to elements that don't support these attributes, /// like the `document` or `` elements for example. +#[derive(Debug)] pub struct KeyboardService {} /// Handle to the key event listener. @@ -19,6 +21,12 @@ pub struct KeyboardService {} /// When it goes out of scope, the listener will be removed from the element. pub struct KeyListenerHandle(Option); +impl fmt::Debug for KeyListenerHandle { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("KeyListenerHandle") + } +} + impl KeyboardService { /// Registers a callback that listens to KeyPressEvents on a provided element. /// diff --git a/src/services/reader.rs b/src/services/reader.rs index 7a16abb3531..c1fd144b098 100644 --- a/src/services/reader.rs +++ b/src/services/reader.rs @@ -3,6 +3,7 @@ use super::Task; use crate::callback::Callback; use std::cmp; +use std::fmt; use stdweb::unstable::TryInto; use stdweb::web::event::LoadEndEvent; pub use stdweb::web::{Blob, File, IBlob}; @@ -39,7 +40,7 @@ pub enum FileChunk { } /// A reader service attached to a user context. -#[derive(Default)] +#[derive(Default, Debug)] pub struct ReaderService {} impl ReaderService { @@ -135,6 +136,12 @@ pub struct ReaderTask { file_reader: FileReader, } +impl fmt::Debug for ReaderTask { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("ReaderTask") + } +} + impl Task for ReaderTask { fn is_active(&self) -> bool { self.file_reader.ready_state() == FileReaderReadyState::Loading diff --git a/src/services/render.rs b/src/services/render.rs index f213bff1693..b5d244a84b8 100644 --- a/src/services/render.rs +++ b/src/services/render.rs @@ -3,6 +3,7 @@ use crate::callback::Callback; use crate::services::Task; +use std::fmt; use stdweb::unstable::TryInto; use stdweb::Value; #[allow(unused_imports)] @@ -12,8 +13,14 @@ use stdweb::{_js_impl, js}; #[must_use] pub struct RenderTask(Option); +impl fmt::Debug for RenderTask { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("RenderTask") + } +} + /// A service to request animation frames. -#[derive(Default)] +#[derive(Default, Debug)] pub struct RenderService {} impl RenderService { diff --git a/src/services/resize.rs b/src/services/resize.rs index c94d032cba6..fd3593795f4 100644 --- a/src/services/resize.rs +++ b/src/services/resize.rs @@ -1,4 +1,5 @@ //! This module contains the implementation of a service that listens for browser window resize events. +use std::fmt; use stdweb::Value; use stdweb::{ js, @@ -7,14 +8,21 @@ use stdweb::{ use yew::callback::Callback; /// A service that fires events when the browser window resizes. -#[derive(Default)] +#[derive(Default, Debug)] pub struct ResizeService {} /// A handle to the event listener for resize events. #[must_use] pub struct ResizeTask(Option); +impl fmt::Debug for ResizeTask { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("ResizeTask") + } +} + /// Dimensions of the window. +#[derive(Debug)] pub struct WindowDimensions { /// The width of the viewport of the browser window. pub width: i32, diff --git a/src/services/storage.rs b/src/services/storage.rs index 4204cbf53c1..e559740a41c 100644 --- a/src/services/storage.rs +++ b/src/services/storage.rs @@ -3,6 +3,7 @@ use crate::format::Text; use failure::Fail; +use std::fmt; use stdweb::web::{window, Storage}; /// Represents errors of a storage. @@ -13,6 +14,7 @@ enum StorageError { } /// An area to keep the data in. +#[derive(Debug)] pub enum Area { /// Use `localStorage` of a browser. Local, @@ -25,6 +27,12 @@ pub struct StorageService { storage: Storage, } +impl fmt::Debug for StorageService { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("StorageService") + } +} + impl StorageService { /// Creates a new storage service instance with specified storage area. pub fn new(area: Area) -> Self { diff --git a/src/services/timeout.rs b/src/services/timeout.rs index 0639034c99d..eb8450ecbfb 100644 --- a/src/services/timeout.rs +++ b/src/services/timeout.rs @@ -3,6 +3,7 @@ use super::{to_ms, Task}; use crate::callback::Callback; +use std::fmt; use std::time::Duration; use stdweb::Value; #[allow(unused_imports)] @@ -12,8 +13,14 @@ use stdweb::{_js_impl, js}; #[must_use] pub struct TimeoutTask(Option); +impl fmt::Debug for TimeoutTask { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("TimeoutTask") + } +} + /// An service to set a timeout. -#[derive(Default)] +#[derive(Default, Debug)] pub struct TimeoutService {} impl TimeoutService { diff --git a/src/services/websocket.rs b/src/services/websocket.rs index d8decaf4f51..23c2d577f84 100644 --- a/src/services/websocket.rs +++ b/src/services/websocket.rs @@ -4,12 +4,13 @@ use super::Task; use crate::callback::Callback; use crate::format::{Binary, Text}; +use std::fmt; use stdweb::traits::IMessageEvent; use stdweb::web::event::{SocketCloseEvent, SocketErrorEvent, SocketMessageEvent, SocketOpenEvent}; use stdweb::web::{IEventTarget, SocketBinaryType, SocketReadyState, WebSocket}; -#[derive(Debug)] /// A status of a websocket connection. Used for status notification. +#[derive(Debug)] pub enum WebSocketStatus { /// Fired when a websocket connection was opened. Opened, @@ -26,8 +27,14 @@ pub struct WebSocketTask { notification: Callback, } +impl fmt::Debug for WebSocketTask { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("WebSocketTask") + } +} + /// A websocket service attached to a user context. -#[derive(Default)] +#[derive(Default, Debug)] pub struct WebSocketService {} impl WebSocketService { diff --git a/src/virtual_dom/vcomp.rs b/src/virtual_dom/vcomp.rs index a1c23a75365..55ffe583295 100644 --- a/src/virtual_dom/vcomp.rs +++ b/src/virtual_dom/vcomp.rs @@ -5,6 +5,7 @@ use crate::callback::Callback; use crate::html::{Component, ComponentUpdate, NodeCell, Scope}; use std::any::TypeId; use std::cell::RefCell; +use std::fmt; use std::rc::Rc; use stdweb::unstable::TryInto; use stdweb::web::{document, Element, INode, Node}; @@ -31,6 +32,12 @@ pub struct VComp { state: Rc>>, } +impl fmt::Debug for VComp { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("VComp<_>") + } +} + /// A virtual child component. pub struct VChild { /// The component properties @@ -39,6 +46,12 @@ pub struct VChild { pub scope: ScopeHolder, } +impl fmt::Debug for VChild { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.write_str("VChild<_,_>") + } +} + impl VChild where SELF: Component, diff --git a/src/virtual_dom/vlist.rs b/src/virtual_dom/vlist.rs index 6be18cd3569..66c7aad39b1 100644 --- a/src/virtual_dom/vlist.rs +++ b/src/virtual_dom/vlist.rs @@ -4,6 +4,7 @@ use crate::html::{Component, Scope}; use stdweb::web::{Element, Node}; /// This struct represents a fragment of the Virtual DOM tree. +#[derive(Debug)] pub struct VList { /// The list of children nodes. Which also could have their own children. pub children: Vec>,