Skip to main content

subxt_codegen/
ir.rs

1// Copyright 2019-2026 Parity Technologies (UK) Ltd.
2// This file is dual-licensed as Apache-2.0 or GPL-3.0.
3// see LICENSE for license details.
4
5use crate::error::CodegenError;
6use syn::token;
7
8#[derive(Debug, PartialEq, Eq)]
9pub struct ItemMod {
10    vis: syn::Visibility,
11    mod_token: token::Mod,
12    pub ident: syn::Ident,
13    brace: token::Brace,
14    items: Vec<syn::Item>,
15}
16
17impl TryFrom<syn::ItemMod> for ItemMod {
18    type Error = CodegenError;
19
20    fn try_from(module: syn::ItemMod) -> Result<Self, Self::Error> {
21        let (brace, items) = match module.content {
22            Some((brace, items)) => (brace, items),
23            None => return Err(CodegenError::InvalidModule(module.ident.span())),
24        };
25
26        Ok(Self {
27            vis: module.vis,
28            mod_token: module.mod_token,
29            ident: module.ident,
30            brace,
31            items,
32        })
33    }
34}
35
36impl ItemMod {
37    pub fn rust_items(&self) -> impl Iterator<Item = &syn::Item> {
38        self.items.iter()
39    }
40}