Skip to main content

SymbolLibFile

Struct SymbolLibFile 

Source
pub struct SymbolLibFile;

Implementations§

Source§

impl SymbolLibFile

Source

pub fn read<P: AsRef<Path>>(path: P) -> Result<SymbolLibDocument, Error>

Examples found in repository?
examples/symbol_roundtrip.rs (line 15)
10fn main() -> Result<(), String> {
11    let mut args = env::args().skip(1);
12    let in_path = args.next().map(PathBuf::from).ok_or_else(usage)?;
13    let out_path = args.next().map(PathBuf::from).ok_or_else(usage)?;
14
15    let mut doc = SymbolLibFile::read(&in_path).map_err(|e| e.to_string())?;
16    doc.set_generator("kiutils")
17        .set_generator_version("roundtrip-demo");
18
19    if let Some(first_name) = doc.ast().symbols.first().and_then(|s| s.name.clone()) {
20        let renamed = format!("{first_name}_Edited");
21        doc.rename_symbol(&first_name, renamed.clone())
22            .upsert_symbol_property(
23                &renamed,
24                "EditedBy",
25                "kiutils_kicad/examples/symbol_roundtrip.rs",
26            );
27    }
28
29    doc.write(&out_path).map_err(|e| e.to_string())?;
30
31    let reread = SymbolLibFile::read(&out_path).map_err(|e| e.to_string())?;
32    println!("input: {}", in_path.display());
33    println!("output: {}", out_path.display());
34    println!("symbol_count: {}", reread.ast().symbol_count);
35    println!("total_pin_count: {}", reread.ast().total_pin_count);
36    println!("unknown_nodes: {}", reread.ast().unknown_nodes.len());
37    println!("diagnostics: {}", reread.diagnostics().len());
38
39    Ok(())
40}
More examples
Hide additional examples
examples/symbol_corpus_roundtrip.rs (line 54)
24fn main() -> Result<(), String> {
25    let mut args = std::env::args().skip(1);
26    let input_dir = args.next().map(PathBuf::from).ok_or_else(usage)?;
27    let output_dir = args.next().map(PathBuf::from).ok_or_else(usage)?;
28
29    let mut files = Vec::new();
30    collect_symbol_files(&input_dir, &mut files)?;
31    files.sort();
32
33    if files.is_empty() {
34        return Err(format!(
35            "no .kicad_sym files found under {}",
36            input_dir.display()
37        ));
38    }
39
40    let mut ok = 0usize;
41    let mut failed = 0usize;
42
43    for path in files {
44        let rel = path
45            .strip_prefix(&input_dir)
46            .map_err(|e| format!("strip_prefix {}: {e}", path.display()))?;
47        let out_path = output_dir.join(rel);
48        if let Some(parent) = out_path.parent() {
49            fs::create_dir_all(parent)
50                .map_err(|e| format!("create_dir_all {}: {e}", parent.display()))?;
51        }
52
53        let result = (|| -> Result<(), String> {
54            let doc = SymbolLibFile::read(&path).map_err(|e| format!("read: {e}"))?;
55            doc.write(&out_path).map_err(|e| format!("write: {e}"))?;
56            let _ = SymbolLibFile::read(&out_path).map_err(|e| format!("reread: {e}"))?;
57            Ok(())
58        })();
59
60        match result {
61            Ok(()) => {
62                ok += 1;
63                println!("ok: {}", path.display());
64            }
65            Err(err) => {
66                failed += 1;
67                eprintln!("fail: {} -> {}", path.display(), err);
68            }
69        }
70    }
71
72    println!("summary: ok={ok} failed={failed}");
73    if failed > 0 {
74        return Err(format!("{failed} files failed"));
75    }
76    Ok(())
77}

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> 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, 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.