Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn on Unhandled commands #1533

Merged
merged 6 commits into from
Jan 29, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Apply Suggestions from Code Review.
maan2003 committed Jan 29, 2021

Verified

This commit was signed with the committer’s verified signature.
germa89 German
commit 7cbfb3b733303a238e7e5e263dbb846ca3ec40a1
25 changes: 16 additions & 9 deletions druid/src/command.rs
Original file line number Diff line number Diff line change
@@ -25,12 +25,19 @@ use crate::{WidgetId, WindowId};
/// The identity of a [`Selector`].
///
/// [`Selector`]: struct.Selector.html
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[derive(Copy, Clone, PartialEq, Eq)]
pub(crate) struct SelectorSymbol {
str: &'static str,
must_use: bool,
}

impl std::fmt::Debug for SelectorSymbol {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let must_use = if self.must_use { " (must_use)" } else { "" };
write!(f, "{}{}", self.str, must_use)
}
}

/// An identifier for a particular command.
///
/// This should be a unique string identifier.
@@ -406,7 +413,7 @@ impl Command {
}

/// Checks if this command must be used.
pub fn is_must_use(&self) -> bool {
pub fn must_be_used(&self) -> bool {
self.symbol.must_use
}

@@ -480,8 +487,8 @@ impl Command {
if self.symbol == selector.symbol() {
Some(self.payload.downcast_ref().unwrap_or_else(|| {
panic!(
"The selector \"{}\" exists twice with different types. See druid::Command::get for more information",
selector.symbol().str
"The selector {:?} exists twice with different types. See druid::Command::get for more information",
selector.symbol()
);
}))
} else {
@@ -533,9 +540,9 @@ impl Notification {
if self.symbol == selector.symbol() {
Some(self.payload.downcast_ref().unwrap_or_else(|| {
panic!(
"The selector \"{}\" exists twice with different types. \
"The selector {:?} exists twice with different types. \
See druid::Command::get for more information",
selector.symbol().str
selector.symbol()
);
}))
} else {
@@ -575,7 +582,7 @@ impl From<Selector> for Command {

impl<T> std::fmt::Display for Selector<T> {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "Selector(\"{}\", {})", self.0.str, any::type_name::<T>())
write!(f, "Selector({:?}, {})", self.0, any::type_name::<T>())
}
}

@@ -625,8 +632,8 @@ impl std::fmt::Debug for Notification {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(
f,
"Notification: Selector {} from {:?}",
self.symbol.str, self.source
"Notification: Selector {:?} from {:?}",
self.symbol, self.source
)
}
}
2 changes: 1 addition & 1 deletion druid/src/win_handler.rs
Original file line number Diff line number Diff line change
@@ -644,7 +644,7 @@ impl<T: Data> AppState<T> {
}
_ => {
let handled = self.inner.borrow_mut().dispatch_cmd(cmd.clone());
if !handled.is_handled() && cmd.is_must_use() {
if !handled.is_handled() && cmd.must_be_used() {
log::warn!("{:?} was not handled.", cmd);
}
}