pub struct Filestore { /* private fields */ }Expand description
File-based storage manager for proxies, sources, and configuration
The Filestore provides methods for loading and saving data to the filesystem, managing proxy lists, source lists, and configuration files.
It handles file operations, serialization/deserialization, and ensures data consistency when reading and writing files.
§Examples
use gooty_proxy::io::filestore::{Filestore, FilestoreConfig};
// Create a filestore with default configuration
let filestore = Filestore::new().unwrap();
// Create a filestore with custom configuration
let config = FilestoreConfig {
data_dir: "custom_data".to_string(),
..Default::default()
};
let filestore = Filestore::with_config(config).unwrap();
// Load proxies from a file
let proxies = filestore.load_proxies("my_proxies").unwrap();Implementations§
Source§impl Filestore
impl Filestore
Sourcepub fn new() -> FilestoreResult<Self>
pub fn new() -> FilestoreResult<Self>
Sourcepub fn with_config(config: FilestoreConfig) -> FilestoreResult<Self>
pub fn with_config(config: FilestoreConfig) -> FilestoreResult<Self>
Sourcepub fn load_proxies(&self, name: &str) -> FilestoreResult<Vec<Proxy>>
pub fn load_proxies(&self, name: &str) -> FilestoreResult<Vec<Proxy>>
Load proxies from a file
§Arguments
name- Base name of the file (without extension)
§Returns
A vector of Proxy objects loaded from the file
§Errors
Returns an error if:
- The file doesn’t exist and
create_defaults_if_missingis false - The file exists but cannot be read
- The file content is not valid TOML
- The TOML cannot be deserialized into proxies
Sourcepub fn save_proxies(&self, proxies: &[Proxy], name: &str) -> FilestoreResult<()>
pub fn save_proxies(&self, proxies: &[Proxy], name: &str) -> FilestoreResult<()>
Sourcepub fn load_sources(&self, name: &str) -> FilestoreResult<Vec<Source>>
pub fn load_sources(&self, name: &str) -> FilestoreResult<Vec<Source>>
Load sources from a file
§Arguments
name- Base name of the file (without extension)
§Returns
A vector of Source objects loaded from the file
§Errors
Returns an error if:
- The file doesn’t exist and
create_defaults_if_missingis false - The file exists but cannot be read
- The file content is not valid TOML
- The TOML cannot be deserialized into sources
Sourcepub fn save_sources(
&self,
sources: &[Source],
name: &str,
) -> FilestoreResult<()>
pub fn save_sources( &self, sources: &[Source], name: &str, ) -> FilestoreResult<()>
Sourcepub fn load_config(&self, name: &str) -> FilestoreResult<AppConfig>
pub fn load_config(&self, name: &str) -> FilestoreResult<AppConfig>
Load application configuration from a file
§Arguments
name- Base name of the file (without extension)
§Returns
An AppConfig object loaded from the file
§Errors
Returns an error if:
- The file doesn’t exist and
create_defaults_if_missingis false - The file exists but cannot be read
- The file content is not valid TOML
- The TOML cannot be deserialized into
AppConfig
Sourcepub fn save_config(&self, config: &AppConfig, name: &str) -> FilestoreResult<()>
pub fn save_config(&self, config: &AppConfig, name: &str) -> FilestoreResult<()>
Save application configuration to a file
§Arguments
config-AppConfigobject to savename- Base name of the file (without extension)
§Returns
Ok(()) if the configuration was successfully saved
§Errors
Returns an error if:
- The file cannot be created or written to
- The configuration cannot be serialized to TOML
Sourcepub fn get_base_dir(&self) -> &PathBuf
pub fn get_base_dir(&self) -> &PathBuf
Sourcepub fn get_config(&self) -> &FilestoreConfig
pub fn get_config(&self) -> &FilestoreConfig
Auto Trait Implementations§
impl Freeze for Filestore
impl RefUnwindSafe for Filestore
impl Send for Filestore
impl Sync for Filestore
impl Unpin for Filestore
impl UnsafeUnpin for Filestore
impl UnwindSafe for Filestore
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