amethystate-core 0.12.0

Internal crate for amethystate, not intended for direct use
Documentation
use crate::primitives::error::{FieldError, ReactiveFieldResult};
use crate::primitives::field_core::FieldValue;
use crate::{AmeBackendAsync, FieldCore};
use std::sync::Arc;
use uuid::Uuid;

pub async fn field_set_async<B, T>(
    backend: &B,
    core: &FieldCore<T>,
    path: Arc<str>,
    value: T,
    source: Option<Uuid>,
) -> ReactiveFieldResult<(), B::Error>
where
    B: AmeBackendAsync,
    T: FieldValue,
{
    let change = core
        .run_interceptors(path.clone(), value, source)
        .map_err(|_| FieldError::Intercepted)?;

    // The cache is left to the backend's subscription, as in the sync path.
    // Writing it here too made the field its own second writer: subscribers
    // heard about one write twice, and a write the backend refused still
    // showed up in get().
    backend
        .set_owned_with_source(path, &change.new_value, change.source)
        .await?;

    Ok(())
}