Struct GCode

Source
pub struct GCode<A = DefaultArguments> { /* private fields */ }
Expand description

The in-memory representation of a single command in the G-code language (e.g. "G01 X50.0 Y-20.0").

Implementations§

Source§

impl GCode

Source

pub fn new(mnemonic: Mnemonic, number: f32, span: Span) -> Self

Create a new GCode which uses the DefaultArguments buffer.

Source§

impl<A: Buffer<Word>> GCode<A>

Source

pub fn new_with_argument_buffer( mnemonic: Mnemonic, number: f32, span: Span, arguments: A, ) -> Self

Create a new GCode which uses a custom Buffer.

Source

pub fn mnemonic(&self) -> Mnemonic

The overall category this GCode belongs to.

Source

pub fn major_number(&self) -> u32

The integral part of a command number (i.e. the 12 in G12.3).

Source

pub fn minor_number(&self) -> u32

The fractional part of a command number (i.e. the 3 in G12.3).

Source

pub fn arguments(&self) -> &[Word]

The arguments attached to this GCode.

Source

pub fn span(&self) -> Span

Where the GCode was found in its source text.

Source

pub fn push_argument(&mut self, arg: Word) -> Result<(), CapacityError<Word>>

Add an argument to the list of arguments attached to this GCode.

Source

pub fn with_argument(self, arg: Word) -> Self

The builder equivalent of GCode::push_argument().

§Panics

This will panic if the underlying Buffer returns a CapacityError.

Source

pub fn value_for(&self, letter: char) -> Option<f32>

Get the value for a particular argument.

§Examples
let gcode = GCode::new(Mnemonic::General, 1.0, Span::PLACEHOLDER)
    .with_argument(Word::new('X', 30.0, Span::PLACEHOLDER))
    .with_argument(Word::new('Y', -3.14, Span::PLACEHOLDER));

assert_eq!(gcode.value_for('Y'), Some(-3.14));

Trait Implementations§

Source§

impl<A: Clone> Clone for GCode<A>

Source§

fn clone(&self) -> GCode<A>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A: Buffer<Word>> Debug for GCode<A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de, A> Deserialize<'de> for GCode<A>
where A: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<A: Buffer<Word>> Display for GCode<A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<A: Buffer<Word>> Extend<Word> for GCode<A>

Source§

fn extend<I: IntoIterator<Item = Word>>(&mut self, words: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<A, B> PartialEq<GCode<B>> for GCode<A>
where A: Buffer<Word>, B: Buffer<Word>,

Source§

fn eq(&self, other: &GCode<B>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<A> Serialize for GCode<A>
where A: Serialize,

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<A> Freeze for GCode<A>
where A: Freeze,

§

impl<A> RefUnwindSafe for GCode<A>
where A: RefUnwindSafe,

§

impl<A> Send for GCode<A>
where A: Send,

§

impl<A> Sync for GCode<A>
where A: Sync,

§

impl<A> Unpin for GCode<A>
where A: Unpin,

§

impl<A> UnwindSafe for GCode<A>
where A: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,