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
use Cow;
use ;
/// A single, unencrypted embedded file, produced by
/// [`embed_bytes!`](crate::embed_bytes) with a `codec = ...` argument.
///
/// Wraps a compiled-in, possibly compressed entry and decompresses it lazily
/// on first access via [`data`](EmbeddedBytes::data). For an `embed_bytes!`
/// call with no `codec` argument, the macro instead expands to a plain
/// `include_bytes!` (a `&'static [u8]`), not this type — `EmbeddedBytes` only
/// shows up once compression is in play.
///
/// # Example
///
/// Both forms, against this crate's own `examples/assets`:
///
/// ```
/// # #[cfg(all(feature = "derive", feature = "deflate", feature = "std"))] {
/// // No codec: a zero-cost `include_bytes!`, so the type is `&[u8]`.
/// static RAW: &[u8] = embark::embed_bytes!("examples/assets/hello.txt");
/// assert_eq!(RAW, b"hello embark");
///
/// // With a codec: an `EmbeddedBytes`, decompressed lazily on first access.
/// static TEXT: embark::EmbeddedBytes =
/// embark::embed_bytes!("examples/assets/lipsum.txt", codec = deflate);
/// let data = TEXT.data();
/// assert!(data.starts_with(b"Embark packs your files"));
///
/// // `codec` takes a bare identifier, never a string. `auto` keeps the
/// // smallest output among the codecs enabled on `embark`.
/// static BEST: embark::EmbeddedBytes =
/// embark::embed_bytes!("examples/assets/lipsum.txt", codec = auto);
/// assert_eq!(BEST.data(), data);
/// # }
/// ```
// An embedded file is routinely megabytes; a derived `Debug` would print
// every byte of it. Report the decoded size instead.