Common/Document/SaveDocument.rs
1// File: Common/Source/Document/SaveDocument.rs
2// Role: Defines the `SaveDocument` ActionEffect.
3// Responsibilities:
4// - Provide a declarative effect for saving a single text document.
5// - This effect abstracts the "what" (save a document) from the "how" (the
6// DocumentProvider implementation).
7
8//! # SaveDocument Effect
9//!
10//! Defines the `ActionEffect` for saving a single document to its persisted
11//! location.
12
13use std::sync::Arc;
14
15use url::Url;
16
17use super::DocumentProvider::DocumentProvider;
18use crate::{Effect::ActionEffect::ActionEffect, Error::CommonError::CommonError};
19
20/// Creates an effect that, when executed, will save the document at the
21/// specified URI.
22///
23/// It uses the `DocumentProvider` capability from the environment to perform
24/// the operation, which involves getting the document's current content from
25/// the in-memory store and writing it to disk.
26///
27/// # Parameters
28/// * `Uri`: The `Url` of the document to save.
29///
30/// # Returns
31/// An `ActionEffect` that resolves with a `bool` indicating whether the save
32/// operation was successful.
33pub fn SaveDocument(Uri:Url) -> ActionEffect<Arc<dyn DocumentProvider>, CommonError, bool> {
34 ActionEffect::New(Arc::new(move |Provider:Arc<dyn DocumentProvider>| {
35 let UriClone = Uri.clone();
36
37 Box::pin(async move { Provider.SaveDocument(UriClone).await })
38 }))
39}