use core::cell::RefCell;
use crate::{
prelude::*,
runtime::{
cache::shared_references_cache::SharedReferencesCache,
execution::ExecutionError,
},
shared_values::base_shared_value_container::observers::TransceiverId,
value_updates::{
update_data::{SetEntryUpdateData, UpdateOperation},
update_handler::UpdateHandler,
},
values::value_container::ValueContainer,
};
pub fn try_set_property(
target: &mut ValueContainer,
key: ValueContainer,
value: ValueContainer,
path: Vec<ValueContainer>,
transceiver_id: TransceiverId,
cache: &RefCell<SharedReferencesCache>,
) -> Result<Option<ValueContainer>, ExecutionError> {
target
.try_set_entry(
path,
transceiver_id,
SetEntryUpdateData::new(key, value),
cache,
)
.map_err(ExecutionError::from)
}
pub fn try_set_shared_container_value(
target: &mut ValueContainer,
new_value: ValueContainer,
source_id: TransceiverId,
cache: &RefCell<SharedReferencesCache>,
) -> Result<(), ExecutionError> {
if let Some(reference) = target.maybe_shared_mut() {
let update =
UpdateOperation::replace(new_value).with_source_root(source_id); Ok(reference.try_handle_update(update, cache).map(|_| ())?) } else {
Err(ExecutionError::ExpectedSharedValue)
}
}