Config

Struct Config 

Source
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

Source

pub fn config_path() -> Result<PathBuf>

設定ファイルのパスを取得

設定ファイルは ~/.config/backup-suite/config.toml に配置されます。

§戻り値

成功時は設定ファイルのパス、失敗時はエラー

§Errors

以下の場合にエラーを返します:

  • ホームディレクトリが取得できない場合
§使用例
use backup_suite::Config;

let path = Config::config_path().unwrap();
println!("設定ファイル: {:?}", path);
Source

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);
Source

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();
Source

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);
Source

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();
}
Source

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();
}
Source

pub fn filter_by_priority(&self, priority: &Priority) -> Vec<&Target>

優先度でフィルタリング

指定された優先度のバックアップ対象のみを抽出します。

§引数
  • priority - フィルタリングする優先度
§戻り値

指定された優先度のバックアップ対象の参照のベクター

§使用例
use backup_suite::{Config, Priority};

let config = Config::load().unwrap();
let high_priority = config.filter_by_priority(&Priority::High);
println!("高優先度のバックアップ対象: {}件", high_priority.len());
Source

pub fn filter_by_category(&self, category: &str) -> Vec<&Target>

カテゴリでバックアップ対象をフィルタ

指定されたカテゴリのバックアップ対象のみを取得します。

§引数
  • category - フィルタリングするカテゴリ名
§戻り値

指定されたカテゴリのバックアップ対象の参照のベクター

§使用例
use backup_suite::Config;

let config = Config::load().unwrap();
let system_targets = config.filter_by_category("system");
println!("システムカテゴリのバックアップ対象: {}件", system_targets.len());
Source

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 Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Config

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Config

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. 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> 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> IntoEither for T

Source§

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

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

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,