rust
The community/lang/rust
directory contains files that provide support for the Rust programming language in Talon.
The rust.py
file at https://github.com/talonhub/community/blob/main/lang/rust/rust.py defines the core functionality for Rust support. It includes:
- Context and lists: It sets up a Talon context that activates when the code language is set to Rust. It defines several lists that are used in the
rust.talon
file for grammar. These lists include:code_type
: A list of Rust's scalar, compound, standard library, and standard sync types.code_type_modifier
: A list of modifiers for types such asmut
,&
, and&mut
.code_macros
: A list of Rust macros, including function-like, array-like, and block-like macros.code_trait
: A list of Rust traits such asFn
,From
, andIterator
.code_libraries
: A list of standard library modules that can be imported using theuse
keyword.code_common_function
: A list of common functions and macros.
- Actions: It defines a set of actions for working with Rust code, including:
- Actions for inserting code structures like
if
,for
,while
,loop
, andmatch
statements. - Actions for inserting comments, including line, documentation, and block comments.
- Actions for inserting operators, including arithmetic, logical, assignment, and bitwise operators.
- Actions for inserting function declarations, including private, protected, and public functions.
- Actions for inserting macros, with different handling for function, array, and block macros.
- Actions for inserting specific keywords like
self
,true
,false
, andNone
. - Actions for inserting implementations of a trait using
impl
.
- Actions for inserting code structures like
- Helper Functions:
code_insert_function_or_macro
: A helper function to insert a function or macro, handling selections and delimiters.repeat_call
: A helper function to repeat a callable a number of times.
The rust.talon
file at https://github.com/talonhub/community/blob/main/lang/rust/rust.talon defines the voice commands that trigger the actions defined in rust.py
. It includes:
- Tagging: It applies several tags to enable language specific functionality.
- Settings: It defines the default formatters for functions and variables.
- Grammar: It defines rules for many Rust keywords, including:
unsafe
,struct
,enum
,async
,pub
,const
,fn
,impl
,let
,mod
,trait
,match
,Some
,static
,use
,ref
,dyn
, andself
. - Complex Grammar: It defines more complex rules for inserting code, including:
- Rules to insert
if let Some
,if let Ok
, andif let Err
statements. - Rules to insert documentation and block documentation comments.
- Rules to insert and implement traits and dynamic traits.
- Rules for inserting types and type modifiers
- Rules for inserting macros.
- Rules to insert
- Synonyms: Defines some synonyms for some actions or language constructs, like
is some
for.is_some()
.
These two files work together to provide a comprehensive set of tools for working with Rust code using voice commands. The rust.py
file provides the underlying logic and actions, while the rust.talon
file provides the voice commands that trigger those actions, allowing users to write Rust code more quickly and easily with voice.