GerberDoc

Struct GerberDoc 

Source
pub struct GerberDoc {
    pub units: Option<Unit>,
    pub format_specification: Option<CoordinateFormat>,
    pub apertures: HashMap<i32, Aperture>,
    pub commands: Vec<Result<Command, GerberParserErrorWithContext>>,
    pub image_name: Option<String>,
}
Expand description

Representation of a Gerber document

Fields§

§units: Option<Unit>

unit type, defined once per document

§format_specification: Option<CoordinateFormat>

format specification for coordinates, defined once per document

§apertures: HashMap<i32, Aperture>

map of apertures which can be used in draw commands later on in the document.

§commands: Vec<Result<Command, GerberParserErrorWithContext>>

Everything else - draw commands, comments, attributes, etc.

§image_name: Option<String>

Image Name, 8.1.3. Deprecated, but still used by fusion 360.

Implementations§

Source§

impl GerberDoc

Source

pub fn new() -> GerberDoc

👎Deprecated since 0.2.0: Use default() instead
Source

pub fn into_commands(self) -> Vec<Command>

Convert Self into a representation of a gerber document purely in terms of elements provided in the gerber-types rust crate.

This will ignore any errors encountered during parsing, to access errors, use errors first.

Examples found in repository?
examples/example1.rs (line 28)
6pub fn main() -> anyhow::Result<()> {
7    use std::fs::File;
8    use std::io::BufReader;
9
10    let path = "assets/reference_files/two_square_boxes.gbr";
11
12    // open a .gbr file from system
13    let file = File::open(path).unwrap();
14    let reader = BufReader::new(file);
15
16    // Now we parse the file to a GerberDoc, if io errors occur a partial gerber_doc will be returned along with the error
17    let gerber_doc = gerber_parser::parse(reader)
18        .map_err(|(_doc, parse_error)| anyhow!("Error parsing file: {:?}", parse_error))?;
19
20    let commands: Vec<&Command> = gerber_doc.commands();
21
22    // Now you can use the commands as you wish
23    println!("Parsed document. command_count: {} ", commands.len());
24    dump_commands(&commands);
25
26    // there are other methods that consume the document to yield an 'atomic' representation purely
27    // in terms of types defined in the gerber-types crate
28    let _commands: Vec<Command> = gerber_doc.into_commands();
29
30    Ok(())
31}
Source

pub fn commands(&self) -> Vec<&Command>

Get a representation of a gerber document purely in terms of elements provided in the gerber-types rust crate.

Similar to into_commands(), but does not consume the Self, and returns references to Commands

This will ignore any errors encountered during parsing, to access errors, use errors.

Examples found in repository?
examples/example1.rs (line 20)
6pub fn main() -> anyhow::Result<()> {
7    use std::fs::File;
8    use std::io::BufReader;
9
10    let path = "assets/reference_files/two_square_boxes.gbr";
11
12    // open a .gbr file from system
13    let file = File::open(path).unwrap();
14    let reader = BufReader::new(file);
15
16    // Now we parse the file to a GerberDoc, if io errors occur a partial gerber_doc will be returned along with the error
17    let gerber_doc = gerber_parser::parse(reader)
18        .map_err(|(_doc, parse_error)| anyhow!("Error parsing file: {:?}", parse_error))?;
19
20    let commands: Vec<&Command> = gerber_doc.commands();
21
22    // Now you can use the commands as you wish
23    println!("Parsed document. command_count: {} ", commands.len());
24    dump_commands(&commands);
25
26    // there are other methods that consume the document to yield an 'atomic' representation purely
27    // in terms of types defined in the gerber-types crate
28    let _commands: Vec<Command> = gerber_doc.into_commands();
29
30    Ok(())
31}
Source

pub fn into_errors(self) -> Vec<GerberParserErrorWithContext>

Source

pub fn errors(&self) -> Vec<&GerberParserErrorWithContext>

Similar to into_errors(), but does not consume the Self, and returns references to errors

Trait Implementations§

Source§

impl Debug for GerberDoc

Source§

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

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

impl Default for GerberDoc

Source§

fn default() -> GerberDoc

Returns the “default value” for a type. Read more
Source§

impl Display for GerberDoc

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.