burn_central_core/bundle/
core.rs1use serde::{Serialize, de::DeserializeOwned};
2use std::io::Read;
3
4pub trait BundleEncode {
6 type Settings: Default + Serialize + DeserializeOwned;
7 type Error: Into<Box<dyn std::error::Error + Send + Sync + 'static>>;
8
9 fn encode<O: BundleSink>(
10 self,
11 sink: &mut O,
12 settings: &Self::Settings,
13 ) -> Result<(), Self::Error>;
14}
15
16pub trait BundleDecode: Sized {
18 type Settings: Default + Serialize + DeserializeOwned;
19 type Error: Into<Box<dyn std::error::Error + Send + Sync + 'static>>;
20
21 fn decode<I: BundleSource>(source: &I, settings: &Self::Settings) -> Result<Self, Self::Error>;
22}
23
24pub trait BundleSink {
26 fn put_file<R: Read>(&mut self, path: &str, reader: &mut R) -> Result<(), String>;
28
29 fn put_bytes(&mut self, path: &str, bytes: &[u8]) -> Result<(), String> {
31 let mut r = std::io::Cursor::new(bytes);
32 self.put_file(path, &mut r)
33 }
34}
35
36pub trait BundleSource {
38 fn open(&self, path: &str) -> Result<Box<dyn Read + Send>, String>;
40
41 fn list(&self) -> Result<Vec<String>, String>;
43}
44
45pub fn normalize_bundle_path<S: AsRef<str>>(s: S) -> String {
47 s.as_ref()
48 .replace('\\', "/")
49 .trim_start_matches('/')
50 .to_string()
51}