starlane_core/starlane/
files.rs

1use tokio::runtime::Handle;
2use tokio::runtime::Runtime;
3
4use starlane_resources::data::BinContext;
5use crate::error::Error;
6use crate::file_access::FileAccess;
7use crate::star::StarKey;
8use std::collections::HashSet;
9use tokio::sync::RwLock;
10
11pub struct MachineFileSystem {
12    runtime: Runtime,
13    local_stars: RwLock<HashSet<StarKey>>,
14    data_access: FileAccess,
15}
16
17impl MachineFileSystem {
18    pub fn new() -> Result<Self, Error> {
19        Ok(Self {
20            runtime: Runtime::new().expect("expected a new tokio Runtime"),
21            local_stars: RwLock::new(HashSet::new()),
22            data_access: FileAccess::new(
23                std::env::var("STARLANE_DATA").unwrap_or("data".to_string()),
24            )?,
25        })
26    }
27
28    pub async fn add_local_star(&self, star: StarKey) {
29        let mut lock = self.local_stars.write().await;
30        lock.insert(star);
31    }
32
33    pub fn data_access(&self) -> FileAccess {
34        self.data_access.clone()
35    }
36}
37
38#[async_trait]
39impl BinContext for MachineFileSystem {
40
41}