pub trait Container {
Show 38 methods
// Required methods
fn disk_file_path(&self) -> &str;
fn disk_file_offset(&self) -> u64;
fn files(&self) -> &HashMap<String, RFile>;
fn files_mut(&mut self) -> &mut HashMap<String, RFile>;
fn paths_cache(&self) -> &HashMap<String, Vec<String>>;
fn paths_cache_mut(&mut self) -> &mut HashMap<String, Vec<String>>;
fn local_timestamp(&self) -> u64;
// Provided methods
fn extract(
&mut self,
container_path: ContainerPath,
destination_path: &Path,
keep_container_path_structure: bool,
schema: &Option<Schema>,
case_insensitive: bool,
extra_data: &Option<EncodeableExtraData<'_>>
) -> Result<Vec<PathBuf>> { ... }
fn extract_metadata(
&mut self,
_destination_path: &Path
) -> Result<Vec<PathBuf>> { ... }
fn insert(&mut self, file: RFile) -> Result<Option<ContainerPath>> { ... }
fn insert_file(
&mut self,
source_path: &Path,
container_path_folder: &str,
schema: &Option<Schema>
) -> Result<Option<ContainerPath>> { ... }
fn insert_folder(
&mut self,
source_path: &Path,
container_path_folder: &str,
ignored_paths: &Option<Vec<&str>>,
schema: &Option<Schema>,
include_base_folder: bool
) -> Result<Vec<ContainerPath>> { ... }
fn remove(&mut self, path: &ContainerPath) -> Vec<ContainerPath> { ... }
fn disk_file_name(&self) -> String { ... }
fn has_file(&self, path: &str) -> bool { ... }
fn has_folder(&self, path: &str) -> bool { ... }
fn file(&self, path: &str, case_insensitive: bool) -> Option<&RFile> { ... }
fn file_mut(
&mut self,
path: &str,
case_insensitive: bool
) -> Option<&mut RFile> { ... }
fn files_by_type(&self, file_types: &[FileType]) -> Vec<&RFile> { ... }
fn files_by_type_mut(&mut self, file_types: &[FileType]) -> Vec<&mut RFile> { ... }
fn files_by_path(
&self,
path: &ContainerPath,
case_insensitive: bool
) -> Vec<&RFile> { ... }
fn files_by_path_mut(
&mut self,
path: &ContainerPath,
case_insensitive: bool
) -> Vec<&mut RFile> { ... }
fn files_by_paths(
&self,
paths: &[ContainerPath],
case_insensitive: bool
) -> Vec<&RFile> { ... }
fn files_by_paths_mut(
&mut self,
paths: &[ContainerPath],
case_insensitive: bool
) -> Vec<&mut RFile> { ... }
fn files_by_type_and_paths(
&self,
file_types: &[FileType],
paths: &[ContainerPath],
case_insensitive: bool
) -> Vec<&RFile> { ... }
fn files_by_type_and_paths_mut(
&mut self,
file_types: &[FileType],
paths: &[ContainerPath],
case_insensitive: bool
) -> Vec<&mut RFile> { ... }
fn paths_cache_generate(&mut self) { ... }
fn paths_cache_insert_path(&mut self, path: &str) { ... }
fn paths_cache_remove_path(&mut self, path: &str) { ... }
fn paths_folders_raw(&self) -> HashSet<String> { ... }
fn paths(&self) -> Vec<ContainerPath> { ... }
fn paths_raw(&self) -> Vec<&str> { ... }
fn paths_raw_from_container_path(&self, path: &ContainerPath) -> Vec<String> { ... }
fn internal_timestamp(&self) -> u64 { ... }
fn preload(&mut self) -> Result<()> { ... }
fn move_paths(
&mut self,
in_out_paths: &[(ContainerPath, ContainerPath)]
) -> Result<Vec<(ContainerPath, ContainerPath)>> { ... }
fn move_path(
&mut self,
source_path: &ContainerPath,
destination_path: &ContainerPath
) -> Result<Vec<(ContainerPath, ContainerPath)>> { ... }
fn clean_undecoded(&mut self) { ... }
}Expand description
An interface to easily work with container-like files.
This trait allow any implementor to provide methods to manipulate them like RFile Containers.
Required Methods§
sourcefn disk_file_path(&self) -> &str
fn disk_file_path(&self) -> &str
This method returns the path on disk of the provided Container.
Implementors should return "" if the provided Container is not from a disk file.
sourcefn disk_file_offset(&self) -> u64
fn disk_file_offset(&self) -> u64
This method returns the offset of the data of this Container in its disk file.
Implementors should return 0 if the provided Container is not within another Container.
sourcefn files(&self) -> &HashMap<String, RFile>
fn files(&self) -> &HashMap<String, RFile>
This method returns a reference to the RFiles inside the provided Container.
sourcefn files_mut(&mut self) -> &mut HashMap<String, RFile>
fn files_mut(&mut self) -> &mut HashMap<String, RFile>
This method returns a mutable reference to the RFiles inside the provided Container.
sourcefn paths_cache(&self) -> &HashMap<String, Vec<String>>
fn paths_cache(&self) -> &HashMap<String, Vec<String>>
This method returns the cache of paths (lowecased -> cased variants) conntained within the Container.
Please keep in mind if you manipulate the file list in any way, you NEED to update this cache too.
sourcefn paths_cache_mut(&mut self) -> &mut HashMap<String, Vec<String>>
fn paths_cache_mut(&mut self) -> &mut HashMap<String, Vec<String>>
This method returns the cache of paths (lowecased -> cased variants) conntained within the Container.
Please keep in mind if you manipulate the file list in any way, you NEED to update this cache too.
sourcefn local_timestamp(&self) -> u64
fn local_timestamp(&self) -> u64
This method returns the Last modified date the filesystem reports for the container file, in seconds.
Implementors should return 0 if the Container doesn’t have a file on disk yet.
Provided Methods§
sourcefn extract(
&mut self,
container_path: ContainerPath,
destination_path: &Path,
keep_container_path_structure: bool,
schema: &Option<Schema>,
case_insensitive: bool,
extra_data: &Option<EncodeableExtraData<'_>>
) -> Result<Vec<PathBuf>>
fn extract( &mut self, container_path: ContainerPath, destination_path: &Path, keep_container_path_structure: bool, schema: &Option<Schema>, case_insensitive: bool, extra_data: &Option<EncodeableExtraData<'_>> ) -> Result<Vec<PathBuf>>
This method allow us to extract anything on a ContainerPath from a Container to disk, replacing any old file with the same path, in case it already existed one.
If keep_container_path_structure is true, the folder structure the file in question has within the container will be replicated on disk.
The case-insensitive option only works when extracting folders. Individual file extractions are always case sensitive.
If a schema is provided, this function will try to extract any DB/Loc file as a TSV. If it fails to decode them, it’ll extract them as binary files.
sourcefn extract_metadata(&mut self, _destination_path: &Path) -> Result<Vec<PathBuf>>
fn extract_metadata(&mut self, _destination_path: &Path) -> Result<Vec<PathBuf>>
This method allows us to extract the metadata associated to the provided container as .json files.
Default implementation does nothing.
sourcefn insert(&mut self, file: RFile) -> Result<Option<ContainerPath>>
fn insert(&mut self, file: RFile) -> Result<Option<ContainerPath>>
This method allow us to insert an RFile within a Container, replacing any old RFile with the same path, in case it already existed one.
Returns the ContainerPath of the inserted RFile.
sourcefn insert_file(
&mut self,
source_path: &Path,
container_path_folder: &str,
schema: &Option<Schema>
) -> Result<Option<ContainerPath>>
fn insert_file( &mut self, source_path: &Path, container_path_folder: &str, schema: &Option<Schema> ) -> Result<Option<ContainerPath>>
This method allow us to insert a file from disk into an specific path within a Container, replacing any old RFile with the same path, in case it already existed one.
If a Schema is provided, this function will attempt to import any tsv files it finds into binary files. If it fails to convert a file, it’ll import it as a normal file instead.
Returns the ContainerPath of the inserted RFile.
sourcefn insert_folder(
&mut self,
source_path: &Path,
container_path_folder: &str,
ignored_paths: &Option<Vec<&str>>,
schema: &Option<Schema>,
include_base_folder: bool
) -> Result<Vec<ContainerPath>>
fn insert_folder( &mut self, source_path: &Path, container_path_folder: &str, ignored_paths: &Option<Vec<&str>>, schema: &Option<Schema>, include_base_folder: bool ) -> Result<Vec<ContainerPath>>
This method allow us to insert an entire folder from disk, including subfolders and files, into an specific path within a Container, replacing any old RFile in a path collision.
By default it doesn’t insert the folder itself, but its contents. If you want to include the folder, pass include_base_folder as true.
If a Schema is provided, this function will attempt to import any tsv files it finds into binary files. If it fails to convert a file, it’ll import it as a normal file instead.
If ignored paths are provided, paths that match them (as in relative path with the Container as root) will not be included in the Container.
Returns the list of ContainerPath inserted.
sourcefn remove(&mut self, path: &ContainerPath) -> Vec<ContainerPath>
fn remove(&mut self, path: &ContainerPath) -> Vec<ContainerPath>
This method allow us to remove any RFile matching the provided ContainerPath from a Container.
An special situation is passing ContainerPath::Folder(""). This represents the root of the container,
meaning passing this will delete all the RFiles within the container.
Returns the list of removed ContainerPath, always using the File variant.
sourcefn disk_file_name(&self) -> String
fn disk_file_name(&self) -> String
This method returns the file name on disk of the provided Container.
sourcefn has_file(&self, path: &str) -> bool
fn has_file(&self, path: &str) -> bool
This function checks if a file with a certain path exists in the provided Container.
sourcefn has_folder(&self, path: &str) -> bool
fn has_folder(&self, path: &str) -> bool
This function checks if a folder with files in it exists in the provided Container.
sourcefn file(&self, path: &str, case_insensitive: bool) -> Option<&RFile>
fn file(&self, path: &str, case_insensitive: bool) -> Option<&RFile>
This method returns a reference to a RFile in the Container, if the file exists.
sourcefn file_mut(&mut self, path: &str, case_insensitive: bool) -> Option<&mut RFile>
fn file_mut(&mut self, path: &str, case_insensitive: bool) -> Option<&mut RFile>
This method returns a mutable reference to a RFile in the Container, if the file exists.
sourcefn files_by_type(&self, file_types: &[FileType]) -> Vec<&RFile>
fn files_by_type(&self, file_types: &[FileType]) -> Vec<&RFile>
This method returns a reference to the RFiles inside the provided Container of the provided FileTypes.
sourcefn files_by_type_mut(&mut self, file_types: &[FileType]) -> Vec<&mut RFile>
fn files_by_type_mut(&mut self, file_types: &[FileType]) -> Vec<&mut RFile>
This method returns a mutable reference to the RFiles inside the provided Container of the provided FileTypes.
sourcefn files_by_path(
&self,
path: &ContainerPath,
case_insensitive: bool
) -> Vec<&RFile>
fn files_by_path( &self, path: &ContainerPath, case_insensitive: bool ) -> Vec<&RFile>
This method returns a reference to the RFiles inside the provided Container that match the provided ContainerPath.
An special situation is passing ContainerPath::Folder(""). This represents the root of the container,
meaning passing this will return all RFiles within the container.
sourcefn files_by_path_mut(
&mut self,
path: &ContainerPath,
case_insensitive: bool
) -> Vec<&mut RFile>
fn files_by_path_mut( &mut self, path: &ContainerPath, case_insensitive: bool ) -> Vec<&mut RFile>
This method returns a mutable reference to the RFiles inside the provided Container that match the provided ContainerPath.
An special situation is passing ContainerPath::Folder(""). This represents the root of the container,
meaning passing this will return all RFiles within the container.
sourcefn files_by_paths(
&self,
paths: &[ContainerPath],
case_insensitive: bool
) -> Vec<&RFile>
fn files_by_paths( &self, paths: &[ContainerPath], case_insensitive: bool ) -> Vec<&RFile>
This method returns a reference to the RFiles inside the provided Container that match one of the provided ContainerPath.
sourcefn files_by_paths_mut(
&mut self,
paths: &[ContainerPath],
case_insensitive: bool
) -> Vec<&mut RFile>
fn files_by_paths_mut( &mut self, paths: &[ContainerPath], case_insensitive: bool ) -> Vec<&mut RFile>
This method returns a mutable reference to the RFiles inside the provided Container that match the provided ContainerPath.
Use this instead of files_by_path_mut if you need to get mutable references to multiple files on different ContainerPath.
sourcefn files_by_type_and_paths(
&self,
file_types: &[FileType],
paths: &[ContainerPath],
case_insensitive: bool
) -> Vec<&RFile>
fn files_by_type_and_paths( &self, file_types: &[FileType], paths: &[ContainerPath], case_insensitive: bool ) -> Vec<&RFile>
This method returns a reference to the RFiles inside the provided Container that match the provided ContainerPath and are of one of the provided FileType.
sourcefn files_by_type_and_paths_mut(
&mut self,
file_types: &[FileType],
paths: &[ContainerPath],
case_insensitive: bool
) -> Vec<&mut RFile>
fn files_by_type_and_paths_mut( &mut self, file_types: &[FileType], paths: &[ContainerPath], case_insensitive: bool ) -> Vec<&mut RFile>
This method returns a mutable reference to the RFiles inside the provided Container that match the provided ContainerPath and are of one of the provided FileType.
sourcefn paths_cache_generate(&mut self)
fn paths_cache_generate(&mut self)
This method generate the paths cache of the container.
sourcefn paths_cache_insert_path(&mut self, path: &str)
fn paths_cache_insert_path(&mut self, path: &str)
This method adds a path to the paths cache.
sourcefn paths_cache_remove_path(&mut self, path: &str)
fn paths_cache_remove_path(&mut self, path: &str)
This method removes a path from the paths cache.
sourcefn paths_folders_raw(&self) -> HashSet<String>
fn paths_folders_raw(&self) -> HashSet<String>
This method returns the list of folders conntained within the Container.
sourcefn paths(&self) -> Vec<ContainerPath>
fn paths(&self) -> Vec<ContainerPath>
This method returns the list of ContainerPath corresponding to RFiles within the provided Container.
sourcefn paths_raw(&self) -> Vec<&str>
fn paths_raw(&self) -> Vec<&str>
This method returns the list of paths (as &str) corresponding to RFiles within the provided Container.
sourcefn paths_raw_from_container_path(&self, path: &ContainerPath) -> Vec<String>
fn paths_raw_from_container_path(&self, path: &ContainerPath) -> Vec<String>
This function returns the list of paths (as String) corresponding to RFiles that match the provided ContainerPath.
sourcefn internal_timestamp(&self) -> u64
fn internal_timestamp(&self) -> u64
This method returns the Last modified date stored on the provided Container, in seconds.
A default implementation that returns 0 is provided for Container types that don’t support internal timestamps.
Implementors should return 0 if the Container doesn’t have a file on disk yet.
sourcefn preload(&mut self) -> Result<()>
fn preload(&mut self) -> Result<()>
This function preloads to memory any lazy-loaded RFile within this container.
sourcefn move_paths(
&mut self,
in_out_paths: &[(ContainerPath, ContainerPath)]
) -> Result<Vec<(ContainerPath, ContainerPath)>>
fn move_paths( &mut self, in_out_paths: &[(ContainerPath, ContainerPath)] ) -> Result<Vec<(ContainerPath, ContainerPath)>>
This function allows you to move multiple RFiles or folders of RFiles from one folder to another.
It returns a list with all the new ContainerPath.
sourcefn move_path(
&mut self,
source_path: &ContainerPath,
destination_path: &ContainerPath
) -> Result<Vec<(ContainerPath, ContainerPath)>>
fn move_path( &mut self, source_path: &ContainerPath, destination_path: &ContainerPath ) -> Result<Vec<(ContainerPath, ContainerPath)>>
This function allows you to move any RFile or folder of RFiles from one folder to another.
It returns a list with all the new ContainerPath.
sourcefn clean_undecoded(&mut self)
fn clean_undecoded(&mut self)
This function removes all not-in-memory-already Files from the Container.
Used for removing possibly corrupted RFiles from the Container in order to sanitize it.
BE CAREFUL WITH USING THIS. IT MAY (PROBABLY WILL) CAUSE DATA LOSSES.