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