1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//! Library for collecting bundling resources based on a manifest.
//!
//! Bundles created with Mr. Bundle are designed to be portable so
//! that they can be sent to other systems and unpacked there.
//!
//! A [`Bundle`] contains a [`Manifest`] as well as any number of arbitrary
//! opaque resources in the form of [`ResourceBytes`]. The manifest describes
//! the resources that should be included in the bundle. A Bundle can be
//! serialized and written to a file.
//!
//! With the `fs` feature, the `FileSystemBundler` can be used to work with
//! bundles on the file system.
//!
//! # Example: In-memory bundle
//!
//! A basic use of this library would be to create a bundle in-memory.
//!
//! ```rust
//! use std::collections::HashMap;
//! use serde::{Deserialize, Serialize};
//! use mr_bundle::{Bundle, Manifest, ResourceIdentifier};
//!
//! // Define your manifest
//! #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
//! struct MyManifest {
//! video: String,
//! audio: String,
//! }
//!
//! // Implement the Manifest trait for MyManifest
//! impl Manifest for MyManifest {
//! fn generate_resource_ids(&mut self) -> HashMap<ResourceIdentifier, String> {
//! [self.video.clone(), self.audio.clone()].into_iter().map(|r| {
//! (r.clone(), r.clone())
//! }).collect()
//! }
//!
//! fn resource_ids(&self) -> Vec<ResourceIdentifier> {
//! [self.video.clone(), self.audio.clone()].into_iter().collect()
//! }
//!
//! fn file_name() -> &'static str {
//! "example.yaml"
//! }
//!
//! fn bundle_extension() -> &'static str {
//! "bundle"
//! }
//! }
//!
//! let bundle = Bundle::new(
//! MyManifest {
//! video: "audio_sample".into(),
//! audio: "video_sample".into(),
//! },
//! vec![(
//! "audio_sample".to_string(), vec![1, 2, 3].into()
//! ), (
//! "video_sample".to_string(), vec![44, 54, 23].into()
//! )]
//! ).unwrap();
//!
//! // Serialize the bundle to a byte vector
//! let bytes = bundle.pack().unwrap();
//!
//! // Then do something with the bytes...
//! ```
//!
//! # Example: Bundle to the file system
//!
//!
//! ```rust,no_run
//! use std::collections::HashMap;
//! use serde::{Deserialize, Serialize};
//! use mr_bundle::{resource_id_for_path, Bundle, FileSystemBundler, Manifest, ResourceIdentifier};
//!
//! # #[tokio::main]
//! # async fn main() {
//! // Define your manifest
//! #[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
//! struct MyManifest {
//! video: String,
//! audio: String,
//! }
//!
//! // Implement the Manifest trait for MyManifest
//! impl Manifest for MyManifest {
//! fn generate_resource_ids(&mut self) -> HashMap<ResourceIdentifier, String> {
//! let mut out = HashMap::new();
//!
//! let audio_id = resource_id_for_path(&self.audio).unwrap_or("audio-id".to_string());
//! out.insert(audio_id.clone(), self.audio.clone());
//! self.audio = audio_id;
//!
//! let video_id = resource_id_for_path(&self.video).unwrap_or("video-id".to_string());
//! out.insert(video_id.clone(), self.video.clone());
//! self.video = video_id;
//!
//! out
//! }
//!
//! fn resource_ids(&self) -> Vec<ResourceIdentifier> {
//! [
//! resource_id_for_path(&self.audio).unwrap_or("audio-id".to_string()),
//! resource_id_for_path(&self.video).unwrap_or("video-id".to_string())
//! ].into_iter().collect()
//! }
//!
//! fn file_name() -> &'static str {
//! "example.yaml"
//! }
//!
//! fn bundle_extension() -> &'static str {
//! "bundle"
//! }
//! }
//!
//! // Create an example manifest, and note that the resource paths would also need to exist.
//! std::fs::write("./example.yaml", r#"
//! audio: ./audio-sample.mp3
//! video: ./video-sample.mp4
//! "#).unwrap();
//!
//! // Then create a bundle using the manifest.
//! // The resulting bundle will be written to the file system.
//! FileSystemBundler::bundle_to::<MyManifest>(
//! "./example.yaml",
//! "./packaging/example.bundle",
//! ).await.unwrap();
//!
//! // The bundle will now exist on the file system.
//! assert!(std::fs::exists("./packaging/example.bundle").unwrap());
//! # }
//! ```
//!
pub use ;
pub use ;
pub use ;
pub use ;