zellij_utils/plugin_api/
pane_frame_style.rs1pub use super::generated_api::api::pane_frame_style::PaneFrameStyle as ProtobufPaneFrameStyle;
2use crate::input::options::PaneFrameStyle;
3
4use std::convert::TryFrom;
5
6impl TryFrom<ProtobufPaneFrameStyle> for PaneFrameStyle {
7 type Error = &'static str;
8 fn try_from(protobuf_pane_frame_style: ProtobufPaneFrameStyle) -> Result<Self, &'static str> {
9 match protobuf_pane_frame_style {
10 ProtobufPaneFrameStyle::Full => Ok(PaneFrameStyle::Full),
11 ProtobufPaneFrameStyle::Titles => Ok(PaneFrameStyle::Titles),
12 ProtobufPaneFrameStyle::None => Ok(PaneFrameStyle::None),
13 }
14 }
15}
16
17impl TryFrom<PaneFrameStyle> for ProtobufPaneFrameStyle {
18 type Error = &'static str;
19 fn try_from(pane_frame_style: PaneFrameStyle) -> Result<Self, &'static str> {
20 Ok(match pane_frame_style {
21 PaneFrameStyle::Full => ProtobufPaneFrameStyle::Full,
22 PaneFrameStyle::Titles => ProtobufPaneFrameStyle::Titles,
23 PaneFrameStyle::None => ProtobufPaneFrameStyle::None,
24 })
25 }
26}
27
28#[cfg(test)]
29mod tests {
30 use super::*;
31
32 #[test]
33 fn pane_frame_style_roundtrips_through_protobuf() {
34 for style in [
35 PaneFrameStyle::Full,
36 PaneFrameStyle::Titles,
37 PaneFrameStyle::None,
38 ] {
39 let protobuf: ProtobufPaneFrameStyle = style.try_into().unwrap();
40 let roundtripped: PaneFrameStyle = protobuf.try_into().unwrap();
41 assert_eq!(style, roundtripped);
42 }
43 }
44
45 #[test]
46 fn unknown_pane_frame_style_value_is_rejected() {
47 assert!(ProtobufPaneFrameStyle::try_from(99).is_err());
48 }
49}