use bitflags::bitflags;
bitflags! {
pub struct FilePermissions: u32 {
const READ = 0b00000001;
const WRITE = 0b00000010;
const EXECUTE = 0b00000100;
}
}
fn main() {
let mut perm = FilePermissions::READ | FilePermissions::WRITE;
// 检查是否包含某个标记
if perm.contains(FilePermissions::READ) {
println!("Read permission is set.");
}
// 添加一个标记
perm.insert(FilePermissions::EXECUTE);
if perm.contains(FilePermissions::EXECUTE) {
println!("Execute permission is set.");
}
// 移除一个标记
perm.remove(FilePermissions::WRITE);
if !perm.contains(FilePermissions::WRITE) {
println!("Write permission is not set.");
}
// 打印当前所有标记
println!("Current permissions: {:?}", perm);
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。