-
-
Save rust-play/abc41037cceb0adf64fa2d6365834526 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_use] | |
extern crate bitflags; | |
bitflags! { | |
struct FileFlags: u32 { | |
const DEVICE = 0b00000001; | |
const EXECUTABLE = 0b00000010; | |
const LOGFILE = 0b00000100; | |
const BACKUP = 0b00001000; | |
const DIRECTORY = 0b00010000; | |
const CASCADE = 0b00100000; | |
const IMMUTABLE = 0b01000000; | |
const LOG_ACCESS = 0b10000000; | |
const USER_FILE = Self::LOG_ACCESS.bits | Self::BACKUP.bits | Self::CASCADE.bits; | |
} | |
} | |
struct File { | |
flags: FileFlags, | |
owner: usize, | |
} | |
fn main() { | |
use std::collections::BTreeMap; | |
let mut filesystem = BTreeMap::new(); | |
filesystem.insert("./my-app/err.log", File{flags: FileFlags::LOGFILE, owner: 1}); | |
filesystem.insert("./my-app/out.log", File{flags: FileFlags::LOGFILE, owner: 1}); | |
filesystem.insert("./my-app/app.conf", File{flags: FileFlags::BACKUP, owner: 1}); | |
filesystem.insert("./passwords.vault", File{flags: FileFlags::USER_FILE | FileFlags::IMMUTABLE, owner: 200}); | |
for (path, f) in &filesystem { | |
if f.flags.contains(FileFlags::BACKUP) { | |
println!("backing up {} for user {}", path, f.owner); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment