pub struct ReferenceFmus { /* private fields */ }
Expand description
A Rust interface to the Modelica Reference-FMUs, downloaded as an archive using fetch_data
This struct provides access to the official Modelica Reference FMUs for testing and validation purposes. It automatically downloads the FMU archive from the official GitHub repository and provides methods to access individual FMUs.
§Examples
use fmi_test_data::ReferenceFmus;
use fmi::traits::FmiImport;
let mut reference_fmus = ReferenceFmus::new()?;
// Load a specific FMU
let fmu: fmi::fmi3::import::Fmi3Import = reference_fmus.get_reference_fmu("BouncingBall")?;
// List all available FMUs
let available_fmus = reference_fmus.list_available_fmus()?;
println!("Available FMUs: {:?}", available_fmus);
Implementations§
Source§impl ReferenceFmus
impl ReferenceFmus
Sourcepub fn new() -> Result<Self>
pub fn new() -> Result<Self>
Fetch the released Modelica Reference-FMUs file
Downloads and caches the Reference FMUs archive from the official GitHub repository. The archive is automatically verified using SHA256 checksums.
§Errors
Returns an error if:
- The download fails
- The file cannot be opened
- The ZIP archive is corrupted
Sourcepub fn get_reference_fmu<Imp: FmiImport>(&mut self, name: &str) -> Result<Imp>
pub fn get_reference_fmu<Imp: FmiImport>(&mut self, name: &str) -> Result<Imp>
Get a reference FMU as an import instance
Loads a specific FMU from the archive and returns it as the requested import type. The FMU version is automatically determined by the import type.
§Arguments
name
- The name of the FMU to load (e.g., “BouncingBall”)
§Examples
let mut reference_fmus = ReferenceFmus::new()?;
// Load FMI 2.0 version
let fmu: fmi::fmi2::import::Fmi2Import = reference_fmus.get_reference_fmu("BouncingBall")?;
// Load FMI 3.0 version
let fmu: fmi::fmi3::import::Fmi3Import = reference_fmus.get_reference_fmu("BouncingBall")?;
Sourcepub fn extract_reference_fmu(
&mut self,
name: &str,
version: MajorVersion,
) -> Result<NamedTempFile>
pub fn extract_reference_fmu( &mut self, name: &str, version: MajorVersion, ) -> Result<NamedTempFile>
Extract a reference FMU from the reference archive into a temporary file
This method extracts an FMU to a temporary file on disk, which can be useful when you need to pass a file path to other tools or libraries.
§Arguments
name
- The name of the FMU to extractversion
- The FMI major version to extract
§Returns
A NamedTempFile
containing the extracted FMU. The file will be automatically
deleted when the returned value is dropped.
Sourcepub fn list_available_fmus(&mut self) -> Result<Vec<String>>
pub fn list_available_fmus(&mut self) -> Result<Vec<String>>
Get a list of all available FMU files in the archive
Returns a sorted list of all FMU names available in the Reference FMUs archive.
These names can be used with get_reference_fmu()
or extract_reference_fmu()
.
§Examples
let mut reference_fmus = ReferenceFmus::new()?;
let fmus = reference_fmus.list_available_fmus()?;
for fmu_name in &fmus {
println!("Available: {}", fmu_name);
}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ReferenceFmus
impl RefUnwindSafe for ReferenceFmus
impl Send for ReferenceFmus
impl Sync for ReferenceFmus
impl Unpin for ReferenceFmus
impl UnwindSafe for ReferenceFmus
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more