Skip to main content

max / mountaineer-sysop

643 B · 28 lines History Blame Raw
1 use anyhow::{Context, Result};
2 use serde::Deserialize;
3
4 const EMBEDDED: &str = include_str!("../data/roles.toml");
5
6 #[derive(Debug, Clone, Deserialize)]
7 pub struct Role {
8 pub name: String,
9 pub description: String,
10 pub tool: String,
11 pub packages: Vec<String>,
12 pub config_paths: Vec<String>,
13 }
14
15 #[derive(Debug, Deserialize)]
16 struct Registry {
17 role: Vec<Role>,
18 }
19
20 pub fn load() -> Result<Vec<Role>> {
21 let reg: Registry = toml::from_str(EMBEDDED).context("parse embedded roles.toml")?;
22 Ok(reg.role)
23 }
24
25 pub fn find<'a>(roles: &'a [Role], name: &str) -> Option<&'a Role> {
26 roles.iter().find(|r| r.name == name)
27 }
28