主要内容

parse

Class: Simulink.RustImporter
Namespace: Simulink

Analyze Rust code for functions

Since R2026a

Description

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

success = parse(rustObj), where rustObj is an object of Simulink.RustImporter class, parses Rust® code, but does not parse the code again if the code has been parsed previously and neither the code nor the settings have changed since the previous parse. Results of a successful parse or error information from an unsuccessful parse are stored in the ParseInfo property of rustObj.

success = parse(rustObj, 'Force','On') parses Rust code irrespective of whether any changes have been made since a previous parse.

success = parse(rustObj, 'Force','Off') has the same effect as success = parse(rustObj).

example

Output Arguments

expand all

Indicator of whether parsing is successful, returned as a logical scalar. Simulink® throws an exception if parsing 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);
rustObj.ParseInfo
ans = 

  ParseInfo with properties:

               Success: 1
    AvailableFunctions: ["add"    "add_one_to_each"    "calculate_perimeter"    "sum_array"]
        EntryFunctions: ["add"    "add_one_to_each"    "calculate_perimeter"    "sum_array"]
        AvailableTypes: "Rectangle"
                Errors: []
             BuildInfo: [1×1 Simulink.CodeImporter.BuildInfo]

Version History

Introduced in R2026a