Skip to main content

twine_codec/
role.rs

1// Copyright (c) 2025 Jake Swensen
2// SPDX-License-Identifier: MPL-2.0
3//
4// This Source Code Form is subject to the terms of the Mozilla Public
5// License, v. 2.0. If a copy of the MPL was not distributed with this
6// file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
8use core::str::FromStr;
9
10use crate::error::TwineCodecError;
11
12#[derive(Debug, Default)]
13pub enum NetworkRole {
14    #[default]
15    Disabled,
16    Detached,
17    Child,
18    Router,
19    Leader,
20}
21
22impl FromStr for NetworkRole {
23    type Err = TwineCodecError;
24
25    fn from_str(s: &str) -> Result<Self, Self::Err> {
26        match s.to_lowercase().as_str() {
27            "disabled" => Ok(NetworkRole::Disabled),
28            "detached" => Ok(NetworkRole::Detached),
29            "child" => Ok(NetworkRole::Child),
30            "router" => Ok(NetworkRole::Router),
31            "leader" => Ok(NetworkRole::Leader),
32            _ => Err(TwineCodecError::StringParseError),
33        }
34    }
35}