pub enum DataSource {
StdReadFile,
Folders(Vec<String>),
TarInMemory(Vec<u8>),
TarFile(TarFile),
FileMap(HashMap<String, SingleFileSource>),
Sync(Box<dyn SyncFolderSource + Send + Sync>),
Async(Box<dyn AsyncFolderSource + Send + Sync>),
}
Expand description
Defines where to get the content of the requested file name.
很多配置中 都要再加载其他外部文件, FileSource 限定了 查找文件的 路径 和 来源, 读取文件时只会限制在这个范围内, 这样就增加了安全性
Variants§
StdReadFile
Folders(Vec<String>)
从指定的一组路径来寻找文件
TarInMemory(Vec<u8>)
从一个 已放到内存中的 tar 中 寻找文件
TarFile(TarFile)
FileMap(HashMap<String, SingleFileSource>)
与其它方式不同,FileMap 存储名称的映射表, 无需遍历目录
Sync(Box<dyn SyncFolderSource + Send + Sync>)
Async(Box<dyn AsyncFolderSource + Send + Sync>)
Implementations§
Source§impl DataSource
impl DataSource
pub fn insert_current_working_dir(&mut self) -> Result<()>
pub fn read_to_string<P>(&self, file_name: P) -> Result<String, FetchError>
Trait Implementations§
Source§impl AsyncFolderSource for DataSource
impl AsyncFolderSource for DataSource
Source§impl Debug for DataSource
impl Debug for DataSource
Source§impl Default for DataSource
impl Default for DataSource
Source§fn default() -> DataSource
fn default() -> DataSource
Returns the “default value” for a type. Read more
Source§impl SyncFolderSource for DataSource
impl SyncFolderSource for DataSource
Source§fn get_file_content(
&self,
file_name: &Path,
) -> Result<(Vec<u8>, Option<String>), FetchError>
fn get_file_content( &self, file_name: &Path, ) -> Result<(Vec<u8>, Option<String>), FetchError>
返回读到的 数据。可能还会返回 成功找到的路径
Auto Trait Implementations§
impl Freeze for DataSource
impl !RefUnwindSafe for DataSource
impl Send for DataSource
impl Sync for DataSource
impl Unpin for DataSource
impl !UnwindSafe for DataSource
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more