Skip to main content

namespace

Function namespace 

Source
pub fn namespace(
    storage: Arc<dyn Storage>,
    prefix: &str,
) -> Result<Arc<dyn Storage>>
Expand description

A view of storage with every key under prefix (namespace): the backend’s own Storage::namespace when it has one, a NamespacedStorage otherwise. This is the form to use on an Arc<dyn Storage>, where the trait method returns None for backends without namespacing.

use std::sync::Arc;
use strands::storage::{self, InMemoryStorage, Storage};

let root: Arc<dyn Storage> = Arc::new(InMemoryStorage::new());
let sessions = storage::namespace(root.clone(), "sessions")?;
sessions.write("abc.json", b"{}").await?;
assert_eq!(root.list("").await?, ["sessions/abc.json"]);

§Errors

Returns a StorageError when the prefix is invalid for the backend.