pub struct Element(/* private fields */);Expand description
An arxml element
This is a wrapper type which provides all the necessary manipulation functions.
Implementations§
Source§impl Element
impl Element
Sourcepub fn parent(&self) -> Result<Option<Element>, AutosarDataError>
pub fn parent(&self) -> Result<Option<Element>, AutosarDataError>
Get the parent element of the current element
Returns None if the current element is the root, or if it has been deleted from the element hierarchy
§Example
if let Some(parent) = element.parent()? {
// ...
}§Errors
AutosarDataError::ItemDeleted: The current element is in the deleted state and will be freed once the last reference is dropped
Sourcepub fn named_parent(&self) -> Result<Option<Element>, AutosarDataError>
pub fn named_parent(&self) -> Result<Option<Element>, AutosarDataError>
Get the next named parent (or grandparent, etc) of the current element
This function steps through the hierarchy until an identifiable element is found. It never returns the current element, even if the current element is identifiable.
The function returns a suitable element if one is found, or None if the root is reached.
§Example
let el_elements = el_arpackage.create_sub_element(ElementName::Elements)?;
let el_system = el_elements.create_named_sub_element(ElementName::System, "Sys")?;
let named_parent = el_elements.named_parent()?.unwrap();
let named_parent2 = el_system.named_parent()?.unwrap();
assert_eq!(named_parent, el_arpackage);
assert_eq!(named_parent2, el_arpackage);§Errors
AutosarDataError::ItemDeleted: The current element is in the deleted state and will be freed once the last reference is dropped
Sourcepub fn element_name(&self) -> ElementName
pub fn element_name(&self) -> ElementName
Get the ElementName of the element
§Example
let element = model.root_element();
let element_name = element.element_name();
assert_eq!(element_name, ElementName::Autosar);Sourcepub fn element_type(&self) -> ElementType
pub fn element_type(&self) -> ElementType
Get the ElementType of the element
The ElementType is needed in order to call methods from the autosar-data-specification crate
§Example
let element_type = element.element_type();Sourcepub fn item_name(&self) -> Option<String>
pub fn item_name(&self) -> Option<String>
Get the name of an identifiable element
An identifiable element has a <SHORT-NAME> sub element and can be referenced using an autosar path.
If the element is not identifiable, this function returns None
§Example
if let Some(item_name) = element.item_name() {
// ...
}Sourcepub fn set_item_name(&self, new_name: &str) -> Result<(), AutosarDataError>
pub fn set_item_name(&self, new_name: &str) -> Result<(), AutosarDataError>
Set the item name of this element
This operation will update all references pointing to the element or its sub-elements so that they remain valid.
§Example
element.set_item_name("NewName");§Note
In order to rename an element without updating any references, do this instead:
if let Some(short_name) = element.get_sub_element(ElementName::ShortName) {
short_name.set_character_data("the_new_name");
}§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::ItemNameRequiredthis function was called for an element which is not identifiable
Sourcepub fn is_identifiable(&self) -> bool
pub fn is_identifiable(&self) -> bool
Returns true if the element is identifiable
In order to be identifiable, the specification must require a SHORT-NAME sub-element and the SHORT-NAME must actually be present.
§Example
if element.is_identifiable() {
// ...
}Sourcepub fn is_reference(&self) -> bool
pub fn is_reference(&self) -> bool
Returns true if the element should contain a reference to another element
The function does not check if the reference is valid
§Example
if element.is_reference() {
// ex: element.set_reference_target(...)
}Sourcepub fn path(&self) -> Result<String, AutosarDataError>
pub fn path(&self) -> Result<String, AutosarDataError>
Get the Autosar path of an identifiable element
§Example
let path = element.path()?;§Errors
AutosarDataError::ItemDeleted: Th ecurrent 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::ElementNotIdentifiable: The current element is not identifiable, so it has no Autosar path
Sourcepub fn model(&self) -> Result<AutosarModel, AutosarDataError>
pub fn model(&self) -> Result<AutosarModel, AutosarDataError>
Get a reference to the AutosarModel containing the current element
§Example
let file = element.model()?;§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.
Sourcepub fn content_type(&self) -> ContentType
pub fn content_type(&self) -> ContentType
Get the ContentType of the current element
§Example
if element.content_type() == ContentType::CharacterData {
// ...
}Sourcepub fn create_sub_element(
&self,
element_name: ElementName,
) -> Result<Element, AutosarDataError>
pub fn create_sub_element( &self, element_name: ElementName, ) -> Result<Element, AutosarDataError>
Create a sub element at a suitable insertion position
The given ElementName must be allowed on a sub element in this element, taking into account any sub elements that may already exist.
It is not possible to create named sub elements with this function; use create_named_sub_element() for that instead.
§Example
let element = model.root_element().create_sub_element(ElementName::ArPackages)?;§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::ItemNameRequired: The sub element requires an item name, so you must usecreate_named_sub_element().AutosarDataError::NoFilesInModel: The operation cannot be completed because the model does not contain any files
Sourcepub fn create_sub_element_at(
&self,
element_name: ElementName,
position: usize,
) -> Result<Element, AutosarDataError>
pub fn create_sub_element_at( &self, element_name: ElementName, position: usize, ) -> Result<Element, AutosarDataError>
Create a sub element at the specified insertion position
The given ElementName must be allowed on a sub element in this element, taking into account any sub elements that may already exist.
It is not possible to create named sub elements with this function; use create_named_sub_element_at() for that instead.
The specified insertion position will be compared to the range of valid insertion positions; if it falls outside that range then the function fails.
§Example
let element = model.root_element().create_sub_element_at(ElementName::ArPackages, 0)?;§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::ItemNameRequired: The sub element requires an item name, so you must usecreate_named_sub_element_at().AutosarDataError::InvalidPosition: This sub element cannot be created at the requested positionAutosarDataError::NoFilesInModel: The operation cannot be completed because the model does not contain any files
Sourcepub fn create_named_sub_element(
&self,
element_name: ElementName,
item_name: &str,
) -> Result<Element, AutosarDataError>
pub fn create_named_sub_element( &self, element_name: ElementName, item_name: &str, ) -> Result<Element, AutosarDataError>
Create a named/identifiable sub element at a suitable insertion position
The given ElementName must be allowed on a sub element in this element, taking into account any sub elements that may already exist.
This method can only be used to create identifiable sub elements.
§Example
let pkgs_element = model.root_element().create_sub_element(ElementName::ArPackages)?;
let element = pkgs_element.create_named_sub_element(ElementName::ArPackage, "Package")?;§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::ElementNotIdentifiable: The sub element does not have an item name, so you must usecreate_sub_element() instead.AutosarDataError::NoFilesInModel: The operation cannot be completed because the model does not contain any files
Sourcepub fn create_named_sub_element_at(
&self,
element_name: ElementName,
item_name: &str,
position: usize,
) -> Result<Element, AutosarDataError>
pub fn create_named_sub_element_at( &self, element_name: ElementName, item_name: &str, position: usize, ) -> Result<Element, AutosarDataError>
Create a named/identifiable sub element at the specified insertion position
The given ElementName must be allowed on a sub element in this element, taking into account any sub elements that may already exist.
The specified insertion position will be compared to the range of valid insertion positions; if it falls outside that range then the function fails.
This method can only be used to create identifiable sub elements.
§Example
let pkgs_element = model.root_element().create_sub_element(ElementName::ArPackages)?;
let element = pkgs_element.create_named_sub_element_at(ElementName::ArPackage, "Package", 0)?;§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::ElementNotIdentifiable: The sub element does not have an item name, so you must usecreate_sub_element() instead.AutosarDataError::InvalidPosition: This sub element cannot be created at the requested position.AutosarDataError::NoFilesInModel: The operation cannot be completed because the model does not contain any files
Sourcepub fn create_copied_sub_element(
&self,
other: &Element,
) -> Result<Element, AutosarDataError>
pub fn create_copied_sub_element( &self, other: &Element, ) -> Result<Element, AutosarDataError>
Create a deep copy of the given element and insert it as a sub-element
The other element must be a permissible sub-element in this element and not conflict with any existing sub element.
The other element can originate from any loaded AutosarModel, it does not have to originate from the same model or file as the current element.
The AutosarVersion of the other element might differ from the version of the current file;
in this case a partial copy will be performed that omits all incompatible elements.
If the copied element is identifiable, then the item name might be extended with a numerical suffix, if one is required in order to make the name unique.
For example: An identifiable element “Foo” already exists at the same path; the copied identifiable element will be renamed to “Foo_1”.
If the copied element or the hierarchy of elements under it contain any references, then these will need to be adjusted manually after copying.
§Example
let other_element = model.get_element_by_path("/Package/Path").unwrap();
let element = base.create_copied_sub_element(&other_element)?;§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 create_copied_sub_element_at(
&self,
other: &Element,
position: usize,
) -> Result<Element, AutosarDataError>
pub fn create_copied_sub_element_at( &self, other: &Element, position: usize, ) -> Result<Element, AutosarDataError>
Create a deep copy of the given element and insert it as a sub-element at the given position
The other element must be a permissible sub-element in this element and not conflict with any existing sub element.
The other element can originate from any loaded AutosarModel, it does not have to originate from the same model or file as the current element.
The AutosarVersion of the other element might differ from the version of the current file;
in this case a partial copy will be performed that omits all incompatible elements.
If the copied element is identifiable, then the item name might be extended with a numerical suffix, if one is required in order to make the name unique.
For example: An identifiable element “Foo” already exists at the same path; the copied identifiable element will be renamed to “Foo_1”.
If the copied element or the hierarchy of elements under it contain any references, then these will need to be adjusted manually after copying.
§Example
let other_element = model.get_element_by_path("/Package/Path").unwrap();
let element = base.create_copied_sub_element_at(&other_element, 0)?;§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::InvalidPosition: This sub element cannot be created at the requested position.AutosarDataError::NoFilesInModel: The operation cannot be completed because the model does not contain any files
Sourcepub fn move_element_here(
&self,
move_element: &Element,
) -> Result<Element, AutosarDataError>
pub fn move_element_here( &self, move_element: &Element, ) -> Result<Element, AutosarDataError>
Take an element from it’s current location and place it in this element as a sub element
The moved element can be taken from anywhere - even from a different arxml document that is not part of the same AutosarModel
Restrictions:
- The element must have a compatible element type. If it could not have been created here, then it can’t be moved either.
- The origin document of the element must have exactly the same
AutosarVersionas the destination.
§Example
let other_element = model.get_element_by_path("/Package/Path").unwrap();
let element = base.move_element_here(&other_element)?;§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::VersionMismatch: The Autosar versions of the source and destination are differentAutosarDataError::ForbiddenMoveToSubElement: The destination is a sub element of the source. Moving here is not possibleAutosarDataError::NoFilesInModel: The operation cannot be completed because the model does not contain any files
Sourcepub fn move_element_here_at(
&self,
move_element: &Element,
position: usize,
) -> Result<Element, AutosarDataError>
pub fn move_element_here_at( &self, move_element: &Element, position: usize, ) -> Result<Element, AutosarDataError>
Take an element from it’s current location and place it at the given position in this element as a sub element
The moved element can be taken from anywhere - even from a different arxml document that is not part of the same AutosarModel
Restrictions:
- The element must have a compatible element type. If it could not have been created here, then it can’t be moved either.
- The origin document of the element must have exactly the same
AutosarVersionas the destination.
§Example
let other_element = model.get_element_by_path("/Package/Path").unwrap();
let element = base.move_element_here_at(&other_element, 0)?;§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::VersionMismatch: The Autosar versions of the source and destination are differentAutosarDataError::ForbiddenMoveToSubElement: The destination is a sub element of the source. Moving here is not possibleAutosarDataError::InvalidPosition: This sub element cannot be created at the requested position.AutosarDataError::NoFilesInModel: The operation cannot be completed because the model does not contain any files
Sourcepub fn remove_sub_element(
&self,
sub_element: Element,
) -> Result<(), AutosarDataError>
pub fn remove_sub_element( &self, sub_element: Element, ) -> Result<(), AutosarDataError>
Remove the sub element sub_element
The sub_element will be unlinked from the hierarchy of elements.
All of the sub-sub-elements nested under the removed element will also be recusively removed.
Since all elements are reference counted, they might not be deallocated immediately, however they do become invalid and unusable immediately.
§Example
let packages = model.root_element().create_sub_element(ElementName::ArPackages)?;
model.root_element().remove_sub_element(packages)?;§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::ElementNotFound: The sub element was not found in this elementAutosarDataError::ShortNameRemovalForbidden: It is not permitted to remove the SHORT-NAME of identifiable elements since this would result in invalid data
Sourcepub fn remove_sub_element_kind(
&self,
element_name: ElementName,
) -> Result<(), AutosarDataError>
pub fn remove_sub_element_kind( &self, element_name: ElementName, ) -> Result<(), AutosarDataError>
Remove a sub element identified by an ElementName
If multiple sub elements with the same ElementName exist, only the first one will be removed.
A sub element with the given ElementName will be unlinked from the hierarchy of elements. All of the sub-sub-elements nested under the removed element will also be recusively removed.
This is a convenience function that is equivalent to calling get_sub_element() followed by remove_sub_element().
§Example
let packages = model.root_element().create_sub_element(ElementName::ArPackages)?;
model.root_element().remove_sub_element_kind(ElementName::ArPackages)?;§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::ElementNotFound: The sub element was not found in this elementAutosarDataError::ShortNameRemovalForbidden: It is not permitted to remove the SHORT-NAME of identifiable elements since this would result in invalid data
Sourcepub fn set_reference_target(
&self,
target: &Element,
) -> Result<(), AutosarDataError>
pub fn set_reference_target( &self, target: &Element, ) -> Result<(), AutosarDataError>
Set the reference target for the element to target
When the reference is updated, the DEST attribute is also updated to match the referenced element. The current element must be a reference element, otherwise the function fails.
§Example
let cluster_element = elements.create_named_sub_element(ElementName::CanCluster, "Cluster")?;
ref_element.set_reference_target(&cluster_element)?;§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::NotReferenceElement: The current element is not a reference, so it is not possible to set a reference targetAutosarDataError::InvalidReference: The target element is not a valid reference target for this referenceAutosarDataError::ElementNotIdentifiable: The target element is not identifiable, so it cannot be referenced by an Autosar pathAutosarDataError::NoFilesInModel: The operation cannot be completed because the model does not contain any files
Sourcepub fn get_reference_target(&self) -> Result<Element, AutosarDataError>
pub fn get_reference_target(&self) -> Result<Element, AutosarDataError>
Get the referenced element
This function will get the reference string from the character data of the element as well as the destination type from the DEST attribute. Then a lookup of the Autosar path is performed, and if an element is found at that path, then the type of the element is compared to the expected type.
The element is returned if it exists and its type is correct.
§Example
let cluster_element = elements.create_named_sub_element(ElementName::CanCluster, "Cluster")?;
ref_element.set_reference_target(&cluster_element)?;
let ref_target = ref_element.get_reference_target()?;
assert_eq!(cluster_element, ref_target);§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::NotReferenceElement: The current element is not a reference, so it is not possible to get the reference targetAutosarDataError::InvalidReference: The reference is invalid; there is no element with the referenced Autosar path
Sourcepub fn set_character_data<T: Into<CharacterData>>(
&self,
value: T,
) -> Result<(), AutosarDataError>
pub fn set_character_data<T: Into<CharacterData>>( &self, value: T, ) -> Result<(), AutosarDataError>
Set the character data of this element
This method only applies to elements which contain character data, i.e. element.content_type == CharacterData or Mixed.
On elements with mixed content this function will replace all current content with the single new CharacterData item.
§Example
element.set_character_data("value")?;§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: Cannot set character data on an element which does not contain character data
Sourcepub fn remove_character_data(&self) -> Result<(), AutosarDataError>
pub fn remove_character_data(&self) -> Result<(), AutosarDataError>
Remove the character data of this element
This method only applies to elements which contain character data, i.e. element.content_type == CharacterData
§Example
element.remove_character_data()?;§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. Only relevant when removing references.AutosarDataError::ShortNameRemovalForbidden: Removing the character content of a SHORT-NAME is forbiddenAutosarDataError::IncorrectContentType: Cannot set character data on an element whoch does not contain character data
Sourcepub fn insert_character_content_item(
&self,
chardata: &str,
position: usize,
) -> Result<(), AutosarDataError>
pub fn insert_character_content_item( &self, chardata: &str, position: usize, ) -> Result<(), AutosarDataError>
Insert a character data item into the content of this element
This method only applies to elements which contain mixed data, i.e. element.content_type() == Mixed.
Use create_sub_element_at to add an element instead of a character data item
§Example
// mixed content elements are primarily used for documentation and description
let desc = element.create_sub_element(ElementName::Desc)?;
let l2 = desc.create_sub_element(ElementName::L2)?;
l2.insert_character_content_item("descriptive text", 0)?;§Errors
AutosarDataError::IncorrectContentTypethe elementcontent_typeis not MixedAutosarDataError::InvalidPositionthe position is not valid
Sourcepub fn remove_character_content_item(
&self,
position: usize,
) -> Result<(), AutosarDataError>
pub fn remove_character_content_item( &self, position: usize, ) -> Result<(), AutosarDataError>
Remove a character data item from the content of this element
This method only applies to elements which contain mixed data, i.e. element.content_type == Mixed
§Example
element.insert_character_content_item("descriptive text", 0)?;
element.remove_character_content_item(0)?;§Errors
AutosarDataError::IncorrectContentTypethe elementcontent_typeis not MixedAutosarDataError::InvalidPositionthe position is not valid
Sourcepub fn content_item_count(&self) -> usize
pub fn content_item_count(&self) -> usize
returns the number of content items in this element
assert_eq!(pkg.content_item_count(), 1);Sourcepub fn character_data(&self) -> Option<CharacterData>
pub fn character_data(&self) -> Option<CharacterData>
Get the character content of the element
This method only applies to elements which contain character data, i.e. element.content_type() == CharacterData
§Example
match element.character_data() {
Some(CharacterData::String(stringval)) => {},
Some(CharacterData::Enum(enumval)) => {},
Some(CharacterData::UnsignedInteger(intval)) => {},
Some(CharacterData::Float(floatval)) => {},
None => {},
}Sourcepub fn content(&self) -> ElementContentIterator
pub fn content(&self) -> ElementContentIterator
Create an iterator over all of the content of this element
The iterator can return both sub elements and character data, wrapped as ElementContent::Element and ElementContent::CharacterData
This method is intended to be used with elements that contain mixed content.
§Example
for content_item in element.content() {
match content_item {
ElementContent::CharacterData(data) => {},
ElementContent::Element(element) => {},
}
}Sourcepub fn downgrade(&self) -> WeakElement
pub fn downgrade(&self) -> WeakElement
Create a weak reference to this element
A weak reference can be stored without preventing the element from being deallocated. The weak reference has to be upgraded in order to be used, which can fail if the element no longer exists.
See the documentation for Arc
§Example
let weak_element = element.downgrade();Sourcepub fn position(&self) -> Option<usize>
pub fn position(&self) -> Option<usize>
return the position of this element within the parent element
None may be returned if the element has been deleted, or for the root element (AUTOSAR) which has no parent.
The returned position can be used with get_sub_element_at().
§Example
let el_pkg1 = el_ar_packages.create_named_sub_element(ElementName::ArPackage, "Pkg1").unwrap();
let el_pkg2 = el_ar_packages.create_named_sub_element(ElementName::ArPackage, "Pkg2").unwrap();
let el_pkg3 = el_ar_packages.create_named_sub_element(ElementName::ArPackage, "Pkg3").unwrap();
let position = el_pkg2.position().unwrap();
assert_eq!(position, 1);
assert_eq!(el_pkg2, el_ar_packages.get_sub_element_at(position).unwrap());Sourcepub fn sub_elements(&self) -> ElementsIterator
pub fn sub_elements(&self) -> ElementsIterator
Create an iterator over all sub elements of this element
§Example
for sub_element in element.sub_elements() {
// ...
}Sourcepub fn get_sub_element(&self, name: ElementName) -> Option<Element>
pub fn get_sub_element(&self, name: ElementName) -> Option<Element>
Get the sub element with the given element name
Returns None if no such element exists. if there are multiple sub elements with the requested name, then only the first is returned
§Example
let element = pkg.get_sub_element(ElementName::ShortName).unwrap();
assert_eq!(element.element_name(), ElementName::ShortName);Sourcepub fn get_sub_element_at(&self, position: usize) -> Option<Element>
pub fn get_sub_element_at(&self, position: usize) -> Option<Element>
Get the sub element at the given position.
Returns None if no such element exists.
§Example
let element = pkg.get_sub_element_at(0).unwrap();
assert_eq!(element.element_name(), ElementName::ShortName);Sourcepub fn get_or_create_sub_element(
&self,
name: ElementName,
) -> Result<Element, AutosarDataError>
pub fn get_or_create_sub_element( &self, name: ElementName, ) -> Result<Element, AutosarDataError>
Get or create a sub element
This is a shorthand for get_sub_element followed by create_cub_element if getting an existing element fails.
§Example
let element = model.root_element().get_or_create_sub_element(ElementName::ArPackages)?;
let element2 = model.root_element().get_or_create_sub_element(ElementName::ArPackages)?;
assert_eq!(element, element2);§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::ItemNameRequired: The sub element requires an item name, so you must usecreate_named_sub_element().AutosarDataError::NoFilesInModel: The operation cannot be completed because the model does not contain any files
Sourcepub fn get_or_create_named_sub_element(
&self,
element_name: ElementName,
item_name: &str,
) -> Result<Element, AutosarDataError>
pub fn get_or_create_named_sub_element( &self, element_name: ElementName, item_name: &str, ) -> Result<Element, AutosarDataError>
Get or create a named sub element
Checks if a matching subelement exists, and returns it if it does. If no matching subelement exists, tries to create one.
§Example
let ar_packages = model.root_element().get_or_create_sub_element(ElementName::ArPackages)?;
let pkg = ar_packages.get_or_create_named_sub_element(ElementName::ArPackage, "Pkg")?;
let pkg_2 = ar_packages.get_or_create_named_sub_element(ElementName::ArPackage, "Pkg")?;
assert_eq!(pkg, pkg_2);§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::ItemNameRequired: The sub element requires an item name, so you must usecreate_named_sub_element().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 this element and all of its sub elements
Each step in the iteration returns the depth and an element. Due to the nature of a depth first search, the returned depth can remain the same, increase by one, or decrease by an arbitrary number in each step.
The dfs iterator will always return this element as the first item.
§Example
for (depth, elem) in element.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 this element and all of its sub elements up to a maximum depth
Each step in the iteration returns the depth and an element. Due to the nature of a depth first search, the returned depth can remain the same, increase by one, or decrease by an arbitrary number in each step.
The dfs iterator will always return this element as the first item. A max_depth of 0 returns all
child elements, regardless of depth (like elements_dfs does).
§Example
for (depth, elem) in element.elements_dfs_with_max_depth(1) {
assert!(depth <= 1);
// ...
}Sourcepub fn attributes(&self) -> AttributeIterator
pub fn attributes(&self) -> AttributeIterator
Create an iterator over all the attributes in this element
§Example
for attribute in element.attributes() {
println!("{} = {}", attribute.attrname, attribute.content);
}Sourcepub fn attribute_value(&self, attrname: AttributeName) -> Option<CharacterData>
pub fn attribute_value(&self, attrname: AttributeName) -> Option<CharacterData>
Get the value of an attribute by name
§Example
let value = model.root_element().attribute_value(AttributeName::xsiSchemalocation);Sourcepub fn set_attribute<T: Into<CharacterData>>(
&self,
attrname: AttributeName,
value: T,
) -> Result<(), AutosarDataError>
pub fn set_attribute<T: Into<CharacterData>>( &self, attrname: AttributeName, value: T, ) -> Result<(), AutosarDataError>
Set the value of a named attribute
If no attribute by that name exists, and the attribute is a valid attribute of the element, then the attribute will be created.
Returns Ok(()) if the attribute was set, otherwise the Err indicates why setting the attribute failed.
let result = element.set_attribute(AttributeName::S, CharacterData::String("1234-5678".to_string()));§Errors
AutosarDataError::ItemDeleted: The current element is in the deleted state and will be freed once the last reference is droppedAutosarDataError::InvalidAttribute: TheAttributeNameis not valid for this elementAutosarDataError::InvalidAttributeValue: The value is not valid for this attribute in this elementAutosarDataError::NoFilesInModel: The operation cannot be completed because the model does not contain any files
Sourcepub fn set_attribute_string(
&self,
attrname: AttributeName,
stringvalue: &str,
) -> Result<(), AutosarDataError>
pub fn set_attribute_string( &self, attrname: AttributeName, stringvalue: &str, ) -> Result<(), AutosarDataError>
Set the value of a named attribute from a string
The function tries to convert the string to the correct data type for the attribute
Returns Ok(()) if the attribute was set, otherwise the Err indicates why setting the attribute failed.
let result = element.set_attribute_string(AttributeName::T, "2022-01-31T13:59:59Z");§Errors
AutosarDataError::ItemDeleted: The current element is in the deleted state and will be freed once the last reference is droppedAutosarDataError::InvalidAttribute: TheAttributeNameis not valid for this elementAutosarDataError::InvalidAttributeValue: The value is not valid for this attribute in this elementAutosarDataError::NoFilesInModel: The operation cannot be completed because the model does not contain any files
Sourcepub fn remove_attribute(&self, attrname: AttributeName) -> bool
pub fn remove_attribute(&self, attrname: AttributeName) -> bool
Remove an attribute from the element
Returns true if the attribute existed and could be removed.
§Example
let result = model.root_element().remove_attribute(AttributeName::xsiSchemalocation);
// xsiSchemalocation exists in the AUTOSAR element, but it is mandatory and cannot be removed
assert_eq!(result, false);Sourcepub fn sort(&self)
pub fn sort(&self)
Recursively sort all sub-elements of this element
All sub elements of the current 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
element.sort();Sourcepub fn serialize(&self) -> String
pub fn serialize(&self) -> String
Serialize the element and all of its content to a string
The serialized text generated for elements below the root element cannot be loaded, but it may be useful for display.
§Example
let text = element.serialize();Sourcepub fn list_valid_sub_elements(&self) -> Vec<ValidSubElementInfo>
pub fn list_valid_sub_elements(&self) -> Vec<ValidSubElementInfo>
List all sub_elements that are valid in the current element
The target use case is direct interaction with a user, e.g. through a selection dialog
§Return Value
A list of tuples consisting of
ElementName of the potential sub element
bool: is the sub element named
bool: can this sub element be inserted considering the current content of the element
§Example
for ValidSubElementInfo{element_name, is_named, is_allowed} in element.list_valid_sub_elements() {
// ...
}Sourcepub fn file_membership(
&self,
) -> Result<(bool, HashSet<WeakArxmlFile>), AutosarDataError>
pub fn file_membership( &self, ) -> Result<(bool, HashSet<WeakArxmlFile>), AutosarDataError>
Return the set of files in which the current element is present
§Return Value
A tuple (bool, HashSet); if the bool value is true, then the file set is stored in this element, otherwise it is inherited from a parent element.
§Example
let (inherited, file_membership) = element.file_membership()?;§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::NoFilesInModel: The operation cannot be completed because the model does not contain any files
Sourcepub fn add_to_file(&self, file: &ArxmlFile) -> Result<(), AutosarDataError>
pub fn add_to_file(&self, file: &ArxmlFile) -> Result<(), AutosarDataError>
add the current element to the given file
In order to successfully cause the element to appear in the serialized file data, all parent elements of the current element will also be added if required.
If the model only has a single file then this function does nothing.
§Example
let file = model.create_file("test", AutosarVersion::Autosar_00050).unwrap();
element.add_to_file(&file);§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.
Sourcepub fn remove_from_file(&self, file: &ArxmlFile) -> Result<(), AutosarDataError>
pub fn remove_from_file(&self, file: &ArxmlFile) -> Result<(), AutosarDataError>
remove this element from a file
If the model consists of multiple files, then the set of files in which this element appears will be restricted. It may be required to also omit its parent(s), up to the next splittable point.
If the element is only present in single file then an attempt to delete it will be made instead. Deleting the element fails if the element is the root AUTOSAR element, or if it is a SHORT-NAME.
§Example
assert!(model.files().count() > 1);
element.remove_from_file(&file);§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.
Sourcepub fn xml_path(&self) -> String
pub fn xml_path(&self) -> String
Return a path that includes non-identifiable elements by their xml names
This function cannot fail completely, it will always collect as much information as possible. It is intended for display in error messages.
Sourcepub fn calc_element_insert_range(
&self,
element_name: ElementName,
version: AutosarVersion,
) -> Result<(usize, usize), AutosarDataError>
pub fn calc_element_insert_range( &self, element_name: ElementName, version: AutosarVersion, ) -> Result<(usize, usize), AutosarDataError>
Find the upper and lower bound on the insert position for a new sub element
If the sub element is allowed for this element given its current content, this function returns the lower and upper bound on the position the new sub element could have. If the sub element is not allowed, then an Err is returned instead.
The lower and upper bounds are inclusive: lower <= (element insert pos) <= upper. In many situations lower == upper, this means there is only a single valid position.
§Example
let (lbound, ubound) = model.root_element()
.calc_element_insert_range(ElementName::ArPackages, AutosarVersion::LATEST)?;
model.root_element().create_sub_element_at(ElementName::ArPackages, lbound)?;§Errors
AutosarDataError::ElementInsertionConflict: The sub element conflicts with an existing sub elementAutosarDataError::InvalidSubElement: The sub element is not valid inside this element
Sourcepub fn comment(&self) -> Option<String>
pub fn comment(&self) -> Option<String>
Return the comment attachd to the element (if any)
A comment directly preceding the opening tag is considered to be atached and is returned here.
In the arxml text:
<!--element comment-->
<ELEMENT> ...§Example
let opt_comment = element.comment();Sourcepub fn set_comment(&self, opt_comment: Option<String>)
pub fn set_comment(&self, opt_comment: Option<String>)
Set or delete the comment attached to the element
Set None to remove the comment.
If the new comment value contains “–”, then this is replaced with “__”, because “–” is forbidden inside XML comments.
§Example
element.set_comment(Some(string));Sourcepub fn min_version(&self) -> Result<AutosarVersion, AutosarDataError>
pub fn min_version(&self) -> Result<AutosarVersion, AutosarDataError>
find the minumum version of all arxml files which contain this element
Typically this reduces to finding out which single file contains the element and returning this version.
§Example
let file1 = model.create_file("file1", AutosarVersion::LATEST).unwrap();
let file2 = model.create_file("file2", AutosarVersion::Autosar_4_3_0).unwrap();
let version = model.root_element().min_version().unwrap();
assert_eq!(version, AutosarVersion::Autosar_4_3_0);§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::NoFilesInModel: The operation cannot be completed because the model does not contain any files
Trait Implementations§
Source§impl Ord for Element
impl Ord for Element
Source§fn cmp(&self, other: &Element) -> Ordering
fn cmp(&self, other: &Element) -> Ordering
compare the content of two elements
This function compares the content of two elements, returning a cmp::Ordering value. The purpose of this function is to allow sorting of elements based on their content.
The comparison is performed in the following order:
- Element name
- Index (if present)
- Item name (if present)
- Definition reference (if present)
- DEST attribute (if present)
- Content of the element
- Attributes of the element
If the comparison returns Ordering::Equal, then the two elements are identical, but this does not imply that they are the same object.
§Example
let ordering = element1.cmp(&element2);1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl PartialOrd for Element
impl PartialOrd for Element
impl Eq for Element
Auto Trait Implementations§
impl Freeze for Element
impl !RefUnwindSafe for Element
impl Send for Element
impl Sync for Element
impl Unpin for Element
impl !UnwindSafe for Element
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> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
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.