Get project compiling with type-safe actions

This commit is contained in:
Nathan Sobo
2021-08-22 21:02:48 -06:00
parent 638b533fc7
commit 86effd64a2
13 changed files with 229 additions and 206 deletions
+1 -1
View File
@@ -132,7 +132,7 @@ impl AnyAction for () {
#[macro_export]
macro_rules! action {
($name:ident, $arg:ty) => {
#[derive(Clone, Debug)]
#[derive(Clone)]
pub struct $name(pub $arg);
impl $crate::Action for $name {
+11 -7
View File
@@ -2,6 +2,7 @@ use anyhow::anyhow;
use std::{
any::Any,
collections::{HashMap, HashSet},
fmt::Debug,
};
use tree_sitter::{Language, Node, Parser};
@@ -148,7 +149,7 @@ impl Keymap {
}
}
mod menu {
pub mod menu {
use crate::action;
action!(SelectPrev);
@@ -425,6 +426,11 @@ mod tests {
}
}
impl Eq for A {}
impl Debug for A {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "A({:?})", &self.0)
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
struct ActionArg {
@@ -472,12 +478,10 @@ mod tests {
}
impl Matcher {
fn test_keystroke<A: Action + Eq>(
&mut self,
keystroke: &str,
view_id: usize,
cx: &Context,
) -> Option<A> {
fn test_keystroke<A>(&mut self, keystroke: &str, view_id: usize, cx: &Context) -> Option<A>
where
A: Action + Debug + Eq,
{
if let MatchResult::Action(action) =
self.push_keystroke(Keystroke::parse(keystroke).unwrap(), view_id, cx)
{
-1
View File
@@ -29,7 +29,6 @@ use objc::{
};
use ptr::null_mut;
use std::{
any::Any,
cell::{Cell, RefCell},
convert::TryInto,
ffi::{c_void, CStr},