Skip to main content

Filestore

Struct Filestore 

Source
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

Source

pub fn new() -> FilestoreResult<Self>

Create a new filestore with default configuration

Creates a new filestore that stores data in the “data” directory.

§Returns

A new Filestore instance

§Errors

Returns an error if the data directory cannot be created or accessed

Source

pub fn with_config(config: FilestoreConfig) -> FilestoreResult<Self>

Create a new filestore with custom configuration

§Arguments
  • config - Configuration settings for the filestore
§Returns

A new Filestore instance with the specified configuration

§Errors

Returns an error if the data directory cannot be created or accessed

Source

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_missing is false
  • The file exists but cannot be read
  • The file content is not valid TOML
  • The TOML cannot be deserialized into proxies
Source

pub fn save_proxies(&self, proxies: &[Proxy], name: &str) -> FilestoreResult<()>

Save proxies to a file

§Arguments
  • proxies - Vector of proxies to save
  • name - Base name of the file (without extension)
§Returns

Ok(()) if the proxies were successfully saved

§Errors

Returns an error if:

  • The file cannot be created or written to
  • The proxies cannot be serialized to TOML
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_missing is false
  • The file exists but cannot be read
  • The file content is not valid TOML
  • The TOML cannot be deserialized into sources
Source

pub fn save_sources( &self, sources: &[Source], name: &str, ) -> FilestoreResult<()>

Save sources to a file

§Arguments
  • sources - Vector of sources to save
  • name - Base name of the file (without extension)
§Returns

Ok(()) if the sources were successfully saved

§Errors

Returns an error if:

  • The file cannot be created or written to
  • The sources cannot be serialized to TOML
Source

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_missing is false
  • The file exists but cannot be read
  • The file content is not valid TOML
  • The TOML cannot be deserialized into AppConfig
Source

pub fn save_config(&self, config: &AppConfig, name: &str) -> FilestoreResult<()>

Save application configuration to a file

§Arguments
  • config - AppConfig object to save
  • name - 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
Source

pub fn get_base_dir(&self) -> &PathBuf

Get the base directory where files are stored

§Returns

Reference to the base directory path

Source

pub fn get_config(&self) -> &FilestoreConfig

Get the current filestore configuration

§Returns

Reference to the current configuration

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more