feat: OpenAI-kompatible API mit Keys, Registry und serve-Befehl (M2.3)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
50
crates/nexus-core/src/priority.rs
Normal file
50
crates/nexus-core/src/priority.rs
Normal file
@ -0,0 +1,50 @@
|
||||
use std::fmt;
|
||||
|
||||
/// Priorität eines Jobs (Spezifikation, Abschnitt 6). Die Reihenfolge ist
|
||||
/// `Low < Normal < High`.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub enum Priority {
|
||||
Low,
|
||||
Normal,
|
||||
High,
|
||||
}
|
||||
|
||||
impl Priority {
|
||||
/// Schreibweise in Datenbank und Header: `low`, `normal`, `high`.
|
||||
pub fn as_str(self) -> &'static str {
|
||||
match self {
|
||||
Priority::Low => "low",
|
||||
Priority::Normal => "normal",
|
||||
Priority::High => "high",
|
||||
}
|
||||
}
|
||||
|
||||
/// Liest `low`, `normal`, `high` (Groß- und Kleinschreibung egal).
|
||||
pub fn parse(text: &str) -> Option<Self> {
|
||||
match text.trim().to_ascii_lowercase().as_str() {
|
||||
"low" => Some(Priority::Low),
|
||||
"normal" => Some(Priority::Normal),
|
||||
"high" => Some(Priority::High),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Priority {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str(self.as_str())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn reihenfolge_und_umwandlung() {
|
||||
assert!(Priority::Low < Priority::Normal && Priority::Normal < Priority::High);
|
||||
assert_eq!(Priority::parse(" HIGH "), Some(Priority::High));
|
||||
assert_eq!(Priority::parse("vip"), None);
|
||||
assert_eq!(Priority::Normal.to_string(), "normal");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user