pub struct FootprintDocument { /* private fields */ }Implementations§
Source§impl FootprintDocument
impl FootprintDocument
Sourcepub fn ast(&self) -> &FootprintAst
pub fn ast(&self) -> &FootprintAst
Examples found in repository?
examples/footprint_roundtrip.rs (line 25)
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 = FootprintFile::read(&in_path).map_err(|e| e.to_string())?;
16 doc.set_generator("kiutils")
17 .set_generator_version("roundtrip-demo")
18 .upsert_property("EditedBy", "kiutils_kicad/examples/footprint_roundtrip.rs");
19
20 doc.write(&out_path).map_err(|e| e.to_string())?;
21
22 let reread = FootprintFile::read(&out_path).map_err(|e| e.to_string())?;
23 println!("input: {}", in_path.display());
24 println!("output: {}", out_path.display());
25 println!("lib_id: {:?}", reread.ast().lib_id);
26 println!("properties: {}", reread.ast().property_count);
27 println!("unknown_nodes: {}", reread.ast().unknown_nodes.len());
28 println!("diagnostics: {}", reread.diagnostics().len());
29
30 Ok(())
31}More examples
examples/read_all.rs (line 18)
8fn main() -> Result<(), Box<dyn std::error::Error>> {
9 let base = PathBuf::from(env!("CARGO_MANIFEST_DIR"))
10 .join("examples")
11 .join("data");
12
13 let pcb = PcbFile::read(base.join("sample.kicad_pcb"))?;
14 println!("pcb version: {:?}", pcb.ast().version);
15 println!("pcb unknown nodes: {}", pcb.ast().unknown_nodes.len());
16
17 let footprint = FootprintFile::read(base.join("sample.kicad_mod"))?;
18 println!("footprint version: {:?}", footprint.ast().version);
19
20 let schematic = SchematicFile::read(base.join("sample.kicad_sch"))?;
21 println!("schematic version: {:?}", schematic.ast().version);
22 println!(
23 "schematic unknown nodes: {}",
24 schematic.ast().unknown_nodes.len()
25 );
26
27 let table = FpLibTableFile::read(base.join("fp-lib-table"))?;
28 println!("fp libs: {}", table.ast().library_count);
29
30 let sym_table = SymLibTableFile::read(base.join("sym-lib-table"))?;
31 println!("sym libs: {}", sym_table.ast().library_count);
32
33 let dru = DesignRulesFile::read(base.join("sample.kicad_dru"))?;
34 println!("rules: {}", dru.ast().rule_count);
35 println!("rule constraints: {}", dru.ast().total_constraint_count);
36
37 let project = ProjectFile::read(base.join("sample.kicad_pro"))?;
38 println!("project meta version: {:?}", project.ast().meta_version);
39
40 let worksheet = WorksheetFile::read(base.join("sample.kicad_wks"))?;
41 println!("worksheet version: {:?}", worksheet.ast().version);
42 println!("worksheet tbtext count: {}", worksheet.ast().tbtext_count);
43
44 pcb.write_mode("/tmp/out.kicad_pcb", WriteMode::Lossless)?;
45 Ok(())
46}pub fn ast_mut(&mut self) -> &mut FootprintAst
pub fn set_lib_id<S: Into<String>>(&mut self, lib_id: S) -> &mut Self
pub fn set_version(&mut self, version: i32) -> &mut Self
Sourcepub fn set_generator<S: Into<String>>(&mut self, generator: S) -> &mut Self
pub fn set_generator<S: Into<String>>(&mut self, generator: S) -> &mut Self
Examples found in repository?
examples/footprint_roundtrip.rs (line 16)
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 = FootprintFile::read(&in_path).map_err(|e| e.to_string())?;
16 doc.set_generator("kiutils")
17 .set_generator_version("roundtrip-demo")
18 .upsert_property("EditedBy", "kiutils_kicad/examples/footprint_roundtrip.rs");
19
20 doc.write(&out_path).map_err(|e| e.to_string())?;
21
22 let reread = FootprintFile::read(&out_path).map_err(|e| e.to_string())?;
23 println!("input: {}", in_path.display());
24 println!("output: {}", out_path.display());
25 println!("lib_id: {:?}", reread.ast().lib_id);
26 println!("properties: {}", reread.ast().property_count);
27 println!("unknown_nodes: {}", reread.ast().unknown_nodes.len());
28 println!("diagnostics: {}", reread.diagnostics().len());
29
30 Ok(())
31}Sourcepub fn set_generator_version<S: Into<String>>(
&mut self,
generator_version: S,
) -> &mut Self
pub fn set_generator_version<S: Into<String>>( &mut self, generator_version: S, ) -> &mut Self
Examples found in repository?
examples/footprint_roundtrip.rs (line 17)
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 = FootprintFile::read(&in_path).map_err(|e| e.to_string())?;
16 doc.set_generator("kiutils")
17 .set_generator_version("roundtrip-demo")
18 .upsert_property("EditedBy", "kiutils_kicad/examples/footprint_roundtrip.rs");
19
20 doc.write(&out_path).map_err(|e| e.to_string())?;
21
22 let reread = FootprintFile::read(&out_path).map_err(|e| e.to_string())?;
23 println!("input: {}", in_path.display());
24 println!("output: {}", out_path.display());
25 println!("lib_id: {:?}", reread.ast().lib_id);
26 println!("properties: {}", reread.ast().property_count);
27 println!("unknown_nodes: {}", reread.ast().unknown_nodes.len());
28 println!("diagnostics: {}", reread.diagnostics().len());
29
30 Ok(())
31}pub fn set_layer<S: Into<String>>(&mut self, layer: S) -> &mut Self
pub fn set_descr<S: Into<String>>(&mut self, descr: S) -> &mut Self
pub fn set_reference<S: Into<String>>(&mut self, value: S) -> &mut Self
pub fn set_value<S: Into<String>>(&mut self, value: S) -> &mut Self
Sourcepub fn upsert_property<K: Into<String>, V: Into<String>>(
&mut self,
key: K,
value: V,
) -> &mut Self
pub fn upsert_property<K: Into<String>, V: Into<String>>( &mut self, key: K, value: V, ) -> &mut Self
Examples found in repository?
examples/footprint_roundtrip.rs (line 18)
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 = FootprintFile::read(&in_path).map_err(|e| e.to_string())?;
16 doc.set_generator("kiutils")
17 .set_generator_version("roundtrip-demo")
18 .upsert_property("EditedBy", "kiutils_kicad/examples/footprint_roundtrip.rs");
19
20 doc.write(&out_path).map_err(|e| e.to_string())?;
21
22 let reread = FootprintFile::read(&out_path).map_err(|e| e.to_string())?;
23 println!("input: {}", in_path.display());
24 println!("output: {}", out_path.display());
25 println!("lib_id: {:?}", reread.ast().lib_id);
26 println!("properties: {}", reread.ast().property_count);
27 println!("unknown_nodes: {}", reread.ast().unknown_nodes.len());
28 println!("diagnostics: {}", reread.diagnostics().len());
29
30 Ok(())
31}pub fn remove_property(&mut self, key: &str) -> &mut Self
pub fn cst(&self) -> &CstDocument
Sourcepub fn diagnostics(&self) -> &[Diagnostic]
pub fn diagnostics(&self) -> &[Diagnostic]
Examples found in repository?
examples/footprint_roundtrip.rs (line 28)
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 = FootprintFile::read(&in_path).map_err(|e| e.to_string())?;
16 doc.set_generator("kiutils")
17 .set_generator_version("roundtrip-demo")
18 .upsert_property("EditedBy", "kiutils_kicad/examples/footprint_roundtrip.rs");
19
20 doc.write(&out_path).map_err(|e| e.to_string())?;
21
22 let reread = FootprintFile::read(&out_path).map_err(|e| e.to_string())?;
23 println!("input: {}", in_path.display());
24 println!("output: {}", out_path.display());
25 println!("lib_id: {:?}", reread.ast().lib_id);
26 println!("properties: {}", reread.ast().property_count);
27 println!("unknown_nodes: {}", reread.ast().unknown_nodes.len());
28 println!("diagnostics: {}", reread.diagnostics().len());
29
30 Ok(())
31}Sourcepub fn write<P: AsRef<Path>>(&self, path: P) -> Result<(), Error>
pub fn write<P: AsRef<Path>>(&self, path: P) -> Result<(), Error>
Examples found in repository?
examples/footprint_roundtrip.rs (line 20)
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 = FootprintFile::read(&in_path).map_err(|e| e.to_string())?;
16 doc.set_generator("kiutils")
17 .set_generator_version("roundtrip-demo")
18 .upsert_property("EditedBy", "kiutils_kicad/examples/footprint_roundtrip.rs");
19
20 doc.write(&out_path).map_err(|e| e.to_string())?;
21
22 let reread = FootprintFile::read(&out_path).map_err(|e| e.to_string())?;
23 println!("input: {}", in_path.display());
24 println!("output: {}", out_path.display());
25 println!("lib_id: {:?}", reread.ast().lib_id);
26 println!("properties: {}", reread.ast().property_count);
27 println!("unknown_nodes: {}", reread.ast().unknown_nodes.len());
28 println!("diagnostics: {}", reread.diagnostics().len());
29
30 Ok(())
31}pub fn write_mode<P: AsRef<Path>>( &self, path: P, mode: WriteMode, ) -> Result<(), Error>
Trait Implementations§
Source§impl Clone for FootprintDocument
impl Clone for FootprintDocument
Source§fn clone(&self) -> FootprintDocument
fn clone(&self) -> FootprintDocument
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for FootprintDocument
impl RefUnwindSafe for FootprintDocument
impl Send for FootprintDocument
impl Sync for FootprintDocument
impl Unpin for FootprintDocument
impl UnsafeUnpin for FootprintDocument
impl UnwindSafe for FootprintDocument
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