From 6accb4d80c750c60d53f2d8246865e78731ce535 Mon Sep 17 00:00:00 2001 From: David Calavera Date: Thu, 20 Jan 2022 21:23:41 -0800 Subject: [PATCH] Expose Scope#items Items can be used to perform actions based on what's in the Scope. Signed-off-by: David Calavera --- src/item.rs | 8 ++++++++ src/lib.rs | 1 + src/scope.rs | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/src/item.rs b/src/item.rs index 5f6fb62..a42282e 100644 --- a/src/item.rs +++ b/src/item.rs @@ -6,13 +6,21 @@ use crate::r#impl::Impl; use crate::r#struct::Struct; use crate::r#trait::Trait; +/// The types of items that can be defined. #[derive(Debug, Clone)] pub enum Item { + /// Module Module(Module), + /// Struct Struct(Struct), + /// Function Function(Function), + /// Trait Trait(Trait), + /// Enum Enum(Enum), + /// Impl Impl(Impl), + /// Raw Raw(String), } diff --git a/src/lib.rs b/src/lib.rs index 70b8675..8d318bf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -54,6 +54,7 @@ pub use field::*; pub use formatter::*; pub use function::*; pub use import::*; +pub use item::*; pub use module::*; pub use scope::*; pub use variant::*; diff --git a/src/scope.rs b/src/scope.rs index 1312139..95b0275 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -233,6 +233,11 @@ impl Scope { ret } + /// Return the items in the scope. + pub fn items(&self) -> &Vec { + &self.items + } + /// Formats the scope using the given formatter. pub fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { self.fmt_imports(fmt)?;