PLACover

Struct PLACover 

Source
pub struct PLACover { /* private fields */ }
Expand description

A cover with dynamic dimensions (from PLA files)

Use this when loading PLA files where dimensions are not known at compile time. Outputs are Option<bool>: Some(true)=1, Some(false)=0, None=don’t-care

Implementations§

Source§

impl PLACover

Source

pub fn new(num_inputs: usize, num_outputs: usize) -> Self

Create a new empty cover with specified dimensions

Source

pub fn from_pla_file<P: AsRef<Path>>(path: P) -> Result<Self>

Load a cover from a PLA format file

The dimensions are determined from the PLA file.

Examples found in repository?
examples/pla_file.rs (line 43)
11fn main() {
12    println!("=== PLA File Minimization Example ===\n");
13
14    // Create a sample PLA file
15    let pla_content = r#".i 4
16.o 1
17.ilb a b c d
18.ob f
19.p 8
200000 1
210001 1
220010 1
230011 1
240100 1
250101 1
260110 1
270111 1
28.e
29"#;
30
31    println!("Sample PLA content:");
32    println!("{}", pla_content);
33
34    // Write to a temporary file
35    let mut temp_in = NamedTempFile::new().expect("Failed to create temp file");
36    temp_in
37        .write_all(pla_content.as_bytes())
38        .expect("Failed to write temp file");
39    temp_in.flush().expect("Failed to flush temp file");
40
41    // Read the PLA file
42    println!("\nReading PLA file...");
43    let mut cover = match PLACover::from_pla_file(temp_in.path()) {
44        Ok(c) => c,
45        Err(e) => {
46            eprintln!("Error reading PLA: {}", e);
47            return;
48        }
49    };
50
51    println!("PLA loaded successfully!");
52    println!("\nOriginal cover:");
53    println!("  Inputs:  {}", cover.num_inputs());
54    println!("  Outputs: {}", cover.num_outputs());
55    println!("  Cubes:   {}", cover.num_cubes());
56
57    // Minimize using the Cover trait
58    println!("\nMinimizing using Espresso...");
59    if let Err(e) = cover.minimize() {
60        eprintln!("Error minimizing: {}", e);
61        return;
62    }
63
64    println!("\nMinimized cover:");
65    println!("  Inputs:  {}", cover.num_inputs());
66    println!("  Outputs: {}", cover.num_outputs());
67    println!("  Cubes:   {}", cover.num_cubes());
68
69    // Show the minimized PLA
70    match cover.to_pla_string(PLAType::F) {
71        Ok(pla_str) => {
72            println!("\nMinimized PLA:");
73            println!("{}", pla_str);
74        }
75        Err(e) => eprintln!("Error generating PLA: {}", e),
76    }
77
78    // Write to output file if requested
79    if let Some(output_path) = env::args().nth(1) {
80        println!("Writing minimized PLA to: {}", output_path);
81        match cover.to_pla_file(&output_path, PLAType::F) {
82            Ok(_) => println!("Successfully wrote output file!"),
83            Err(e) => eprintln!("Error writing output: {}", e),
84        }
85    } else {
86        println!("\nTo write output to a file, run:");
87        println!("cargo run --example pla_file output.pla");
88    }
89}
Source

pub fn from_pla_content(content: &str) -> Result<Self>

Load a cover from PLA format string

The dimensions are determined from the PLA content.

Trait Implementations§

Source§

impl Clone for PLACover

Source§

fn clone(&self) -> PLACover

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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> Cover for T
where T: Minimizable + PLASerializable,

Source§

fn num_inputs(&self) -> usize

Get the number of inputs
Source§

fn num_outputs(&self) -> usize

Get the number of outputs
Source§

fn num_cubes(&self) -> usize

Get the number of cubes (for F/FD types, only counts F cubes; for FR/FDR, counts all)
Source§

fn cover_type(&self) -> PLAType

Get the cover type (F, FD, FR, or FDR)
Source§

fn cubes_iter<'a>( &'a self, ) -> Box<dyn Iterator<Item = (Vec<Option<bool>>, Vec<Option<bool>>)> + 'a>

Iterate over cubes (inputs, outputs) Returns cubes in same format as add_cube takes (owned vecs for easy use)
Source§

fn minimize(&mut self) -> Result<(), Error>

Minimize this cover in-place using default configuration
Source§

fn minimize_with_config(&mut self, config: &EspressoConfig) -> Result<(), Error>

Minimize this cover in-place with custom configuration
Source§

fn to_pla_string(&self, pla_type: PLAType) -> Result<String, Error>

Write this cover to PLA format string
Source§

fn to_pla_file<P>(&self, path: P, pla_type: PLAType) -> Result<(), Error>
where P: AsRef<Path>,

Write this cover to a PLA file
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 = Infallible

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

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

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.