Skip to main content

Board

Struct Board 

Source
pub struct Board(/* private fields */);
Expand description

A complete PCB stackup: an ordered collection of Layers of any type.

Layers are identified by their LayerType; each type may appear at most once. Use Board::add_layer to insert or merge a layer, and LayerMerge::merge to combine two boards that share the same layer set.

Implementations§

Source§

impl Board

Source

pub fn load(data: Vec<(&str, BufReader<&mut dyn Read>)>) -> LoadResult

Parses a board from a list of (filename, reader) pairs.

The layer type is inferred from the file name (see LayerType::from_file_name): the extension (e.g. .gtl → Top), or for .gbr files the KiCad layer name (e.g. -F_Courtyard.gbr). A specific X2 FileFunction embedded in the Gerber data takes precedence. Files with unrecognised extensions or parse failures are collected in LoadResult::errors so the caller can inspect them without losing the layers that did load correctly.

Source

pub fn empty() -> Self

Creates a board with no layers.

Source

pub fn comment(&mut self, txt: String)

Appends a comment command to every layer that supports it (Gerber and Excellon).

Source

pub fn from_folder(path: &Path) -> Result<LoadResult>

Loads every file with a recognised Gerber or Excellon extension from path.

Files with unrecognised extensions are silently skipped. Returns an Err only if the directory itself cannot be read. Per-file open and parse failures are captured in LoadResult::errors so the caller can inspect them without losing the successfully loaded layers.

When the parallel feature is enabled, files are parsed concurrently using Rayon.

Source

pub fn layers(&self) -> &[Layer]

Returns references to all layers in insertion order.

Source

pub fn layers_mut(&mut self) -> &mut [Layer]

Returns mutable references to all layers in insertion order.

Source

pub fn add_layer(&mut self, layer: impl Into<Layer>) -> Result<(), MergeError>

Inserts a layer into the board, or merges it into the existing layer of the same type if one is already present.

Accepts anything that converts into a Layer (e.g. GerberLayerData, ExcellonLayerData).

A failed merge leaves the board unchanged.

Source

pub fn has_undefined(&self) -> bool

Returns true if any layer has type LayerType::UndefinedGerber.

Source

pub fn get_undefined(&self) -> Vec<&Layer>

Returns all layers with type LayerType::UndefinedGerber.

Source

pub fn get_undefined_mut(&mut self) -> Vec<&mut Layer>

Returns mutable references to all layers with type LayerType::UndefinedGerber.

Source

pub fn get_layer(&self, ty: &LayerType) -> Option<&Layer>

Returns the layer with the given type, or None if not present.

Source

pub fn get_layer_mut(&mut self, ty: &LayerType) -> Option<&mut Layer>

Returns a mutable reference to the layer with the given type, or None if not present.

Source

pub fn write_to<T>( &self, options: &WriteOptions, f: &mut impl FnMut(&Layer) -> Result<BufWriter<T>>, ) -> Result<(), WriteError>
where T: Write,

Writes every layer through a writer obtained from f.

Unmodified layers are written as their original bytes. Everything is checked (names, and completeness of edited layers) before f is called for the first time, so a rejected export opens no writer.

Source

pub fn check_write(&self, options: &WriteOptions) -> Result<(), WriteError>

Runs every check write_to performs before writing, without writing anything.

Source

pub fn unresolved_edits(&self) -> Vec<(String, LayerDiagnostics)>

Edited layers that would be refused without WriteOptions::allow_incomplete, with their diagnostics.

Source

pub fn diagnostics(&self) -> Vec<(String, LayerDiagnostics)>

Interpretation diagnostics of every layer, by layer name.

Source

pub fn write_to_folder( &self, path: &Path, options: &WriteOptions, ) -> Result<(), WriteError>

Writes all layers to path, creating the directory if necessary.

Each layer is written to a file named layer.name inside path. Files are first written to temporary names and only renamed into place once every layer was written successfully, so a write failure leaves existing files untouched (the renames themselves are not atomic as a group).

Trait Implementations§

Source§

impl Clone for Board

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Board

Source§

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

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

impl From<ExcellonLayerData> for Board

Source§

fn from(data: ExcellonLayerData) -> Self

Creates a board containing a single Excellon drill layer.

Source§

impl From<GerberLayerData> for Board

Source§

fn from(data: GerberLayerData) -> Self

Creates a board containing a single Gerber layer.

Source§

impl From<Layer> for Board

Source§

fn from(layer: Layer) -> Self

Creates a board containing a single layer.

Source§

impl From<Vec<Layer>> for Board

Source§

fn from(layers: Vec<Layer>) -> Self

Creates a board from a pre-built list of layers.

Source§

impl LayerCorners for Board

Source§

fn get_corners(&self) -> (Pos, Pos)

Returns the bounding box of the board.

Computed as the union of all layer corners (Gerber and Excellon drill), excluding KeepOut, Info, SidePlating and courtyard layers as they don’t represent physical board area.

Source§

fn get_size(&self) -> Size

Returns the bounding-box dimensions derived from get_corners.
Source§

impl LayerMerge for Board

Source§

fn merge(&mut self, other: &Self) -> Result<(), MergeError>

Merges layers from other into the corresponding layers of self.

Only layers whose LayerType already exists in self are updated. Layer types present in other but not in self are ignored — use add_layer to insert a new layer instead.

Every layer pair is checked first, so a failure on any layer leaves the whole board unchanged.

Source§

fn check_merge(&self, _other: &Self) -> Result<(), MergeError>

Checks whether merge would succeed, without changing anything.
Source§

fn merge_from(&mut self, other: impl Into<Self>) -> Result<(), MergeError>

Converts other into Self and merges it. Read more
Source§

impl LayerRotate for Board

Source§

fn rotate(&mut self, steps: i32)

Rotate by steps CW quarter-turns about the layer’s own centroid.
Source§

fn rebase(&mut self, steps: i32, offset: &Pos)

Rotate by steps CW quarter-turns about the origin, then translate by offset (mm).
Source§

impl LayerTransform for Board

Source§

fn transform(&mut self, transform: &Pos)

Translates every layer by transform (mm).

Source§

impl PartialEq for Board

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Board

Auto Trait Implementations§

§

impl Freeze for Board

§

impl RefUnwindSafe for Board

§

impl Send for Board

§

impl Sync for Board

§

impl Unpin for Board

§

impl UnsafeUnpin for Board

§

impl UnwindSafe for Board

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.