Getting Started with Rust Plugins
This guide shows the smallest useful Rust reader plugin: it registers a file format, describes its capabilities, and creates a simple drawing when LinkCAD imports a file.
Crate Setup
A LinkCAD Rust plugin is a native library. In a LinkCAD plugin workspace, configure the plugin crate as a cdylib and depend on the LinkCAD plugin crates supplied by the SDK or source tree:
[lib]crate-type = ["cdylib", "rlib"]
[dependencies]lc-plugin = { path = "../lc-plugin" }lc-types = { path = "../lc-types" }Use the dependency paths or package references that match your SDK layout.
Minimal Reader
use lc_plugin::builder::DrawingBuilder;use lc_plugin::format::{Format, FormatAttributes, FormatDescriptor};use lc_plugin::{EndCap, Reader};use lc_types::Point;
#[derive(Default)]struct ExampleReader;
impl FormatDescriptor for ExampleReader { fn describe_format(&self, fmt: &mut Format) { fmt.set_attributes(FormatAttributes::LAYER_NAMES | FormatAttributes::CELL_NAMES); fmt.set_file_name_extension("exa"); }}
impl Reader for ExampleReader { fn parse_file( &mut self, _path: &str, builder: &mut DrawingBuilder, _file_size: i64, _current_file: i32, _file_count: i32, ) -> bool { builder.set_drawing_name("Example import"); builder.open_cell_by_name("TOP", true, false); builder.select_layer_by_name("L1");
builder.create_rectangle(Point::new(0, 0), Point::new(1000, 1000)); builder.create_polyline( 25, &[Point::new(0, 0), Point::new(1000, 1000)], false, EndCap::Round, );
builder.close_cell(); true }}
lc_plugin::register_reader! { name: "Example Rust Reader", extensions: "*.exa", license: 0, create: || Box::new(ExampleReader::default()),}Error Handling
Return false when import or export cannot continue. Log messages through the controller’s event log so users see actionable diagnostics in LinkCAD:
builder.log().error("Could not read the example file header");return false;Keep plugin code panic-free at the host boundary. The lc-plugin wrappers are designed for explicit return values and logged diagnostics.
Build and Load
- Build the plugin for the same platform and architecture as LinkCAD.
- Copy the resulting dynamic library (
.dllon Windows,.soon Linux) into a LinkCAD plugin directory. - Restart LinkCAD and import a file whose extension matches the registered
extensionspattern.
For export support, implement the Writer trait and register it with lc_plugin::register_writer! or use lc_plugin::register_format! for a combined reader/writer plugin.