Struct autosar_data::AutosarProject
source · [−]pub struct AutosarProject(_);Expand description
AutosarProject is the top level data type in the autosar-data crate.
All manipulations of arxml files are performed through an instance of AutosarProject
Implementations
sourceimpl AutosarProject
impl AutosarProject
sourcepub fn new() -> AutosarProject
pub fn new() -> AutosarProject
Create an instance of AutosarData
Initially it contains no arxml files
Example
let project = AutosarProject::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 project. 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 project = AutosarProject::new();
let file = project.create_file("filename.arxml", AutosarVersion::Autosar_00050)?;Possible Errors
- AutosarDataError::DuplicateFilenameError: The project already contains a file with this filename
sourcepub fn load_named_arxml_buffer<P: AsRef<Path>>(
&self,
buffer: &[u8],
filename: P,
strict: bool
) -> Result<(ArxmlFile, Vec<AutosarDataError>), AutosarDataError>
pub fn load_named_arxml_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 project = AutosarProject::new();
project.load_named_arxml_buffer(buffer, "filename.arxml", true)?;Possible Errors
- AutosarDataError::DuplicateFilenameError: The project already contains a file with this filename
- AutosarDataError::OverlappingDataError: The new data contains Autosar paths that are already defined by the existing data
- AutosarDataError::ParserError: The parser detected an error; the source field gives further details
sourcepub fn load_arxml_file<P: AsRef<Path>>(
&self,
filename: P,
strict: bool
) -> Result<(ArxmlFile, Vec<AutosarDataError>), AutosarDataError>
pub fn load_arxml_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_named_arxml_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 project = AutosarProject::new();
project.load_arxml_file("filename.arxml", true)?;Possible Errors
- AutosarDataError::IoErrorOpen: The file could not be opened
- AutosarDataError::IoErrorRead: There was an error while reading the file
- AutosarDataError::DuplicateFilenameError: The project already contains a file with this filename
- AutosarDataError::OverlappingDataError: The new data contains Autosar paths that are already defined by the existing data
- AutosarDataError::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)
remove a file from the project
Parameters:
file: The file that will be removed from the project
Example
let project = AutosarProject::new();
let file = project.create_file("filename.arxml", AutosarVersion::Autosar_00050)?;
project.remove_file(&file);sourcepub fn serialize_files(&self) -> HashMap<PathBuf, String>
pub fn serialize_files(&self) -> HashMap<PathBuf, String>
serialize each of the files in the project
returns the result in a HashMap of <file_name, file_content>
Example
let project = AutosarProject::new();
for (pathbuf, file_content) in project.serialize_files() {
// do something with it
}sourcepub fn write(&self) -> Result<(), AutosarDataError>
pub fn write(&self) -> Result<(), AutosarDataError>
write all files in the project
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 project = AutosarProject::new();
// load or create files
project.write()?;Possible errors
- AutosarDataError::IoErrorWrite: There was an error while writing a file
sourcepub fn get_element_by_path(&self, path: &str) -> Option<Element>
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 project = AutosarProject::new();
// [...]
if let Some(element) = project.get_element_by_path("/Path/To/Element") {
// use the element
}sourcepub fn elements_dfs(&self) -> AutosarDataElementsDfsIterator
pub fn elements_dfs(&self) -> AutosarDataElementsDfsIterator
create a depth-first iterator over all Elements in all ArxmlFiles
The AUTOSAR elements in each file will appear at depth = 0. 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 project.elements_dfs() {
// [...]
}sourcepub fn identifiable_elements(&self) -> AutosarDataIdentElementsIterator
pub fn identifiable_elements(&self) -> AutosarDataIdentElementsIterator
create an iterator over all identifiable elements
It returns the full Autosar path of each element together with a reference to the element. The returned values are sorted alphabetically by the path value.
The iterator created by identifiable_elements() returns values from an internal list that is built when identifiable_elements() is called. This means that the iteration can never show any changes that were made to the data after the iterator was created.
Example
for (path, element) in project.identifiable_elements() {
// [...]
}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 project.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 project.check_references() {
if let Some(broken_ref) = broken_ref_weak.upgrade() {
// update or delete ref?
}
}Trait Implementations
sourceimpl Clone for AutosarProject
impl Clone for AutosarProject
sourcefn clone(&self) -> AutosarProject
fn clone(&self) -> AutosarProject
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl Debug for AutosarProject
impl Debug for AutosarProject
sourceimpl Default for AutosarProject
impl Default for AutosarProject
sourceimpl PartialEq<AutosarProject> for AutosarProject
impl PartialEq<AutosarProject> for AutosarProject
Auto Trait Implementations
impl !RefUnwindSafe for AutosarProject
impl Send for AutosarProject
impl Sync for AutosarProject
impl Unpin for AutosarProject
impl !UnwindSafe for AutosarProject
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more