diff --git a/macros/specctra_derive/src/lib.rs b/macros/specctra_derive/src/lib.rs index da06f39..a2f4e61 100644 --- a/macros/specctra_derive/src/lib.rs +++ b/macros/specctra_derive/src/lib.rs @@ -27,9 +27,5 @@ fn attr_content(attrs: &Vec, name: &str) -> Option { attrs .iter() .find(|attr| attr.path().is_ident(name)) - .and_then(|attr| Some(attr - .parse_args::() - .expect("string literal") - .value() - )) + .and_then(|attr| Some(attr.parse_args::().expect("string literal").value())) } diff --git a/macros/specctra_derive/src/read.rs b/macros/specctra_derive/src/read.rs index b38da66..c34cc51 100644 --- a/macros/specctra_derive/src/read.rs +++ b/macros/specctra_derive/src/read.rs @@ -1,11 +1,11 @@ use proc_macro2::TokenStream; use quote::quote; -use syn::{Data, DeriveInput, Fields, Field}; -use syn::Type::Path; use syn::ext::IdentExt; +use syn::Type::Path; +use syn::{Data, DeriveInput, Field, Fields}; -use crate::attr_present; use crate::attr_content; +use crate::attr_present; pub fn impl_read(input: &DeriveInput) -> TokenStream { let name = &input.ident; @@ -24,26 +24,22 @@ pub fn impl_read(input: &DeriveInput) -> TokenStream { fn impl_body(data: &Data) -> TokenStream { match data { - Data::Struct(data) => { - match &data.fields { - Fields::Named(fields) => { - let fields = fields.named.iter().map(|field| { - impl_field(field) - }); + Data::Struct(data) => match &data.fields { + Fields::Named(fields) => { + let fields = fields.named.iter().map(|field| impl_field(field)); - quote! { - Ok(Self { - #(#fields)* - }) - } + quote! { + Ok(Self { + #(#fields)* + }) } - _ => unimplemented!() } - } + _ => unimplemented!(), + }, Data::Enum(_data) => { todo!(); } - _ => unimplemented!() + _ => unimplemented!(), } } @@ -71,7 +67,7 @@ fn impl_field(field: &Field) -> TokenStream { if ident == "Option" { return quote! { #name: tokenizer.read_optional(stringify!(#name_str))?, - } + }; } } } @@ -81,4 +77,3 @@ fn impl_field(field: &Field) -> TokenStream { } } } - diff --git a/src/autorouter/autorouter.rs b/src/autorouter/autorouter.rs index 4fd5438..dfa7f5a 100644 --- a/src/autorouter/autorouter.rs +++ b/src/autorouter/autorouter.rs @@ -5,11 +5,7 @@ use thiserror::Error; use crate::{ board::{mesadata::AccessMesadata, Board}, - drawing::{ - band::BandTermsegIndex, - dot::FixedDotIndex, - Infringement, - }, + drawing::{band::BandTermsegIndex, dot::FixedDotIndex, Infringement}, layout::via::ViaWeight, router::{navmesh::NavmeshError, RouterError, RouterOptions}, triangulation::GetTrianvertexNodeIndex, @@ -99,7 +95,10 @@ impl Autorouter { Ok(()) } - pub fn place_via(&self, weight: ViaWeight) -> Result { + pub fn place_via( + &self, + weight: ViaWeight, + ) -> Result { PlaceViaExecutionStepper::new(weight) } diff --git a/src/autorouter/command.rs b/src/autorouter/command.rs index d56fec7..25f3b2f 100644 --- a/src/autorouter/command.rs +++ b/src/autorouter/command.rs @@ -44,9 +44,9 @@ impl ExecutionStepper { match autoroute.step(&mut invoker.autorouter)? { AutorouteStatus::Running => InvokerStatus::Running, AutorouteStatus::Routed(..) => InvokerStatus::Running, - AutorouteStatus::Finished => InvokerStatus::Finished( - "finished autorouting".to_string(), - ), + AutorouteStatus::Finished => { + InvokerStatus::Finished("finished autorouting".to_string()) + } } } ExecutionStepper::PlaceVia(place_via) => { @@ -70,10 +70,7 @@ impl ExecutionStepper { } ExecutionStepper::MeasureLength(measure_length) => { let length = measure_length.doit(&mut invoker.autorouter)?; - InvokerStatus::Finished(format!( - "Total length of selected bands: {}", - length - )) + InvokerStatus::Finished(format!("Total length of selected bands: {}", length)) } }) } diff --git a/src/autorouter/ratsnest.rs b/src/autorouter/ratsnest.rs index 9cdae3b..61cc7dd 100644 --- a/src/autorouter/ratsnest.rs +++ b/src/autorouter/ratsnest.rs @@ -89,7 +89,8 @@ impl Ratsnest { for layer in 0..layout.drawing().layer_count() { let mut handle_rvw = |maybe_net: Option, vertex: RatvertexIndex, pos: Point| { if let Some(net) = maybe_net { - triangulations.entry((layer, net)) + triangulations + .entry((layer, net)) .or_insert_with(|| Triangulation::new(node_bound)) .add_vertex(RatvertexWeight { vertex, pos })?; } diff --git a/src/drawing/drawing.rs b/src/drawing/drawing.rs index 17873ca..87715c2 100644 --- a/src/drawing/drawing.rs +++ b/src/drawing/drawing.rs @@ -927,12 +927,15 @@ impl Drawing { fn test_if_looses_dont_infringe_each_other(&self) -> bool { !self .primitive_nodes() - .filter(|node| matches!(node, - PrimitiveIndex::LooseDot(..) - | PrimitiveIndex::LoneLooseSeg(..) - | PrimitiveIndex::SeqLooseSeg(..) - | PrimitiveIndex::LooseBend(..) - )) + .filter(|node| { + matches!( + node, + PrimitiveIndex::LooseDot(..) + | PrimitiveIndex::LoneLooseSeg(..) + | PrimitiveIndex::SeqLooseSeg(..) + | PrimitiveIndex::LooseBend(..) + ) + }) .any(|node| { self.find_infringement( node, @@ -944,12 +947,15 @@ impl Drawing { None } }) - .filter(|primitive_node| matches!(primitive_node, - PrimitiveIndex::LooseDot(..) - | PrimitiveIndex::LoneLooseSeg(..) - | PrimitiveIndex::SeqLooseSeg(..) - | PrimitiveIndex::LooseBend(..) - )), + .filter(|primitive_node| { + matches!( + primitive_node, + PrimitiveIndex::LooseDot(..) + | PrimitiveIndex::LoneLooseSeg(..) + | PrimitiveIndex::SeqLooseSeg(..) + | PrimitiveIndex::LooseBend(..) + ) + }), ) .is_some() }) diff --git a/src/geometry/geometry.rs b/src/geometry/geometry.rs index f12fc74..3831c46 100644 --- a/src/geometry/geometry.rs +++ b/src/geometry/geometry.rs @@ -434,10 +434,7 @@ impl< GeometryLabel::Joined ) }) - .map(|ni| { - self.primitive_weight(ni) - .retag(ni) - }) + .map(|ni| self.primitive_weight(ni).retag(ni)) } pub fn seg_joints(&self, seg: SI) -> (DI, DI) { diff --git a/src/layout/poly.rs b/src/layout/poly.rs index f124607..8e5ddb7 100644 --- a/src/layout/poly.rs +++ b/src/layout/poly.rs @@ -37,7 +37,8 @@ impl<'a, R: AccessRules> Poly<'a, R> { } fn is_apex(&self, dot: FixedDotIndex) -> bool { - !self.layout + !self + .layout .drawing() .primitive(dot) .segs() diff --git a/src/math.rs b/src/math.rs index 0489458..64fee5d 100644 --- a/src/math.rs +++ b/src/math.rs @@ -86,7 +86,8 @@ fn cast_point_to_canonical_line(pt: Point, line: CanonicalLine) -> Point { / (line.a * line.a + line.b * line.b), (line.a * (-line.b * pt.x() + line.a * pt.y()) - line.b * line.c) / (line.a * line.a + line.b * line.b), - ).into() + ) + .into() } fn tangent_point_pairs( diff --git a/src/router/astar.rs b/src/router/astar.rs index eab2214..3c49fbe 100644 --- a/src/router/astar.rs +++ b/src/router/astar.rs @@ -197,10 +197,8 @@ where let zero_score = K::default(); this.scores.insert(start, zero_score); - this.visit_next.push(MinScored( - strategy.estimate_cost(&this.graph, start), - start, - )); + this.visit_next + .push(MinScored(strategy.estimate_cost(&this.graph, start), start)); this } } diff --git a/src/router/draw.rs b/src/router/draw.rs index 74185eb..da1ad00 100644 --- a/src/router/draw.rs +++ b/src/router/draw.rs @@ -131,9 +131,7 @@ impl<'a, R: AccessRules> Draw<'a, R> { let tangent = self .guide() .head_around_bend_segment(&head, around, cw, width)?; - let offset = self - .guide() - .head_around_bend_offset(&head, around, width); + let offset = self.guide().head_around_bend_offset(&head, around, width); self.cane_around( head, diff --git a/src/specctra/design.rs b/src/specctra/design.rs index 51bc81e..30f14e2 100644 --- a/src/specctra/design.rs +++ b/src/specctra/design.rs @@ -39,7 +39,6 @@ pub enum LoadingError { Parse(#[from] read::ParseErrorContext), } - /// This struct is responsible for managing the various Specctra components of a PCB design, /// including parsing the DSN file, handling the resolution, unit of measurement, /// and organizing the PCB's structure, placement, library, network, and wiring. @@ -68,16 +67,16 @@ impl SpecctraDesign { pub fn get_name(&self) -> &str { &self.pcb.name } - + /// Writes the Specctra Session (.ses) file format using the current board layout and mesadata. /// /// This function generates a Specctra SES session file that represents the board's net routing and - /// writes it to the provided output stream. The session data includes routed nets, wires, + /// writes it to the provided output stream. The session data includes routed nets, wires, /// layers, and other essential information for routing management. - pub fn write_ses( + pub fn write_ses( &self, board: &Board, - writer: impl std::io::Write, + writer: impl std::io::Write, ) -> Result<(), std::io::Error> { let mesadata = board.mesadata(); let drawing = board.layout().drawing(); @@ -150,8 +149,8 @@ impl SpecctraDesign { structure::NetOut { name: mesadata.net_netname(net).unwrap().to_owned(), wire: vec![wire], - via: Vec::new() - }, + via: Vec::new(), + }, ); } } @@ -193,7 +192,8 @@ impl SpecctraDesign { ))); // mapping of pin -> net prepared for adding pins - let pin_nets = self.pcb + let pin_nets = self + .pcb .network .nets .iter() @@ -229,22 +229,15 @@ impl SpecctraDesign { .unwrap(); let place_side_is_front = place.side == "front"; - let get_layer = |board: &Board, name: &str| Self::layer( - board, - &self.pcb.structure.layers, - name, - place_side_is_front, - ); + let get_layer = |board: &Board, name: &str| { + Self::layer(board, &self.pcb.structure.layers, name, place_side_is_front) + }; for pin in &image.pins { let pinname = format!("{}-{}", place.name, pin.id); let net = pin_nets.get(&pinname).unwrap(); - let padstack = self - .pcb - .library - .find_padstack_by_name(&pin.name) - .unwrap(); + let padstack = self.pcb.library.find_padstack_by_name(&pin.name).unwrap(); for shape in padstack.shapes.iter() { match shape { @@ -315,14 +308,11 @@ impl SpecctraDesign { .netname_net(&via.net) .unwrap(); - let padstack = self - .pcb - .library - .find_padstack_by_name(&via.name) - .unwrap(); + let padstack = self.pcb.library.find_padstack_by_name(&via.name).unwrap(); - let get_layer = |board: &Board, name: &str| - Self::layer(board, &self.pcb.structure.layers, name, true); + let get_layer = |board: &Board, name: &str| { + Self::layer(board, &self.pcb.structure.layers, name, true) + }; for shape in &padstack.shapes { match shape { @@ -692,12 +682,7 @@ impl SpecctraDesign { } } - fn pos( - place: PointWithRotation, - pin: PointWithRotation, - x: f64, - y: f64, - ) -> Point { + fn pos(place: PointWithRotation, pin: PointWithRotation, x: f64, y: f64) -> Point { let pos = (point! {x: x, y: y} + pin.pos).rotate_around_point(pin.rot, pin.pos); (pos + place.pos).rotate_around_point(place.rot, place.pos) } diff --git a/src/specctra/mesadata.rs b/src/specctra/mesadata.rs index 15eed7c..a16473a 100644 --- a/src/specctra/mesadata.rs +++ b/src/specctra/mesadata.rs @@ -1,5 +1,5 @@ //! Module for handling Specctra's mesadata - design rules, as well as layers -//! or net properties +//! or net properties use std::collections::HashMap; @@ -16,7 +16,7 @@ use crate::{ /// the Topola auto-router, in a PCB design process. This struct defines two key design /// rules: the width of the trace and the minimum clearance between electrical features. pub struct SpecctraRule { - /// Specifies the width of the trace (or conductor) in millimeters. + /// Specifies the width of the trace (or conductor) in millimeters. /// This value ensures that the traces meet electrical /// and mechanical requirements, such as current-carrying capacity or signal integrity. pub width: f64, @@ -42,10 +42,9 @@ impl SpecctraRule { /// This struct encapsulates information about rules for individual nets, net classes, /// layers, and their corresponding relationships. pub struct SpecctraMesadata { - /// The default routing rule applied globally if no specific net class rule is defined. structure_rule: SpecctraRule, - + // net class name -> rule /// A map from net class names to their specific `SpecctraRule` constraints. /// These rules are applied to all nets belonging to the respective net clas @@ -67,7 +66,6 @@ pub struct SpecctraMesadata { net_netclass: HashMap, } - impl SpecctraMesadata { /// Creates a [`SpecctraMesadata`] instance from a given `Pcb` reference. /// @@ -75,10 +73,11 @@ impl SpecctraMesadata { /// layer-to-layer name mappings, net-to-net name mappings, and net class rules. pub fn from_pcb(pcb: &Pcb) -> Self { let layer_layername = BiHashMap::from_iter( - pcb.structure.layers + pcb.structure + .layers .iter() .enumerate() - .map(|(index, layer)| (index, layer.name.clone())) + .map(|(index, layer)| (index, layer.name.clone())), ); // keeping this as a separate iter pass because it might be moved into a different struct later? @@ -115,7 +114,9 @@ impl SpecctraMesadata { if rule.width.is_some() { structure_rule.width = rule.width.unwrap() } - structure_rule.clearances.extend_from_slice(&rule.clearances); + structure_rule + .clearances + .extend_from_slice(&rule.clearances); } Self { @@ -129,9 +130,9 @@ impl SpecctraMesadata { /// Retrieves the Specctra routing rule associated with a specified net ID. /// - /// This function looks up the routing rule for a given net ID. It first checks if the net is - /// associated with a net class. If a net class is found, it retrieves the corresponding rule - /// from the class rules. If no class is associated, or if the class does not have a defined rule, + /// This function looks up the routing rule for a given net ID. It first checks if the net is + /// associated with a net class. If a net class is found, it retrieves the corresponding rule + /// from the class rules. If no class is associated, or if the class does not have a defined rule, /// it defaults to the general structure rule. /// pub fn get_rule(&self, net: usize) -> &SpecctraRule { diff --git a/src/specctra/read.rs b/src/specctra/read.rs index cc4ee45..130d219 100644 --- a/src/specctra/read.rs +++ b/src/specctra/read.rs @@ -38,26 +38,31 @@ pub struct InputToken { impl InputToken { pub fn new(token: ListToken, context: (usize, usize)) -> Self { - Self { - token, - context, - } + Self { token, context } } pub fn expect_start(self, name: &'static str) -> Result<(), ParseErrorContext> { - self.token.expect_start(name).map_err(|err| err.add_context(self.context)) + self.token + .expect_start(name) + .map_err(|err| err.add_context(self.context)) } pub fn expect_any_start(self) -> Result { - self.token.expect_any_start().map_err(|err| err.add_context(self.context)) + self.token + .expect_any_start() + .map_err(|err| err.add_context(self.context)) } pub fn expect_leaf(self) -> Result { - self.token.expect_leaf().map_err(|err| err.add_context(self.context)) + self.token + .expect_leaf() + .map_err(|err| err.add_context(self.context)) } pub fn expect_end(self) -> Result<(), ParseErrorContext> { - self.token.expect_end().map_err(|err| err.add_context(self.context)) + self.token + .expect_end() + .map_err(|err| err.add_context(self.context)) } } @@ -191,9 +196,7 @@ impl ListTokenizer { } } - fn map_context(&self, result: Result) - -> Result - { + fn map_context(&self, result: Result) -> Result { result.map_err(|err| self.add_context(err)) } @@ -215,7 +218,8 @@ impl ListTokenizer { Ok(if let Some(chr) = self.peeked_char { chr } else { - let chr = self.reader + let chr = self + .reader .read_char() .transpose() .ok_or(self.add_context(ParseError::Eof))? @@ -332,7 +336,10 @@ impl ListTokenizer { T::read_dsn(self) } - pub fn read_named>(&mut self, name: &'static str) -> Result { + pub fn read_named>( + &mut self, + name: &'static str, + ) -> Result { self.consume_token()?.expect_start(name)?; let value = self.read_value::()?; self.consume_token()?.expect_end()?; diff --git a/src/specctra/structure.rs b/src/specctra/structure.rs index 58d21a6..b9e6600 100644 --- a/src/specctra/structure.rs +++ b/src/specctra/structure.rs @@ -99,9 +99,7 @@ pub struct Structure { // custom impl to handle layers appearing late impl ReadDsn for Structure { - fn read_dsn( - tokenizer: &mut ListTokenizer, - ) -> Result { + fn read_dsn(tokenizer: &mut ListTokenizer) -> Result { let mut value = Self { layers: tokenizer.read_named_array("layer")?, boundary: tokenizer.read_named("boundary")?, @@ -111,7 +109,9 @@ impl ReadDsn for Structure { rules: tokenizer.read_named_array("rule")?, }; - value.layers.append(&mut tokenizer.read_named_array("layer")?); + value + .layers + .append(&mut tokenizer.read_named_array("layer")?); Ok(value) }