Content

Struct Content 

Source
pub struct Content {}
Expand description

The Content is a static struct that manages file searching, loading and other operations related to resources.

Implementations§

Source§

impl Content

Source

pub fn set_search_paths(val: &Vec<&str>)

Sets an array of directories to search for resource files.

Source

pub fn get_search_paths() -> Vec<String>

Gets an array of directories to search for resource files.

Source

pub fn set_asset_path(val: &str)

Sets the path to the directory containing read-only resources. Can only be altered by the user on platform Windows, MacOS and Linux.

Source

pub fn get_asset_path() -> String

Gets the path to the directory containing read-only resources. Can only be altered by the user on platform Windows, MacOS and Linux.

Source

pub fn set_writable_path(val: &str)

Sets the path to the directory where files can be written. Can only be altered by the user on platform Windows, MacOS and Linux. Default is the same as appPath.

Source

pub fn get_writable_path() -> String

Gets the path to the directory where files can be written. Can only be altered by the user on platform Windows, MacOS and Linux. Default is the same as appPath.

Source

pub fn get_app_path() -> String

Gets the path to the directory for the application storage.

Source

pub fn save(filename: &str, content: &str) -> bool

Saves the specified content to a file with the specified filename.

§Arguments
  • filename - The name of the file to save.
  • content - The content to save to the file.
§Returns
  • bool - true if the content saves to file successfully, false otherwise.
Source

pub fn exist(filename: &str) -> bool

Checks if a file with the specified filename exists.

§Arguments
  • filename - The name of the file to check.
§Returns
  • bool - true if the file exists, false otherwise.
Source

pub fn mkdir(path: &str) -> bool

Creates a new directory with the specified path.

§Arguments
  • path - The path of the directory to create.
§Returns
  • bool - true if the directory was created, false otherwise.
Source

pub fn isdir(path: &str) -> bool

Checks if the specified path is a directory.

§Arguments
  • path - The path to check.
§Returns
  • bool - true if the path is a directory, false otherwise.
Source

pub fn is_absolute_path(path: &str) -> bool

Checks if the specified path is an absolute path.

§Arguments
  • path - The path to check.
§Returns
  • bool - true if the path is an absolute path, false otherwise.
Source

pub fn copy(src: &str, dst: &str) -> bool

Copies the file or directory at the specified source path to the target path.

§Arguments
  • src_path - The path of the file or directory to copy.
  • dst_path - The path to copy the file or directory to.
§Returns
  • bool - true if the file or directory was successfully copied to the target path, false otherwise.
Source

pub fn move_to(src: &str, dst: &str) -> bool

Moves the file or directory at the specified source path to the target path.

§Arguments
  • src_path - The path of the file or directory to move.
  • dst_path - The path to move the file or directory to.
§Returns
  • bool - true if the file or directory was successfully moved to the target path, false otherwise.
Source

pub fn remove(path: &str) -> bool

Removes the file or directory at the specified path.

§Arguments
  • path - The path of the file or directory to remove.
§Returns
  • bool - true if the file or directory was successfully removed, false otherwise.
Source

pub fn get_full_path(filename: &str) -> String

Gets the full path of a file with the specified filename.

§Arguments
  • filename - The name of the file to get the full path of.
§Returns
  • String - The full path of the file.
Source

pub fn add_search_path(path: &str)

Adds a new search path to the end of the list.

§Arguments
  • path - The search path to add.
Source

pub fn insert_search_path(index: i32, path: &str)

Inserts a search path at the specified index.

§Arguments
  • index - The index at which to insert the search path.
  • path - The search path to insert.
Source

pub fn remove_search_path(path: &str)

Removes the specified search path from the list.

§Arguments
  • path - The search path to remove.
Source

pub fn clear_path_cache()

Clears the search path cache of the map of relative paths to full paths.

Source

pub fn get_dirs(path: &str) -> Vec<String>

Gets the names of all subdirectories in the specified directory.

§Arguments
  • path - The path of the directory to search.
§Returns
  • Vec<String> - An array of the names of all subdirectories in the specified directory.
Source

pub fn get_files(path: &str) -> Vec<String>

Gets the names of all files in the specified directory.

§Arguments
  • path - The path of the directory to search.
§Returns
  • Vec<String> - An array of the names of all files in the specified directory.
Source

pub fn get_all_files(path: &str) -> Vec<String>

Gets the names of all files in the specified directory and its subdirectories.

§Arguments
  • path - The path of the directory to search.
§Returns
  • Vec<String> - An array of the names of all files in the specified directory and its subdirectories.
Source

pub fn load_async(filename: &str, callback: Box<dyn FnMut(&str)>)

Asynchronously loads the content of the file with the specified filename.

§Arguments
  • filename - The name of the file to load.
  • callback - The function to call with the content of the file once it is loaded.
§Returns
  • String - The content of the loaded file.
Source

pub fn copy_async( src_file: &str, target_file: &str, callback: Box<dyn FnMut(bool)>, )

Asynchronously copies a file or a folder from the source path to the destination path.

§Arguments
  • srcFile - The path of the file or folder to copy.
  • targetFile - The destination path of the copied files.
  • callback - The function to call with a boolean indicating whether the file or folder was copied successfully.
§Returns
  • bool - true if the file or folder was copied successfully, false otherwise.
Source

pub fn save_async(filename: &str, content: &str, callback: Box<dyn FnMut(bool)>)

Asynchronously saves the specified content to a file with the specified filename.

§Arguments
  • filename - The name of the file to save.
  • content - The content to save to the file.
  • callback - The function to call with a boolean indicating whether the content was saved successfully.
§Returns
  • bool - true if the content was saved successfully, false otherwise.
Source

pub fn zip_async( folder_path: &str, zip_file: &str, filter: Box<dyn FnMut(&str) -> bool>, callback: Box<dyn FnMut(bool)>, )

Asynchronously compresses the specified folder to a ZIP archive with the specified filename.

§Arguments
  • folder_path - The path of the folder to compress, should be under the asset writable path.
  • zip_file - The name of the ZIP archive to create.
  • filter - An optional function to filter the files to include in the archive. The function takes a filename as input and returns a boolean indicating whether to include the file. If not provided, all files will be included.
  • callback - The function to call with a boolean indicating whether the folder was compressed successfully.
§Returns
  • bool - true if the folder was compressed successfully, false otherwise.
Source

pub fn unzip_async( zip_file: &str, folder_path: &str, filter: Box<dyn FnMut(&str) -> bool>, callback: Box<dyn FnMut(bool)>, )

Asynchronously decompresses a ZIP archive to the specified folder.

§Arguments
  • zip_file - The name of the ZIP archive to decompress, should be a file under the asset writable path.
  • folder_path - The path of the folder to decompress to, should be under the asset writable path.
  • filter - An optional function to filter the files to include in the archive. The function takes a filename as input and returns a boolean indicating whether to include the file. If not provided, all files will be included.
  • callback - The function to call with a boolean indicating whether the archive was decompressed successfully.
§Returns
  • bool - true if the folder was decompressed successfully, false otherwise.
Source

pub fn load_excel(filename: &str) -> WorkBook

Source§

impl Content

Source

pub fn load(filename: &str) -> Option<String>

Loads the content of the file with the specified filename.

§Arguments
  • filename - The name of the file to load.
§Returns
  • String - The content of the loaded file.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.