vite_rs_interface/
lib.rs

1// Production File
2#[cfg(any(not(debug_assertions), feature = "debug-prod"))]
3#[derive(Debug, Clone)]
4/// File retrieved from a ViteJS-compiled project
5pub struct ViteFile {
6    pub bytes: ::std::borrow::Cow<'static, [u8]>,
7    pub last_modified: Option<&'static str>,
8    pub content_type: &'static str,
9    pub content_length: u64,
10    #[cfg(feature = "content-hash")]
11    /// SHA-256 hash of the file contents.
12    pub content_hash: &'static str,
13}
14
15// Production Struct Trait
16/// Note: this is used to allow dynamic usage of embedded asset structs.
17#[cfg(any(not(debug_assertions), feature = "debug-prod"))]
18pub trait GetFromVite: Send + Sync + 'static {
19    fn get(&self, file_path: &str) -> Option<ViteFile>;
20    fn clone_box(&self) -> Box<dyn GetFromVite>;
21}
22
23// Development File
24#[cfg(all(debug_assertions, not(feature = "debug-prod")))]
25#[derive(Debug, Clone)]
26/// File retreived from the ViteJS dev server
27pub struct ViteFile {
28    pub bytes: Vec<u8>,
29    pub last_modified: Option<String>,
30    pub content_type: String,
31    pub content_length: u64,
32    #[cfg(feature = "content-hash")]
33    /// Note: in development mode, this is a weak hash returned by the ViteJS dev server.
34    pub content_hash: String,
35}
36
37// Development Struct Trait
38/// Note: this is used to allow dynamic usage of embedded asset structs.
39#[cfg(all(debug_assertions, not(feature = "debug-prod")))]
40pub trait GetFromVite: Send + Sync + 'static {
41    fn get(&self, file_path: &str) -> Option<ViteFile>;
42    fn clone_box(&self) -> Box<dyn GetFromVite>;
43}