AutosarModel

Struct AutosarModel 

Source
pub struct AutosarModel(/* private fields */);
Expand description

AutosarModel is the top level data type in the autosar-data crate.

An instance of AutosarModel is required for all other operations.

The model contains the hierarchy of Autosar elements. It can be created manually or loaded from one or more arxml files. It stores the association between elements and files. In addition, this top-level structure provides caching of Autosar paths, to allow quick resolution of cross-references.

Implementations§

Source§

impl AutosarModel

Source

pub fn new() -> AutosarModel

Create an AutosarData model

Initially it contains no arxml files and only has a default <AUTOSAR> element

§Example
let model = AutosarModel::new();
Source

pub fn create_file<P: AsRef<Path>>( &self, filename: P, version: AutosarVersion, ) -> Result<ArxmlFile, AutosarDataError>

Create a new ArxmlFile inside this AutosarData structure

You must provide a filename for the ArxmlFile, even if you do not plan to write the data to disk. You must also specify an AutosarVersion. All methods manipulation the data insdie the file will ensure conformity with the version specified here. The newly created ArxmlFile will be created with a root AUTOSAR element.

§Parameters
  • filename: A filename for the data from the buffer. It must be unique within the model. It will be used by write(), and is also used to identify this data in error messages.
  • version: The AutosarVersion that will be used by the data created inside this file
§Example
let model = AutosarModel::new();
let file = model.create_file("filename.arxml", AutosarVersion::Autosar_00050)?;
§Errors
Source

pub fn load_buffer<P: AsRef<Path>>( &self, buffer: &[u8], filename: P, strict: bool, ) -> Result<(ArxmlFile, Vec<AutosarDataError>), AutosarDataError>

Load a named buffer containing arxml data

If you have e.g. received arxml data over a network, or decompressed it from an archive, etc, then you may load it with this method.

§Parameters:
  • buffer: The data inside the buffer must be valid utf-8. Optionally it may begin with a UTF-8-BOM, which will be silently ignored.
  • filename: the original filename of the data, or a newly generated name that is unique within the AutosarData instance.
  • strict: toggle strict parsing. Some parsing errors are recoverable and can be issued as warnings.

This method may be called concurrently on multiple threads to load different buffers

§Example
let model = AutosarModel::new();
model.load_buffer(buffer, "filename.arxml", true)?;
§Errors
Source

pub fn load_file<P: AsRef<Path>>( &self, filename: P, strict: bool, ) -> Result<(ArxmlFile, Vec<AutosarDataError>), AutosarDataError>

Load an arxml file

This function is a wrapper around load_buffer to make the common case of loading a file from disk more convenient

§Parameters:
  • filename: the original filename of the data, or a newly generated name that is unique within the AutosarData instance.
  • strict: toggle strict parsing. Some parsing errors are recoverable and can be issued as warnings.
§Example
let model = AutosarModel::new();
model.load_file("filename.arxml", true)?;
§Errors
Source

pub fn remove_file(&self, file: &ArxmlFile)

remove a file from the model

§Parameters:
  • file: The file that will be removed from the model
§Example
let model = AutosarModel::new();
let file = model.create_file("filename.arxml", AutosarVersion::Autosar_00050)?;
model.remove_file(&file);
Source

pub fn serialize_files(&self) -> HashMap<PathBuf, String>

serialize each of the files in the model

returns the result in a HashMap of <file_name, file_content>

§Example
let model = AutosarModel::new();
for (pathbuf, file_content) in model.serialize_files() {
    // do something with it
}
Source

pub fn write(&self) -> Result<(), AutosarDataError>

write all files in the model

This is a wrapper around serialize_files. The current filename of each file will be used to write the serialized data.

If any of the individual files cannot be written, then write() will abort and return the error. This may result in a situation where some files have been written and others have not.

§Example
let model = AutosarModel::new();
// load or create files
model.write()?;
§Errors
Source

pub fn files(&self) -> ArxmlFileIterator

create an iterator over all ArxmlFiles in this AutosarData object

§Example
let model = AutosarModel::new();
// load or create files
for file in model.files() {
    // do something with the file
}
Source

pub fn root_element(&self) -> Element

Get a reference to the root <AUTOSAR ...> element of this model

§Example
let autosar_element = model.root_element();
Source

pub fn get_element_by_path(&self, path: &str) -> Option<Element>

get a named element by its Autosar path

This is a lookup in a hash table and runs in O(1) time

§Parameters
  • path: The Autosar path to look up
§Example
let model = AutosarModel::new();
// [...]
if let Some(element) = model.get_element_by_path("/Path/To/Element") {
    // use the element
}
Source

pub fn duplicate(&self) -> Result<AutosarModel, AutosarDataError>

Duplicate the model

This creates a second, fully independent model. The original model and the duplicate are not linked in any way and can be modified independently.

§Example
let model = AutosarModel::new();
// [...]
let model_copy = model.duplicate()?;
assert!(model != model_copy);
§Errors
Source

pub fn elements_dfs(&self) -> ElementsDfsIterator

create a depth-first iterator over all Elements in the model

The iterator returns all elements from the merged model, consisting of data from all arxml files loaded in this model.

Directly printing the return values could show something like this:

0: AUTOSAR
1: AR-PACKAGES
2: AR-PACKAGE
...
2: AR-PACKAGE
§Example
for (depth, element) in model.elements_dfs() {
    // [...]
}
Source

pub fn elements_dfs_with_max_depth( &self, max_depth: usize, ) -> ElementsDfsIterator

Create a depth first iterator over all Elements in this model, up to a maximum depth

The iterator returns all elements from the merged model, consisting of data from all arxml files loaded in this model.

§Example
for (depth, elem) in model.elements_dfs_with_max_depth(1) {
    assert!(depth <= 1);
    // ...
}
Source

pub fn sort(&self)

Recursively sort all elements in the model. This is exactly identical to calling sort() on the root element of the model.

All sub elements of the root element are sorted alphabetically. If the sub-elements are named, then the sorting is performed according to the item names, otherwise the serialized form of the sub-elements is used for sorting.

Element attributes are not taken into account while sorting. The elements are sorted in place, and sorting cannot fail, so there is no return value.

§Example
model.sort();
Source

pub fn identifiable_elements(&self) -> IdentifiablesIterator

Create an iterator over the list of the Autosar paths of all identifiable elements

The list contains the full Autosar path of each element. It is not sorted.

§Example
for (path, _) in model.identifiable_elements() {
    let element = model.get_element_by_path(&path).unwrap();
    // [...]
}
Source

pub fn get_references_to(&self, target_path: &str) -> Vec<WeakElement>

return all elements referring to the given target path

It returns WeakElements which must be upgraded to get usable Elements.

This is effectively the reverse operation of get_element_by_path()

§Parameters
  • target_path: The path whose references should be returned
§Example
for weak_element in model.get_references_to("/Path/To/Element") {
    // [...]
}
Source

pub fn check_references(&self) -> Vec<WeakElement>

check all Autosar path references and return a list of elements with invalid references

For each reference: The target must exist and the DEST attribute must correctly specify the type of the target

If no references are invalid, then the return value is an empty list

§Example
for broken_ref_weak in model.check_references() {
    if let Some(broken_ref) = broken_ref_weak.upgrade() {
        // update or delete ref?
    }
}

Trait Implementations§

Source§

impl Clone for AutosarModel

Source§

fn clone(&self) -> AutosarModel

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AutosarModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for AutosarModel

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Hash for AutosarModel

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for AutosarModel

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for AutosarModel

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.