diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-03-11 22:52:25 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-03-11 22:52:25 +0800 |
| commit | 085bce616f68eb6c1586f7a7e1089b5f4cdd0155 (patch) | |
| tree | 5782ae03692754845958ef06b92c56805ddd7bbc /systems/vault/src/func.rs | |
| parent | 55c7ea778be2f3ce44d88440607ac8d4117e31d2 (diff) | |
Add vault and workspace systems with config management
Diffstat (limited to 'systems/vault/src/func.rs')
| -rw-r--r-- | systems/vault/src/func.rs | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/systems/vault/src/func.rs b/systems/vault/src/func.rs new file mode 100644 index 0000000..125c0ac --- /dev/null +++ b/systems/vault/src/func.rs @@ -0,0 +1,40 @@ +use crate::vault::{Vault, config::VaultConfig, error::VaultOperationError, manager::VaultManager}; +use asset_system::asset::Handle; +use framework::space::Space; +use std::{env::current_dir, path::PathBuf}; + +/// Create a vault at the current location +pub async fn create_vault_here() -> Result<(), VaultOperationError> { + create_vault(current_dir()?).await +} + +/// Create a vault at the specified location +pub async fn create_vault(path: impl Into<PathBuf>) -> Result<(), VaultOperationError> { + let path = path.into(); + let mut space = Space::new(Vault); + space.set_current_dir(path)?; + space.init_here().await?; + + Ok(()) +} + +#[allow(unused)] +/// Get a handle to the vault configuration file and edit its content +pub async fn operate_vault_config<F>( + vault_path: impl Into<PathBuf>, + operate: F, +) -> Result<(), VaultOperationError> +where + F: AsyncFn(Handle<VaultConfig>), +{ + // Get the vault manager and set the context to the given vault path + let mut mgr = VaultManager::new(); + mgr.get_space_mut().set_current_dir(vault_path.into())?; + + // Obtain the vault configuration, and pass it to the function for execution + let config = mgr.vault_config()?; + let handle = config.get_handle().await?; + operate(handle).await; + + Ok(()) +} |
