starlane_core/resource/
file_system.rs

1use std::convert::{TryFrom, TryInto};
2use std::sync::Arc;
3
4use serde::{Deserialize, Serialize};
5
6use starlane_resources::{AssignResourceStateSrc, LocalStateSetSrc, Resource};
7use starlane_resources::data::{BinSrc, DataSet};
8
9use crate::error::Error;
10use crate::resource::{
11    FileSystemKey, ResourceAddress,
12    ResourceType,
13};
14
15#[derive(Clone)]
16pub struct FileSystem {
17    key: FileSystemKey,
18    address: ResourceAddress,
19    state_src: DataSet<BinSrc>,
20}
21
22#[derive(Clone, Serialize, Deserialize)]
23pub struct FileSystemState {}
24
25impl FileSystemState {
26    pub fn new() -> Self {
27        FileSystemState {}
28    }
29}
30
31impl TryInto<Vec<u8>> for FileSystemState {
32    type Error = Error;
33
34    fn try_into(self) -> Result<Vec<u8>, Self::Error> {
35        Ok(bincode::serialize(&self)?)
36    }
37}
38
39impl TryInto<Arc<Vec<u8>>> for FileSystemState {
40    type Error = Error;
41
42    fn try_into(self) -> Result<Arc<Vec<u8>>, Self::Error> {
43        Ok(Arc::new(bincode::serialize(&self)?))
44    }
45}
46
47impl TryFrom<Arc<Vec<u8>>> for FileSystemState {
48    type Error = Error;
49
50    fn try_from(value: Arc<Vec<u8>>) -> Result<Self, Self::Error> {
51        Ok(bincode::deserialize::<FileSystemState>(value.as_slice())?)
52    }
53}
54
55impl TryFrom<Vec<u8>> for FileSystemState {
56    type Error = Error;
57
58    fn try_from(value: Vec<u8>) -> Result<Self, Self::Error> {
59        Ok(bincode::deserialize::<FileSystemState>(value.as_slice())?)
60    }
61}