Skip to main content

munin_msbuild/
field_flags.rs

1// Copyright (c) Michael Grier
2
3//! Bitflags indicating which fields are present on a serialized `BuildEventArgs`.
4//!
5//! These flag values are part of the on-disk format. Changing any value is a
6//! breaking change.
7
8use serde::{Deserialize, Serialize};
9
10/// Bitmask specifying which fields are present on a serialized build event.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
12#[serde(transparent)]
13pub struct BuildEventArgsFieldFlags(u32);
14
15/// Individual flag constants. Changing any value is a breaking change.
16#[allow(non_upper_case_globals)]
17impl BuildEventArgsFieldFlags {
18    pub const NONE: Self = Self(0x0000);
19    pub const BUILD_EVENT_CONTEXT: Self = Self(0x0001);
20    pub const HELP_KEYWORD: Self = Self(0x0002);
21    pub const MESSAGE: Self = Self(0x0004);
22    pub const SENDER_NAME: Self = Self(0x0008);
23    pub const THREAD_ID: Self = Self(0x0010);
24    pub const TIMESTAMP: Self = Self(0x0020);
25    pub const SUBCATEGORY: Self = Self(0x0040);
26    pub const CODE: Self = Self(0x0080);
27    pub const FILE: Self = Self(0x0100);
28    pub const PROJECT_FILE: Self = Self(0x0200);
29    pub const LINE_NUMBER: Self = Self(0x0400);
30    pub const COLUMN_NUMBER: Self = Self(0x0800);
31    pub const END_LINE_NUMBER: Self = Self(0x1000);
32    pub const END_COLUMN_NUMBER: Self = Self(0x2000);
33    pub const ARGUMENTS: Self = Self(0x4000);
34    pub const IMPORTANCE: Self = Self(0x8000);
35    pub const EXTENDED: Self = Self(0x1_0000);
36}
37
38impl BuildEventArgsFieldFlags {
39    /// Create from a raw `u32` read from the stream.
40    pub fn from_raw(bits: u32) -> Self {
41        Self(bits)
42    }
43
44    /// Return the raw `u32` value.
45    pub fn bits(self) -> u32 {
46        self.0
47    }
48
49    /// Check whether a specific flag is set.
50    pub fn contains(self, flag: Self) -> bool {
51        self.0 & flag.0 == flag.0
52    }
53}
54
55impl std::ops::BitOr for BuildEventArgsFieldFlags {
56    type Output = Self;
57    fn bitor(self, rhs: Self) -> Self {
58        Self(self.0 | rhs.0)
59    }
60}
61
62impl std::ops::BitAnd for BuildEventArgsFieldFlags {
63    type Output = Self;
64    fn bitand(self, rhs: Self) -> Self {
65        Self(self.0 & rhs.0)
66    }
67}
68
69#[cfg(test)]
70mod tests;