review: make value_of internal and remove unused function
This commit is contained in:
@@ -42,31 +42,13 @@ impl O {
|
||||
}
|
||||
self
|
||||
}
|
||||
pub fn value_of(&self, id: &str) -> Option<&Value> {
|
||||
pub(crate) fn value_of(&self, id: &str) -> Option<&Value> {
|
||||
let attribute = self.attributes.get(id);
|
||||
match attribute {
|
||||
None => None,
|
||||
Some(attribute) => Some(&attribute.value),
|
||||
}
|
||||
}
|
||||
pub fn set(&mut self, id: &str, value: impl Into<Value>) -> Option<Value> {
|
||||
let attribute = Attribute::new(id, value);
|
||||
let previous_attribute = self.attributes.insert(attribute.id.clone(), attribute);
|
||||
match previous_attribute {
|
||||
None => None,
|
||||
Some(attribute) => Some(attribute.value),
|
||||
}
|
||||
}
|
||||
pub fn unset(&mut self, id: &str) -> Option<Value> {
|
||||
let attribute = self.attributes.remove(id);
|
||||
match attribute {
|
||||
None => None,
|
||||
Some(attribute) => Some(attribute.value),
|
||||
}
|
||||
}
|
||||
pub fn has_attribute(&self, id: &str) -> bool {
|
||||
self.attributes.contains_key(id)
|
||||
}
|
||||
pub fn unwrap<T>(&self, id: &str) -> T
|
||||
where
|
||||
T: From<Value>,
|
||||
|
||||
@@ -27,15 +27,12 @@ mod tests {
|
||||
}
|
||||
impl From<Product> for Entity {
|
||||
fn from(value: Product) -> Self {
|
||||
let mut entity = Entity::new::<Product>()
|
||||
Entity::new::<Product>()
|
||||
.with_id(&value.id)
|
||||
.with_attribute("name", value.name)
|
||||
.with_attribute("price", value.price)
|
||||
.with_attribute("in_stock", value.in_stock);
|
||||
if let Some(model) = value.model {
|
||||
entity.set("model", model);
|
||||
}
|
||||
entity
|
||||
.with_attribute("in_stock", value.in_stock)
|
||||
.with_opt_attribute("model", value.model)
|
||||
}
|
||||
}
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user