pub struct Config {
pub version: String,
pub backup: BackupConfig,
pub schedule: ScheduleConfig,
pub targets: Vec<Target>,
}Expand description
メイン設定構造体
backup-suite の全体設定を管理します。
TOML形式で永続化され、~/.config/backup-suite/config.toml に保存されます。
§フィールド
version- 設定ファイルのバージョンbackup- バックアップ関連の設定schedule- スケジュール関連の設定targets- バックアップ対象のリスト
§使用例
use backup_suite::{Config, Target, Priority};
use std::path::PathBuf;
// デフォルト設定を作成
let mut config = Config::default();
// バックアップ対象を追加
let target = Target::new(
PathBuf::from("/home/user/documents"),
Priority::High,
"重要ドキュメント".to_string()
);
config.add_target(target);
// 設定を保存
config.save().unwrap();Fields§
§version: String§backup: BackupConfig§schedule: ScheduleConfig§targets: Vec<Target>Implementations§
Source§impl Config
impl Config
Sourcepub fn config_path() -> Result<PathBuf>
pub fn config_path() -> Result<PathBuf>
Sourcepub fn load() -> Result<Self>
pub fn load() -> Result<Self>
設定ファイルを読み込み
~/.config/backup-suite/config.toml から設定を読み込みます。
ファイルが存在しない場合はデフォルト設定を返します。
§戻り値
成功時は Config インスタンス、失敗時はエラー
§Errors
以下の場合にエラーを返します:
- 設定ファイルパスの取得に失敗した場合
- 設定ファイルの読み込みに失敗した場合
- TOML解析に失敗した場合
§使用例
use backup_suite::Config;
let config = Config::load().unwrap_or_default();
println!("バックアップ先: {:?}", config.backup.destination);Sourcepub fn save(&self) -> Result<()>
pub fn save(&self) -> Result<()>
設定ファイルに保存
現在の設定を ~/.config/backup-suite/config.toml に保存します。
設定ディレクトリが存在しない場合は自動的に作成されます。
§戻り値
成功時は Ok(())、失敗時はエラー
§Errors
以下の場合にエラーを返します:
- 設定ファイルパスの取得に失敗した場合
- 設定ディレクトリの作成に失敗した場合
- TOML生成に失敗した場合
- ファイル書き込みに失敗した場合
§使用例
use backup_suite::{Config, Target, Priority};
use std::path::PathBuf;
let mut config = Config::default();
let target = Target::new(
PathBuf::from("/path/to/backup"),
Priority::High,
"重要データ".to_string()
);
config.add_target(target);
config.save().unwrap();Sourcepub fn add_target(&mut self, target: Target) -> bool
pub fn add_target(&mut self, target: Target) -> bool
バックアップ対象を追加
新しいバックアップ対象を設定に追加します。
§引数
target- 追加するバックアップ対象
§使用例
use backup_suite::{Config, Target, Priority};
use std::path::PathBuf;
let mut config = Config::default();
let target = Target::new(
PathBuf::from("/home/user/documents"),
Priority::High,
"ドキュメント".to_string()
);
config.add_target(target);Sourcepub fn remove_target(&mut self, path: &PathBuf) -> bool
pub fn remove_target(&mut self, path: &PathBuf) -> bool
バックアップ対象を削除
指定されたパスのバックアップ対象を設定から削除します。
§引数
path- 削除するバックアップ対象のパス
§戻り値
削除された場合は true、見つからなかった場合は false
§使用例
use backup_suite::Config;
use std::path::PathBuf;
let mut config = Config::load().unwrap();
let removed = config.remove_target(&PathBuf::from("/old/path"));
if removed {
config.save().unwrap();
}Sourcepub fn update_target(
&mut self,
path: &PathBuf,
priority: Option<Priority>,
category: Option<String>,
exclude_patterns: Option<Vec<String>>,
) -> bool
pub fn update_target( &mut self, path: &PathBuf, priority: Option<Priority>, category: Option<String>, exclude_patterns: Option<Vec<String>>, ) -> bool
バックアップ対象を更新
指定されたパスのバックアップ対象の優先度・カテゴリ・除外パターンを更新します。
§引数
path- 更新するバックアップ対象のパスpriority- 新しい優先度(Noneの場合は変更しない)category- 新しいカテゴリ(Noneの場合は変更しない)exclude_patterns- 新しい除外パターン(Noneの場合は変更しない)
§戻り値
更新された場合は true、見つからなかった場合は false
§使用例
use backup_suite::{Config, Priority};
use std::path::PathBuf;
let mut config = Config::load().unwrap();
let updated = config.update_target(
&PathBuf::from("/path/to/update"),
Some(Priority::High),
Some("新カテゴリ".to_string()),
None
);
if updated {
config.save().unwrap();
}Sourcepub fn filter_by_priority(&self, priority: &Priority) -> Vec<&Target>
pub fn filter_by_priority(&self, priority: &Priority) -> Vec<&Target>
Sourcepub fn filter_by_category(&self, category: &str) -> Vec<&Target>
pub fn filter_by_category(&self, category: &str) -> Vec<&Target>
Sourcepub fn validate(&self) -> BackupResult<()>
pub fn validate(&self) -> BackupResult<()>
設定の妥当性を検証
すべての設定項目が正しく、実行可能であることを確認します。
§検証項目
- バックアップ先ディレクトリの存在と書き込み権限
- 保存期間(keep_days)の妥当性(1-3650日)
- 各ターゲットの存在確認と読み取り権限
- 除外パターンの正規表現の妥当性
§戻り値
すべての検証に成功した場合は Ok(())、失敗した場合はエラー
§Errors
以下の場合にエラーを返します:
BackupError::BackupDirectoryCreationError- バックアップ先ディレクトリの作成に失敗BackupError::PermissionDenied- バックアップ先に書き込み権限がないBackupError::ConfigValidationError- 保存期間(keep_days)が範囲外(1-3650日)BackupError::PermissionDenied- ターゲットに読み取り権限がないBackupError::RegexError- 不正な正規表現パターンが含まれている
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Config
impl<'de> Deserialize<'de> for Config
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.