Skip to content
Snippets Groups Projects
Commit 86f9c31f authored by Udo Eisenbarth's avatar Udo Eisenbarth :speech_balloon:
Browse files

Properties: make attribute private

parent 86920a00
No related branches found
No related tags found
1 merge request!42Resolve "Improve property system"
......@@ -75,10 +75,9 @@ pub trait Optical: Dottable {
/// This function will return an error if a non-defined property is set or the property has the wrong data type.
fn set_property(&mut self, name: &str, property: Property) -> OpmResult<()>;
fn set_properties(&mut self, properties: &Properties) -> OpmResult<()> {
let own_properties = self.properties().props.clone();
for prop in properties.props.iter() {
if own_properties.contains_key(prop.0) {
let own_properties = self.properties().clone();
for prop in properties.iter() {
if own_properties.contains(prop.0) {
self.set_property(prop.0, prop.1.clone())?;
}
}
......
......@@ -11,9 +11,8 @@ use crate::{
/// A general set of (optical) properties.
#[derive(Default, Serialize, Deserialize, Debug, Clone)]
pub struct Properties {
pub props: HashMap<String, Property>,
props: HashMap<String, Property>,
}
impl Properties {
pub fn create(&mut self, name: &str, value: Property) -> OpmResult<()> {
if self.props.insert(name.into(), value).is_some() {
......@@ -35,6 +34,12 @@ impl Properties {
Ok(())
}
}
pub fn iter(&self) -> std::collections::hash_map::Iter<'_, String, Property> {
self.props.iter()
}
pub fn contains(&self, key: &str) -> bool {
self.props.contains_key(key)
}
pub fn get(&self, name: &str) -> Option<&Property> {
self.props.get(name)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment