codama_koroks/
impl_item_korok.rs1use crate::{ConstKorok, KorokTrait, UnsupportedImplItemKorok};
2use codama_attributes::Attributes;
3use codama_errors::{CodamaResult, IteratorCombineErrors};
4use codama_nodes::Node;
5
6#[derive(Debug, PartialEq)]
7pub enum ImplItemKorok<'a> {
8 Const(ConstKorok<'a>),
9 Unsupported(UnsupportedImplItemKorok<'a>),
10}
11
12impl<'a> ImplItemKorok<'a> {
13 pub fn parse(item: &'a syn::ImplItem) -> CodamaResult<Self> {
14 match item {
15 syn::ImplItem::Const(_) => Ok(ImplItemKorok::Const(ConstKorok::parse_impl_item(item)?)),
16 _ => Ok(ImplItemKorok::Unsupported(UnsupportedImplItemKorok::parse(
17 item,
18 )?)),
19 }
20 }
21
22 pub fn parse_all(items: &'a [syn::ImplItem]) -> CodamaResult<Vec<Self>> {
23 items.iter().map(Self::parse).collect_and_combine_errors()
24 }
25}
26
27impl KorokTrait for ImplItemKorok<'_> {
28 fn node(&self) -> &Option<Node> {
29 match self {
30 ImplItemKorok::Const(k) => k.node(),
31 ImplItemKorok::Unsupported(k) => k.node(),
32 }
33 }
34
35 fn set_node(&mut self, node: Option<Node>) {
36 match self {
37 ImplItemKorok::Const(k) => k.set_node(node),
38 ImplItemKorok::Unsupported(k) => k.set_node(node),
39 }
40 }
41
42 fn attributes(&self) -> Option<&Attributes<'_>> {
43 match self {
44 ImplItemKorok::Const(k) => k.attributes(),
45 ImplItemKorok::Unsupported(k) => k.attributes(),
46 }
47 }
48}