specctra: added scraped-examples

This commit is contained in:
hakki 2024-09-05 18:55:58 +02:00
parent c064490724
commit 46e935b9f6
4 changed files with 26 additions and 33 deletions

View File

@ -126,3 +126,6 @@ contracts = { path = "vendored/contracts" }
[build-dependencies] [build-dependencies]
clap_mangen = "0.2.23" clap_mangen = "0.2.23"
clap = {version="4.5.8", features = ["derive"] } clap = {version="4.5.8", features = ["derive"] }
[package.metadata.docs.rs]
cargo-args = ["-Zunstable-options", "-Zrustdoc-scrape-examples"]

0
examples/example.dsn Normal file
View File

22
examples/specctra.rs Normal file
View File

@ -0,0 +1,22 @@
use std::fs::File;
use std::io::BufReader;
use topola::autorouter::history::History;
use topola::autorouter::invoker::Command;
use topola::autorouter::invoker::Invoker;
use topola::autorouter::selection::PinSelection;
use topola::autorouter::Autorouter;
use topola::specctra::design::SpecctraDesign;
fn main() -> Result<(), std::io::Error> {
let design_file = File::open("example.dsn")?;
let mut design_bufread = BufReader::new(design_file);
let design = SpecctraDesign::load(design_bufread).unwrap();
let board = design.make_board();
let mut invoker = Invoker::new(Autorouter::new(board).unwrap());
let mut file = File::create("example.ses").unwrap();
design.write_ses(invoker.autorouter().board(), &mut file);
Ok(())
}

View File

@ -47,14 +47,6 @@ impl SpecctraDesign {
/// # Errors /// # Errors
/// ///
/// Returns a `LoadingError` if an I/O error occurs or if the file format is invalid. /// Returns a `LoadingError` if an I/O error occurs or if the file format is invalid.
///
/// # Examples
///
/// ```
/// let design_file = File::open("random_design.dsn").unwrap();
/// let design_bufread = BufReader::new(design_file);
/// let design = SpecctraDesign::load(design_bufread).unwrap();
/// ```
pub fn load(reader: impl std::io::BufRead) -> Result<SpecctraDesign, LoadingError> { pub fn load(reader: impl std::io::BufRead) -> Result<SpecctraDesign, LoadingError> {
let mut list_reader = ListTokenizer::new(reader); let mut list_reader = ListTokenizer::new(reader);
let dsn = list_reader.read_value::<DsnFile>()?; let dsn = list_reader.read_value::<DsnFile>()?;
@ -62,14 +54,7 @@ impl SpecctraDesign {
Ok(Self { pcb: dsn.pcb }) Ok(Self { pcb: dsn.pcb })
} }
/// Retrieves the name of the PCB design and return name of the PCB as a string slice. /// Retrieves the name of the PCB design and return name of the PCB as a string slice.
///
/// # Examples
///
/// FIXME add more detailed info
/// ```
/// let name = design.get_name();
/// ```
pub fn get_name(&self) -> &str { pub fn get_name(&self) -> &str {
&self.pcb.name &self.pcb.name
} }
@ -79,14 +64,6 @@ impl SpecctraDesign {
/// # Errors /// # Errors
/// ///
/// Returns an `std::io::Error` if an I/O error occurs while writing the SES file. /// Returns an `std::io::Error` if an I/O error occurs while writing the SES file.
///
/// # Examples
///
/// ```
/// let board = invoker.autorouter().board();
/// let mut writebuf = vec![];
/// design.write_ses(board, &mut writebuf);
/// ```
pub fn write_ses( pub fn write_ses(
&self, &self,
board: &Board<SpecctraMesadata>, board: &Board<SpecctraMesadata>,
@ -195,15 +172,6 @@ impl SpecctraDesign {
/// This method interprets the PCB design and generates a `Board<SpecctraMesadata>` object /// This method interprets the PCB design and generates a `Board<SpecctraMesadata>` object
/// containing the layout and associated Specctra mesadata . /// containing the layout and associated Specctra mesadata .
///
/// # Examples
///
/// ```
/// let design_file = File::open("random_file.dsn")?;
/// let mut design_bufread = BufReader::new(design_file);
/// let design = SpecctraDesign::load(design_bufread).unwrap();
/// let board = design.make_board();
/// ```
pub fn make_board(&self) -> Board<SpecctraMesadata> { pub fn make_board(&self) -> Board<SpecctraMesadata> {
let mesadata = SpecctraMesadata::from_pcb(&self.pcb); let mesadata = SpecctraMesadata::from_pcb(&self.pcb);
let mut board = Board::new(Layout::new(Drawing::new( let mut board = Board::new(Layout::new(Drawing::new(