Skip to content

Commit

Permalink
Improve Debug display of flags by showing them in hexa
Browse files Browse the repository at this point in the history
  • Loading branch information
touilleMan committed Mar 15, 2024
1 parent 316383d commit 2080f57
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions winfsp_wrs/src/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,24 @@ use crate::ext::{
FspCleanupSetChangeTime, FspCleanupSetLastAccessTime, FspCleanupSetLastWriteTime,
};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
macro_rules! impl_debug_flags {
($name:ident) => {

Check warning on line 34 in winfsp_wrs/src/flags.rs

View workflow job for this annotation

GitHub Actions / ci

Diff in \\?\D:\a\winfsp_wrs\winfsp_wrs\winfsp_wrs\src\flags.rs

Check warning on line 34 in winfsp_wrs/src/flags.rs

View workflow job for this annotation

GitHub Actions / ci

Diff in \\?\D:\a\winfsp_wrs\winfsp_wrs\winfsp_wrs\src\flags.rs
impl std::fmt::Debug for $name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_tuple("FileAttributes").field(&format_args!("0x{:X}", self.0)).finish()
}
}
};
}

#[derive(Clone, Copy, PartialEq, Eq, Hash)]
/// File attributes are metadata values stored by the file system on disk and
/// are used by the system and are available to developers via various file I/O
/// APIs.
pub struct FileAttributes(pub FILE_FLAGS_AND_ATTRIBUTES);

impl_debug_flags!(FileAttributes);

impl FileAttributes {
/// A file that is read-only. Applications can read the file, but cannot write
/// to it or delete it. This attribute is not honored on directories. For more
Expand Down Expand Up @@ -224,9 +236,11 @@ impl BitOrAssign for FileAttributes {
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct CreateOptions(pub u32);

impl_debug_flags!(CreateOptions);

impl CreateOptions {
pub const fn file_directory_file() -> Self {
Self(FILE_DIRECTORY_FILE)
Expand Down Expand Up @@ -259,9 +273,11 @@ impl BitOrAssign for CreateOptions {
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct FileAccessRights(pub FILE_ACCESS_RIGHTS);

impl_debug_flags!(FileAccessRights);

impl FileAccessRights {
/// For a file object, the right to read the corresponding file data. For a
/// directory object, the right to read the corresponding directory data.
Expand Down Expand Up @@ -429,9 +445,11 @@ impl BitOrAssign for FileAccessRights {
}
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub struct CleanupFlags(pub i32);

impl_debug_flags!(CleanupFlags);

impl CleanupFlags {
pub const fn delete() -> Self {
Self(FspCleanupDelete)
Expand Down Expand Up @@ -476,9 +494,11 @@ impl BitOrAssign for CleanupFlags {
}
}

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash)]
#[derive(Default, Clone, Copy, PartialEq, Eq, Hash)]
pub struct FileShareMode(pub FILE_SHARE_MODE);

impl_debug_flags!(FileShareMode);

impl FileShareMode {
pub const fn none() -> Self {
Self(FILE_SHARE_NONE)
Expand Down

0 comments on commit 2080f57

Please sign in to comment.