Skip to main content

FootprintDocument

Struct FootprintDocument 

Source
pub struct FootprintDocument { /* private fields */ }

Implementations§

Source§

impl FootprintDocument

Source

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
Hide additional 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}
Source

pub fn ast_mut(&mut self) -> &mut FootprintAst

Source

pub fn set_lib_id<S: Into<String>>(&mut self, lib_id: S) -> &mut Self

Source

pub fn set_version(&mut self, version: i32) -> &mut Self

Source

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}
Source

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}
Source

pub fn set_layer<S: Into<String>>(&mut self, layer: S) -> &mut Self

Source

pub fn set_descr<S: Into<String>>(&mut self, descr: S) -> &mut Self

Source

pub fn set_tags<S: Into<String>>(&mut self, tags: S) -> &mut Self

Source

pub fn set_reference<S: Into<String>>(&mut self, value: S) -> &mut Self

Source

pub fn set_value<S: Into<String>>(&mut self, value: S) -> &mut Self

Source

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}
Source

pub fn remove_property(&mut self, key: &str) -> &mut Self

Source

pub fn cst(&self) -> &CstDocument

Source

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}
Source

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}
Source

pub fn write_mode<P: AsRef<Path>>( &self, path: P, mode: WriteMode, ) -> Result<(), Error>

Trait Implementations§

Source§

impl Clone for FootprintDocument

Source§

fn clone(&self) -> FootprintDocument

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
Source§

impl Debug for FootprintDocument

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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> 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.