pub struct SymbolLibFile;Implementations§
Source§impl SymbolLibFile
impl SymbolLibFile
Sourcepub fn read<P: AsRef<Path>>(path: P) -> Result<SymbolLibDocument, Error>
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
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§
impl Freeze for SymbolLibFile
impl RefUnwindSafe for SymbolLibFile
impl Send for SymbolLibFile
impl Sync for SymbolLibFile
impl Unpin for SymbolLibFile
impl UnsafeUnpin for SymbolLibFile
impl UnwindSafe for SymbolLibFile
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more