From 6d335777bbd03c143eb2ef8b1fdf657ad9de4f60 Mon Sep 17 00:00:00 2001 From: aawsome <37850842+aawsome@users.noreply.github.com> Date: Wed, 2 Oct 2024 01:07:19 +0200 Subject: [PATCH] fix: Add #[non_exhaustive] to pub structs which may be extended in future (#293) --- crates/backend/src/choose.rs | 1 + crates/backend/src/error.rs | 4 ++++ crates/core/src/backend/ignore.rs | 2 ++ crates/core/src/blob/tree.rs | 1 + crates/core/src/commands/check.rs | 2 ++ crates/core/src/commands/config.rs | 1 + crates/core/src/commands/key.rs | 1 + crates/core/src/commands/prune.rs | 2 ++ crates/core/src/commands/repair/snapshots.rs | 1 + crates/core/src/commands/repoinfo.rs | 5 +++++ crates/core/src/commands/restore.rs | 3 +++ crates/core/src/repository.rs | 1 + 12 files changed, 24 insertions(+) diff --git a/crates/backend/src/choose.rs b/crates/backend/src/choose.rs index e7ec87d1..ab5007ca 100644 --- a/crates/backend/src/choose.rs +++ b/crates/backend/src/choose.rs @@ -31,6 +31,7 @@ use clap::ValueHint; #[derive(Clone, Default, Debug, serde::Deserialize, serde::Serialize, Setters)] #[serde(default, rename_all = "kebab-case", deny_unknown_fields)] #[setters(into, strip_option)] +#[non_exhaustive] pub struct BackendOptions { /// Repository to use #[cfg_attr( diff --git a/crates/backend/src/error.rs b/crates/backend/src/error.rs index 4e055d8c..f2aa3477 100644 --- a/crates/backend/src/error.rs +++ b/crates/backend/src/error.rs @@ -6,6 +6,7 @@ use thiserror::Error; /// [`BackendAccessErrorKind`] describes the errors that can be returned by the various Backends #[derive(Error, Debug, Display)] +#[non_exhaustive] pub enum BackendAccessErrorKind { /// backend {0:?} is not supported! BackendNotSupported(String), @@ -38,6 +39,7 @@ pub enum BackendAccessErrorKind { /// [`RcloneErrorKind`] describes the errors that can be returned by a backend provider #[derive(Error, Debug, Display)] +#[non_exhaustive] pub enum RcloneErrorKind { /// 'rclone version' doesn't give any output NoOutputForRcloneVersion, @@ -61,6 +63,7 @@ pub enum RcloneErrorKind { /// [`RestErrorKind`] describes the errors that can be returned while dealing with the REST API #[derive(Error, Debug, Display)] +#[non_exhaustive] pub enum RestErrorKind { /// value `{0:?}` not supported for option retry! NotSupportedForRetry(String), @@ -83,6 +86,7 @@ pub enum RestErrorKind { /// [`LocalBackendErrorKind`] describes the errors that can be returned by an action on the filesystem in Backends #[derive(Error, Debug, Display)] +#[non_exhaustive] pub enum LocalBackendErrorKind { /// directory creation failed: `{0:?}` DirectoryCreationFailed(#[from] std::io::Error), diff --git a/crates/core/src/backend/ignore.rs b/crates/core/src/backend/ignore.rs index fa191f3a..4270851f 100644 --- a/crates/core/src/backend/ignore.rs +++ b/crates/core/src/backend/ignore.rs @@ -46,6 +46,7 @@ pub struct LocalSource { #[derive(serde::Deserialize, serde::Serialize, Default, Clone, Copy, Debug, Setters)] #[serde(default, rename_all = "kebab-case", deny_unknown_fields)] #[setters(into)] +#[non_exhaustive] /// [`LocalSourceSaveOptions`] describes how entries from a local source will be saved in the repository. pub struct LocalSourceSaveOptions { /// Save access time for files and directories @@ -65,6 +66,7 @@ pub struct LocalSourceSaveOptions { #[derive(serde::Deserialize, serde::Serialize, Default, Clone, Debug, Setters)] #[serde(default, rename_all = "kebab-case", deny_unknown_fields)] #[setters(into)] +#[non_exhaustive] /// [`LocalSourceFilterOptions`] allow to filter a local source by various criteria. pub struct LocalSourceFilterOptions { /// Glob pattern to exclude/include (can be specified multiple times) diff --git a/crates/core/src/blob/tree.rs b/crates/core/src/blob/tree.rs index 1ac05ee8..ffd03577 100644 --- a/crates/core/src/blob/tree.rs +++ b/crates/core/src/blob/tree.rs @@ -396,6 +396,7 @@ impl IntoIterator for Tree { #[derive(Derivative, Clone, Debug, Setters)] #[derivative(Default)] #[setters(into)] +#[non_exhaustive] /// Options for listing the `Nodes` of a `Tree` pub struct TreeStreamerOptions { /// Glob pattern to exclude/include (can be specified multiple times) diff --git a/crates/core/src/commands/check.rs b/crates/core/src/commands/check.rs index 39ab786b..89153599 100644 --- a/crates/core/src/commands/check.rs +++ b/crates/core/src/commands/check.rs @@ -31,6 +31,7 @@ use crate::{ }; #[derive(Clone, Copy, Debug, Default)] +#[non_exhaustive] /// Options to specify which subset of packs will be read pub enum ReadSubsetOption { #[default] @@ -119,6 +120,7 @@ impl FromStr for ReadSubsetOption { #[cfg_attr(feature = "clap", derive(clap::Parser))] #[derive(Clone, Copy, Debug, Default, Setters)] #[setters(into)] +#[non_exhaustive] /// Options for the `check` command pub struct CheckOptions { /// Don't verify the data saved in the cache diff --git a/crates/core/src/commands/config.rs b/crates/core/src/commands/config.rs index df99a0a0..195f8701 100644 --- a/crates/core/src/commands/config.rs +++ b/crates/core/src/commands/config.rs @@ -102,6 +102,7 @@ pub(crate) fn save_config( #[cfg_attr(feature = "clap", derive(clap::Parser))] #[derive(Debug, Clone, Copy, Default, Setters)] #[setters(into)] +#[non_exhaustive] /// Options for the `config` command, used to set repository-wide options pub struct ConfigOptions { /// Set compression level. Allowed levels are 1 to 22 and -1 to -7, see . diff --git a/crates/core/src/commands/key.rs b/crates/core/src/commands/key.rs index 221428c8..d6d052bd 100644 --- a/crates/core/src/commands/key.rs +++ b/crates/core/src/commands/key.rs @@ -12,6 +12,7 @@ use crate::{ #[cfg_attr(feature = "clap", derive(clap::Parser))] #[derive(Debug, Clone, Default, Setters)] #[setters(into)] +#[non_exhaustive] /// Options for the `key` command. These are used when creating a new key. pub struct KeyOptions { /// Set 'hostname' in public key information diff --git a/crates/core/src/commands/prune.rs b/crates/core/src/commands/prune.rs index 07fc9bf0..9418ef45 100644 --- a/crates/core/src/commands/prune.rs +++ b/crates/core/src/commands/prune.rs @@ -53,6 +53,7 @@ pub(super) mod constants { #[cfg_attr(feature = "clap", derive(clap::Parser))] #[derive(Debug, Clone, Setters)] #[setters(into)] +#[non_exhaustive] /// Options for the `prune` command pub struct PruneOptions { /// Define maximum data to repack in % of reposize or as size (e.g. '5b', '2 kB', '3M', '4TiB') or 'unlimited' @@ -248,6 +249,7 @@ impl PruneOptions { /// Enum to specify a size limit #[derive(Clone, Copy, Debug)] +#[non_exhaustive] pub enum LimitOption { /// Size in bytes Size(ByteSize), diff --git a/crates/core/src/commands/repair/snapshots.rs b/crates/core/src/commands/repair/snapshots.rs index 3fb24329..8b0c0200 100644 --- a/crates/core/src/commands/repair/snapshots.rs +++ b/crates/core/src/commands/repair/snapshots.rs @@ -24,6 +24,7 @@ use crate::{ #[cfg_attr(feature = "clap", derive(clap::Parser))] #[derive(Debug, Setters)] #[setters(into)] +#[non_exhaustive] /// Options for the `repair snapshots` command pub struct RepairSnapshotsOptions { /// Also remove defect snapshots diff --git a/crates/core/src/commands/repoinfo.rs b/crates/core/src/commands/repoinfo.rs index 63b9298f..e105e305 100644 --- a/crates/core/src/commands/repoinfo.rs +++ b/crates/core/src/commands/repoinfo.rs @@ -12,6 +12,7 @@ use crate::{ }; #[derive(Default, Clone, Debug, Serialize, Deserialize)] +#[non_exhaustive] /// Index information from `repoinfo` pub struct IndexInfos { /// Infos about blobs @@ -25,6 +26,7 @@ pub struct IndexInfos { } #[derive(Clone, Copy, Debug, Serialize, Deserialize)] +#[non_exhaustive] /// Information about blobs within `repoinfo` pub struct BlobInfo { /// Blob type @@ -57,6 +59,7 @@ impl BlobInfo { #[skip_serializing_none] #[derive(Clone, Copy, Debug, Serialize, Deserialize)] +#[non_exhaustive] /// Information about packs within `repoinfo` pub struct PackInfo { /// Packs of the given blob type @@ -155,6 +158,7 @@ pub(crate) fn collect_index_infos( #[skip_serializing_none] #[derive(Default, Clone, Debug, Serialize, Deserialize)] +#[non_exhaustive] /// Information about repository files pub struct RepoFileInfos { /// Repository files @@ -164,6 +168,7 @@ pub struct RepoFileInfos { } #[derive(Clone, Copy, Debug, Serialize, Deserialize)] +#[non_exhaustive] /// Information about a repository files of a given [`FileType`] pub struct RepoFileInfo { /// The type of the files diff --git a/crates/core/src/commands/restore.rs b/crates/core/src/commands/restore.rs index d861022a..af44dfc1 100644 --- a/crates/core/src/commands/restore.rs +++ b/crates/core/src/commands/restore.rs @@ -44,6 +44,7 @@ type Filenames = Vec; #[cfg_attr(feature = "clap", derive(clap::Parser))] #[derive(Debug, Copy, Clone, Default, Setters)] #[setters(into)] +#[non_exhaustive] /// Options for the `restore` command pub struct RestoreOptions { /// Remove all files/dirs in destination which are not contained in snapshot. @@ -68,6 +69,7 @@ pub struct RestoreOptions { } #[derive(Default, Debug, Clone, Copy)] +#[non_exhaustive] /// Statistics for files or directories pub struct FileDirStats { /// Number of files or directories to restore @@ -83,6 +85,7 @@ pub struct FileDirStats { } #[derive(Default, Debug, Clone, Copy)] +#[non_exhaustive] /// Restore statistics pub struct RestoreStats { /// file statistics diff --git a/crates/core/src/repository.rs b/crates/core/src/repository.rs index f098f1fe..03a7d261 100644 --- a/crates/core/src/repository.rs +++ b/crates/core/src/repository.rs @@ -84,6 +84,7 @@ mod constants { #[derive(Clone, Default, Debug, serde::Deserialize, serde::Serialize, Setters)] #[serde(default, rename_all = "kebab-case", deny_unknown_fields)] #[setters(into, strip_option)] +#[non_exhaustive] pub struct RepositoryOptions { /// Password of the repository ///