nom_gcode/
mnemonic.rs

1use std::fmt;
2
3#[derive(Debug, PartialEq, Clone, Copy)]
4pub enum Mnemonic {
5    /// Preparatory commands, often telling the controller what kind of motion
6    /// or offset is desired.
7    General,
8    /// Auxilliary commands.
9    Miscellaneous,
10    /// Used to give the current program a unique "name".
11    ProgramNumber,
12    /// Tool selection.
13    ToolChange,
14    /// O-Code: http://linuxcnc.org/docs/html/gcode/o-code.html
15    Subroutine,
16}
17
18pub static G: Mnemonic = Mnemonic::General;
19pub static M: Mnemonic = Mnemonic::Miscellaneous;
20pub static P: Mnemonic = Mnemonic::ProgramNumber;
21pub static T: Mnemonic = Mnemonic::ToolChange;
22pub static O: Mnemonic = Mnemonic::Subroutine;
23
24impl fmt::Display for Mnemonic {
25    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
26        use Mnemonic::*;
27
28        let mnemonic_char = match self {
29            General => 'G',
30            Miscellaneous => 'M',
31            ProgramNumber =>  'P',
32            ToolChange => 'T',
33            Subroutine =>  'O',
34        };
35
36        write!(f, "{}", mnemonic_char)
37    }
38}