Implement ListenMode::from_bytes
"external" is a weird name tho...
- Id
- 9c116bff7c2cbb961a727a5b9a26a9de8757c1d7
- Author
- Caio
- Commit time
- 2024-02-29T14:27:57+01:00
Modified caca/src/config.rs
}
#[derive(Debug, Clone)]
-#[allow(dead_code)]
pub(crate) enum ListenMode {
External,
Bind(BindOptions),
}
-#[allow(dead_code)]
+impl ListenMode {
+ // listen = "external"
+ // listen = "addr"
+ // listen = "addr,admin_addr"
+ fn from_bytes(data: &[u8]) -> crate::Result<Self> {
+ let text = std::str::from_utf8(data)?.trim();
+ if text == "external" {
+ Ok(Self::External)
+ } else if let Some((addr, admin_addr)) = text.split_once(',') {
+ Ok(Self::with_admin(addr.trim(), admin_addr.trim())?)
+ } else {
+ Ok(Self::addr(text)?)
+ }
+ }
+}
+
impl ListenMode {
pub fn external() -> Self {
Self::External