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
impl AutosarModel
Sourcepub fn new() -> AutosarModel
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();Sourcepub fn create_file<P: AsRef<Path>>(
&self,
filename: P,
version: AutosarVersion,
) -> Result<ArxmlFile, AutosarDataError>
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 bywrite(), and is also used to identify this data in error messages.version: TheAutosarVersionthat 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
AutosarDataError::DuplicateFilenameError: The model already contains a file with this filename
Sourcepub fn load_buffer<P: AsRef<Path>>(
&self,
buffer: &[u8],
filename: P,
strict: bool,
) -> Result<(ArxmlFile, Vec<AutosarDataError>), AutosarDataError>
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 theAutosarDatainstance.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
AutosarDataError::DuplicateFilenameError: The model already contains a file with this filenameAutosarDataError::OverlappingDataError: The new data contains Autosar paths that are already defined by the existing dataAutosarDataError::ParserError: The parser detected an error; the source field gives further details
Sourcepub fn load_file<P: AsRef<Path>>(
&self,
filename: P,
strict: bool,
) -> Result<(ArxmlFile, Vec<AutosarDataError>), AutosarDataError>
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 theAutosarDatainstance.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
AutosarDataError::IoErrorRead: There was an error while reading the fileAutosarDataError::DuplicateFilenameError: The model already contains a file with this filenameAutosarDataError::OverlappingDataError: The new data contains Autosar paths that are already defined by the existing dataAutosarDataError::ParserError: The parser detected an error; the source field gives further details
Sourcepub fn remove_file(&self, file: &ArxmlFile)
pub fn remove_file(&self, file: &ArxmlFile)
Sourcepub fn serialize_files(&self) -> HashMap<PathBuf, String>
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
}Sourcepub fn write(&self) -> Result<(), AutosarDataError>
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
AutosarDataError::IoErrorWrite: There was an error while writing a file
Sourcepub fn root_element(&self) -> Element
pub fn root_element(&self) -> Element
Get a reference to the root <AUTOSAR ...> element of this model
§Example
let autosar_element = model.root_element();Sourcepub fn get_element_by_path(&self, path: &str) -> Option<Element>
pub fn get_element_by_path(&self, path: &str) -> Option<Element>
Sourcepub fn duplicate(&self) -> Result<AutosarModel, AutosarDataError>
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
AutosarDataError::ItemDeleted: The current element is in the deleted state and will be freed once the last reference is droppedAutosarDataError::ParentElementLocked: a parent element was locked and did not become available after waiting briefly. The operation was aborted to avoid a deadlock, but can be retried.AutosarDataError::IncorrectContentType: A sub element may not be created in an element with content typeCharacterData.AutosarDataError::ElementInsertionConflict: The requested sub element cannot be created because it conflicts with an existing sub element.AutosarDataError::InvalidSubElement: TheElementNameis not a valid sub element according to the specification.AutosarDataError::NoFilesInModel: The operation cannot be completed because the model does not contain any files
Sourcepub fn elements_dfs(&self) -> ElementsDfsIterator
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() {
// [...]
}Sourcepub fn elements_dfs_with_max_depth(
&self,
max_depth: usize,
) -> ElementsDfsIterator
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);
// ...
}Sourcepub fn sort(&self)
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();Sourcepub fn identifiable_elements(&self) -> IdentifiablesIterator
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();
// [...]
}Sourcepub fn get_references_to(&self, target_path: &str) -> Vec<WeakElement>
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") {
// [...]
}Sourcepub fn check_references(&self) -> Vec<WeakElement>
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
impl Clone for AutosarModel
Source§fn clone(&self) -> AutosarModel
fn clone(&self) -> AutosarModel
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AutosarModel
impl Debug for AutosarModel
Source§impl Default for AutosarModel
impl Default for AutosarModel
Source§impl Hash for AutosarModel
impl Hash for AutosarModel
Source§impl PartialEq for AutosarModel
impl PartialEq for AutosarModel
impl Eq for AutosarModel
Auto Trait Implementations§
impl Freeze for AutosarModel
impl !RefUnwindSafe for AutosarModel
impl Send for AutosarModel
impl Sync for AutosarModel
impl Unpin for AutosarModel
impl !UnwindSafe for AutosarModel
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.