mirror of
https://codeberg.org/unspeaker/tek.git
synced 2025-12-06 11:46:41 +01:00
wip: make EdnItem work on Arc<str>
This commit is contained in:
parent
d4f962fbfa
commit
1b9da07280
17 changed files with 152 additions and 260 deletions
|
|
@ -2,14 +2,14 @@ use crate::*;
|
|||
|
||||
pub trait EdnInput: Input {
|
||||
fn matches_edn (&self, token: &str) -> bool;
|
||||
fn get_event <S: AsRef<str>> (_: &EdnItem<S>) -> Option<Self::Event> {
|
||||
fn get_event <S: AsRef<str>> (_: &EdnItem) -> Option<Self::Event> {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
/// Turns an EDN item sequence into a command enum variant.
|
||||
pub trait EdnCommand<C>: Command<C> {
|
||||
fn from_edn <'a> (state: &C, head: &EdnItem<&str>, tail: &'a [EdnItem<&'a str>])
|
||||
fn from_edn <'a> (state: &C, head: &EdnItem, tail: &'a [EdnItem])
|
||||
-> Option<Self>;
|
||||
}
|
||||
|
||||
|
|
@ -39,8 +39,8 @@ pub trait EdnCommand<C>: Command<C> {
|
|||
impl<$T: $Trait> EdnCommand<$T> for $Command {
|
||||
fn from_edn <'a> (
|
||||
$state: &$T,
|
||||
head: &EdnItem<&str>,
|
||||
tail: &'a [EdnItem<&'a str>]
|
||||
head: &EdnItem,
|
||||
tail: &'a [EdnItem]
|
||||
) -> Option<Self> {
|
||||
$(if let (EdnItem::Key($key), [ // if the identifier matches
|
||||
// bind argument ids
|
||||
|
|
@ -81,9 +81,7 @@ pub trait EdnCommand<C>: Command<C> {
|
|||
))* }) => {
|
||||
impl EdnCommand<$State> for $Command {
|
||||
fn from_edn <'a> (
|
||||
$state: &$State,
|
||||
head: &EdnItem<&str>,
|
||||
tail: &'a [EdnItem<&'a str>]
|
||||
$state: &$State, head: &EdnItem, tail: &'a [EdnItem]
|
||||
) -> Option<Self> {
|
||||
$(if let (EdnItem::Key($key), [ // if the identifier matches
|
||||
// bind argument ids
|
||||
|
|
@ -109,11 +107,11 @@ pub trait EdnCommand<C>: Command<C> {
|
|||
};
|
||||
}
|
||||
|
||||
pub struct EdnKeyMapToCommand<'a>(Vec<EdnItem<&'a str>>);
|
||||
impl<'a> EdnKeyMapToCommand<'a> {
|
||||
pub struct EdnKeyMapToCommand(Vec<EdnItem>);
|
||||
impl EdnKeyMapToCommand {
|
||||
/// Construct keymap from source text or fail
|
||||
pub fn new (keymap: &'a str) -> Usually<Self> {
|
||||
Ok(Self(EdnItem::<&str>::read_all(keymap)?))
|
||||
pub fn new (keymap: &str) -> Usually<Self> {
|
||||
Ok(Self(EdnItem::read_all(keymap)?))
|
||||
}
|
||||
/// Try to find a binding matching the currently pressed key
|
||||
pub fn from <T, C> (&self, state: &T, input: &impl EdnInput) -> Option<C>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue