Skip to content

Commit

Permalink
Merge 57bc2a6 into 9bc4675
Browse files Browse the repository at this point in the history
  • Loading branch information
dbrgn committed Mar 4, 2017
2 parents 9bc4675 + 57bc2a6 commit 714c5ce
Show file tree
Hide file tree
Showing 6 changed files with 471 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/attributes.rs
@@ -1,3 +1,5 @@
//! Attributes.

use chrono::{DateTime, UTC};
use uuid::Uuid;

Expand Down
13 changes: 12 additions & 1 deletion src/codegen.rs
Expand Up @@ -7,6 +7,17 @@ pub trait GerberCode {
fn to_code(&self) -> GerberResult<String>;
}

/// Implement GerberCode for booleans
impl GerberCode for bool {
fn to_code(&self) -> GerberResult<String> {
Ok(if *self {
"1".to_string()
} else {
"0".to_string()
})
}
}

/// Implement GerberCode for Vectors of types that implement GerberCode.
impl<T: GerberCode> GerberCode for Vec<T> {
fn to_code(&self) -> GerberResult<String> {
Expand Down Expand Up @@ -165,7 +176,7 @@ impl GerberCode for ExtendedCode {
ExtendedCode::CoordinateFormat(ref cf) => format!("%FSLAX{0}{1}Y{0}{1}*%", cf.integer, cf.decimal),
ExtendedCode::Unit(ref unit) => format!("%MO{}*%", try!(unit.to_code())),
ExtendedCode::ApertureDefinition(ref def) => format!("%ADD{}*%", try!(def.to_code())),
ExtendedCode::ApertureMacro => panic!("not yet implemented"),
ExtendedCode::ApertureMacro(ref am) => panic!("not yet implemented"),
ExtendedCode::LoadPolarity(ref polarity) => format!("%LP{}*%", try!(polarity.to_code())),
ExtendedCode::StepAndRepeat(ref sar) => format!("%SR{}*%", try!(sar.to_code())),
ExtendedCode::FileAttribute(ref attr) => format!("%TF.{}*%", try!(attr.to_code())),
Expand Down
2 changes: 2 additions & 0 deletions src/errors.rs
Expand Up @@ -7,6 +7,8 @@ quick_error! {
ConversionError(msg: String) {}
/// Bad coordinate format
CoordinateFormatError(msg: String) {}
/// A value is out of range
RangeError(msg: String) {}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Expand Up @@ -18,12 +18,14 @@ extern crate num;

mod types;
mod attributes;
mod macros;
mod codegen;
mod coordinates;
mod errors;

pub use types::*;
pub use attributes::*;
pub use macros::*;
pub use codegen::*;
pub use coordinates::*;
pub use errors::*;
Expand Down

0 comments on commit 714c5ce

Please sign in to comment.