주요 콘텐츠

import

Class: Simulink.RustImporter
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.

success = import(rustObj), where rustObj is an object of class Simulink.RustImporter, parses the specified Rust® code and imports it into Simulink® with default import options. If the Rust code was not previously parsed or if the code has changed since the code was parsed, then the ParseInfo property of rustObj is populated or repopulated with the information resulting from the parse.

success = import(rustObj, Name1 = Value1,...,NameN = ValueN) parses the specified Rust code and imports it into Simulink with options based on the specified name-value arguments.

example

Input Arguments

expand all

Rust Importer object, specified as a handle to a Simulink.RustImporter object.

Name-Value Arguments

expand all

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: import(rustObj, Functions = ["add"]);

Functions to import, specified as a cell array of character vectors or a string array. Specify this argument to limit import to the named Rust code functions. Otherwise, all available custom code functions or all available entry-point Rust code functions are imported.

Data Types: char | string

Option to overwrite existing Simulink library with the same name as the name specified in the LibraryFileName property, specified as 'On' or 'Off'. If set to 'Off' and an existing Simulink library has the same name, Rust code is imported into the existing library without changing block settings applied in the library after previous imports of Rust code. If set to 'On', the existing library is overwritten by the library created from the Rust code import, and any prior changes to the existing library are lost. If no existing Simulink library has the same name, a new library is created.

Data Types: char | string

Additional types to import, specified as a cell array of character vectors or a string array. All types required by the imported functions are imported. Additional types are defined in the interface headers.

Data Types: char | string

Output Arguments

expand all

Indicator of whether import is successful, returned as a logical scalar. Simulink issues an exception if the import is unsuccessful.

Examples

expand all

Import Rust code containing C compatible functions.

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.

parse(rustObj);

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

import(rustObj);

Version History

Introduced in R2026a