Debian Codegraph @

src/options/config/disk.rs

raw symbols SCIP
1 use serderust-analyzer cargo serde 1.0.228 crate/::Deserializerust-analyzer cargo serde_core 1.0.228 de/Deserialize#;
2
3 use superrust-analyzer cargo bottom 0.14.9 options/config/::IgnoreListrust-analyzer cargo bottom 0.14.9 options/config/ignore_list/IgnoreList#;
4 use craterust-analyzer cargo bottom 0.14.9 crate/::{canvasrust-analyzer cargo bottom 0.14.9 canvas/::componentsrust-analyzer cargo bottom 0.14.9 canvas/components/::data_tablerust-analyzer cargo bottom 0.14.9 canvas/components/data_table/::SortOrderrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/sortable/SortOrder#, optionsrust-analyzer cargo bottom 0.14.9 options/::DiskWidgetColumnrust-analyzer cargo bottom 0.14.9 widgets/disk_table/DiskWidgetColumn#};
5
6 /// Disk configuration.
7 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:, Deserializerust-analyzer cargo serde_derive 1.0.228 Deserialize:)]
8 #[cfg_attr(feature = "generate_schema", derive(schemars::JsonSchema))]
9 #[cfg_attr(test, serde(deny_unknown_fields), derive(PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:))]
10 pub(craterust-analyzer cargo bottom 0.14.9 crate/) struct DiskConfigrust-analyzer cargo bottom 0.14.9 options/config/disk/DiskConfig# {
11 /// A filter over the disk names.
12 pub(craterust-analyzer cargo bottom 0.14.9 crate/) name_filterrust-analyzer cargo bottom 0.14.9 options/config/disk/DiskConfig#name_filter.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<IgnoreListrust-analyzer cargo bottom 0.14.9 options/config/ignore_list/IgnoreList#>,
13
14 /// A filter over the mount names.
15 pub(craterust-analyzer cargo bottom 0.14.9 crate/) mount_filterrust-analyzer cargo bottom 0.14.9 options/config/disk/DiskConfig#mount_filter.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<IgnoreListrust-analyzer cargo bottom 0.14.9 options/config/ignore_list/IgnoreList#>,
16
17 /// Whether to include block devices that aren't currently mounted (currently Linux only). Defaults to false.
18 pub(craterust-analyzer cargo bottom 0.14.9 crate/) include_unmountedrust-analyzer cargo bottom 0.14.9 options/config/disk/DiskConfig#include_unmounted.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<bool>,
19
20 /// A list of disk widget columns.
21 // TODO: make this more composable(?) in the future, we might need to
22 // rethink how it's done for custom widgets.
23 #[serderust-analyzer cargo serde_derive 1.0.228 serde:(default)]
24 pub(craterust-analyzer cargo bottom 0.14.9 crate/) columnsrust-analyzer cargo bottom 0.14.9 options/config/disk/DiskConfig#columns.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<DiskWidgetColumnrust-analyzer cargo bottom 0.14.9 widgets/disk_table/DiskWidgetColumn#>>,
25
26 /// The default sort column.
27 #[serderust-analyzer cargo serde_derive 1.0.228 serde:(default)]
28 pub(craterust-analyzer cargo bottom 0.14.9 crate/) default_sortrust-analyzer cargo bottom 0.14.9 options/config/disk/DiskConfig#default_sort.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<DiskWidgetColumnrust-analyzer cargo bottom 0.14.9 widgets/disk_table/DiskWidgetColumn#>,
29
30 /// The default sort order. Defaults to ascending.
31 #[serderust-analyzer cargo serde_derive 1.0.228 serde:(default)]
32 pub(craterust-analyzer cargo bottom 0.14.9 crate/) sort_orderrust-analyzer cargo bottom 0.14.9 options/config/disk/DiskConfig#sort_order.: SortOrderrust-analyzer cargo bottom 0.14.9 canvas/components/data_table/sortable/SortOrder#,
33 }
34
35 #[cfg(test)]
36 mod testrust-analyzer cargo bottom 0.14.9 options/config/disk/test/ {
37 use superrust-analyzer cargo bottom 0.14.9 options/config/disk/::DiskConfigrust-analyzer cargo bottom 0.14.9 options/config/disk/DiskConfig#;
38
39 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
40 fn none_column_settingrust-analyzer cargo bottom 0.14.9 options/config/disk/test/none_column_setting().() {
41 let config = "";
42 let generated: DiskConfigrust-analyzer cargo bottom 0.14.9 options/config/disk/DiskConfig# = toml_editrust-analyzer cargo toml_edit 0.25.12+spec-1.1.0 crate/::derust-analyzer cargo toml_edit 0.25.12+spec-1.1.0 de/::from_strrust-analyzer cargo toml_edit 0.25.12+spec-1.1.0 de/from_str().(config).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
43 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(generated.columnsrust-analyzer cargo bottom 0.14.9 options/config/disk/DiskConfig#columns..is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().());
44 }
45
46 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
47 fn empty_column_settingrust-analyzer cargo bottom 0.14.9 options/config/disk/test/empty_column_setting().() {
48 let config = r#"columns = []"#;
49 let generated: DiskConfigrust-analyzer cargo bottom 0.14.9 options/config/disk/DiskConfig# = toml_editrust-analyzer cargo toml_edit 0.25.12+spec-1.1.0 crate/::derust-analyzer cargo toml_edit 0.25.12+spec-1.1.0 de/::from_strrust-analyzer cargo toml_edit 0.25.12+spec-1.1.0 de/from_str().(config).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
50 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(generated.columnsrust-analyzer cargo bottom 0.14.9 options/config/disk/DiskConfig#columns..unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().().is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().());
51 }
52
53 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
54 fn valid_disk_column_settingsrust-analyzer cargo bottom 0.14.9 options/config/disk/test/valid_disk_column_settings().() {
55 let config = r#"columns = ["disk", "mount", "used", "free", "total", "used%", "free%", "r/s", "w/s"]"#;
56 toml_editrust-analyzer cargo toml_edit 0.25.12+spec-1.1.0 crate/::derust-analyzer cargo toml_edit 0.25.12+spec-1.1.0 de/::from_strrust-analyzer cargo toml_edit 0.25.12+spec-1.1.0 de/from_str().::<DiskConfigrust-analyzer cargo bottom 0.14.9 options/config/disk/DiskConfig#>(config).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("Should succeed!");
57 }
58
59 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
60 fn bad_disk_column_settingsrust-analyzer cargo bottom 0.14.9 options/config/disk/test/bad_disk_column_settings().() {
61 let config = r#"columns = ["diskk"]"#;
62 toml_editrust-analyzer cargo toml_edit 0.25.12+spec-1.1.0 crate/::derust-analyzer cargo toml_edit 0.25.12+spec-1.1.0 de/::from_strrust-analyzer cargo toml_edit 0.25.12+spec-1.1.0 de/from_str().::<DiskConfigrust-analyzer cargo bottom 0.14.9 options/config/disk/DiskConfig#>(config).expect_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect_err().("Should error out!");
63 }
64
65 /// Test that disk enum variants that are advertised in the schema are valid.
66 #[cfg(feature = "generate_schema")]
67 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
68 fn ensure_disk_column_schema_is_accepted() {
69 use strum::VariantArray;
70
71 use craterust-analyzer cargo bottom 0.14.9 crate/::optionsrust-analyzer cargo bottom 0.14.9 options/::{Configrust-analyzer cargo bottom 0.14.9 options/config/Config#, DiskWidgetColumnrust-analyzer cargo bottom 0.14.9 widgets/disk_table/DiskWidgetColumn#};
72
73 for column in DiskWidgetColumn::VARIANTS {
74 for &name in columnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/column!.get_schema_names() {
75 let config = formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("[disk]\ncolumns = [\"{name}\"]\n");
76 toml_editrust-analyzer cargo toml_edit 0.25.12+spec-1.1.0 crate/::derust-analyzer cargo toml_edit 0.25.12+spec-1.1.0 de/::from_strrust-analyzer cargo toml_edit 0.25.12+spec-1.1.0 de/from_str().::<Config>(&config).unwrap_or_else(|e| {
77 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("schema name {name:?} was rejected:\n{e}\nconfig was:\n{config}")
78 });
79 }
80 }
81 }
82 }