主要内容

Simulink.RustImporter Class

Namespace: Simulink

Import C compatible Rust code into Simulink

Since R2026a

Description

Add-On Required: This feature requires the Simulink Support Package for Rust Code add-on.

Use the Simulink.RustImporter class to import C compatible Rust® code into Simulink®. When you import Rust code into Simulink, you can simulate and test custom Rust logic alongside Simulink model components, enabling simulation between Simulink and Rust code. Instances of this class are used to specify external Rust code to import into Simulink.

The Simulink.RustImporter class is a handle class.

Creation

Description

rustObj = Simulink.RustImporter() creates an instance of the RustImporter class with the LibraryFileName property set to "untitled".

example

rustObj = Simulink.RustImporter(ModelName), where ModelName is the name of a Simulink library or model specified as a string or character vector, creates an instance of the RustImporter class with the LibraryFileName property set to ModelName.

Properties

expand all

Properties

Name of Simulink library file or model and generated artifacts created for the imported code, specified as a string or a character vector. The name must be a valid MATLAB® variable name. The same file-name is used with different extensions for the data dictionary and other artifacts generated when code is imported.

Example: "myLib"

Data Types: string | char

Location of generated library file or model and generated artifacts, specified as a string or a character vector. If left blank, the software uses the current MATLAB folder.

Example: "C:\myfolderpath\Output\generatedFiles"

Data Types: string | char

Path of the folder relative to the output folder containing the Cargo.toml file for the Rust code to be imported, specified as a string or character vector.

Example: "..\my_rust_code"

Data Types: string | char

Configuration that determines the Rust code compilation, optimization, and usage, specified as a string or character vector.

Example: "Debug"

Data Types: string | char

Additional options used by Rust Importer during import for library and test harness creation, specified as an object of class Simulink.RustImporter.Options. For information, see Simulink.RustImporter.Options.

rustObj.Options
ans = 

  Options with properties:

     CreateTestHarness: 1
    LibraryBrowserName: ""

Change the property values.

rustObj.Options.CreateTestHarness = 0;
rustObj.Options.LibraryBrowserName = "myLib";

Verify the changes.

rustObj.Options
ans = 

  Options with properties:

     CreateTestHarness: 0
    LibraryBrowserName: "myLib"

This property is read-only.

Information regarding the parsed Rust code, returned as an object of class Simulink.CodeImporter.ParseInfo. Parsing must be successful to obtain information regarding custom code. For information, see Simulink.CodeImporter.ParseInfo.

s = parse(rustObj);
rustObj.ParseInfo

Methods

expand all

Examples

collapse all

Import Rust code containing C compatible functions.

To use the Simulink.RustImporter class, you must:

  • Install Simulink Support Package for Rust Code. For more information, see Install Simulink Support Package for Rust Code.

  • After installing the support package, install cbindgen by entering this command in MATLAB Command Window:

    ! cargo install cbindgen

    After installation, you can verify that cbindgen is available in your system path by running this command.

    ! cbindgen --version

For information about the Rust code and Cargo.toml file used in this example, see Import C Compatible Rust Code into Simulink Using the Rust Importer Wizard.

Create an instance of the Simulink.RustImporter class.

 rustObj = Simulink.RustImporter();

Specify the Simulink library name that imports the Rust code and the output folder that stores the output Simulink library or model.

In this example, the C:\myfolderpath\Output has two subfolders: generatedFiles and my_rust_code. The generatedFiles folder contains the generated library or model and generated artifacts. The my_rust_code folder contains the Cargo.toml file.

Replace myfolderpath with your folder path.

rustObj.LibraryFileName = "myRustLib";
rustObj.OutputFolder = "C:\myfolderpath\Output\generatedFiles";

Specify the path of the folder containing Cargo.toml file relative to the output folder specified using the OutputFolder property.

rustObj.RustCrate = "..\my_rust_code";

Specify the option to generate a test harness.

rustObj.Options.CreateTestHarness = 1;

To parse the code, enter this command in the MATLAB Command Window from the C:\myfolderpath\Output\generatedFiles folder.

success = parse(rustObj);

Import parsed code. This step generates a Simulink library named myRustLib in the output folder you specified in an earlier step.

r = import(rustObj);

Version History

Introduced in R2026a