Borrow syntax tree idents to make Block copyable
diff --git a/gen/src/alphasort.rs b/gen/src/alphasort.rs
index ea911f8..95b49a6 100644
--- a/gen/src/alphasort.rs
+++ b/gen/src/alphasort.rs
@@ -18,7 +18,7 @@
&self.direct
}
- pub fn nested_content(&self) -> impl Iterator<Item = (&Ident, &NamespaceEntries)> {
+ pub fn nested_content(&self) -> impl Iterator<Item = (&'a Ident, &NamespaceEntries<'a>)> {
self.nested.iter().map(|(k, entries)| (*k, entries))
}
}
diff --git a/gen/src/block.rs b/gen/src/block.rs
index e7f7c63..7775c52 100644
--- a/gen/src/block.rs
+++ b/gen/src/block.rs
@@ -1,14 +1,15 @@
use proc_macro2::Ident;
-pub enum Block {
+#[derive(Copy, Clone)]
+pub enum Block<'a> {
AnonymousNamespace,
Namespace(&'static str),
- UserDefinedNamespace(Ident),
+ UserDefinedNamespace(&'a Ident),
InlineNamespace(&'static str),
ExternC,
}
-impl Block {
+impl<'a> Block<'a> {
pub fn write_begin(&self, out: &mut String) {
if let Block::InlineNamespace(_) = self {
out.push_str("inline ");
diff --git a/gen/src/builtin.rs b/gen/src/builtin.rs
index e755e10..4b8dce5 100644
--- a/gen/src/builtin.rs
+++ b/gen/src/builtin.rs
@@ -3,7 +3,7 @@
use crate::gen::out::{Content, OutFile};
#[derive(Default, PartialEq)]
-pub struct Builtins {
+pub struct Builtins<'a> {
pub panic: bool,
pub rust_string: bool,
pub rust_str: bool,
@@ -22,10 +22,10 @@
pub rust_str_repr: bool,
pub rust_slice_new: bool,
pub rust_slice_repr: bool,
- pub content: Content,
+ pub content: Content<'a>,
}
-impl Builtins {
+impl<'a> Builtins<'a> {
pub fn new() -> Self {
Builtins::default()
}
diff --git a/gen/src/include.rs b/gen/src/include.rs
index 8dc7146..d88c12d 100644
--- a/gen/src/include.rs
+++ b/gen/src/include.rs
@@ -19,7 +19,7 @@
}
#[derive(Default, PartialEq)]
-pub struct Includes {
+pub struct Includes<'a> {
pub custom: Vec<Include>,
pub array: bool,
pub cstddef: bool,
@@ -33,10 +33,10 @@
pub utility: bool,
pub vector: bool,
pub basetsd: bool,
- pub content: Content,
+ pub content: Content<'a>,
}
-impl Includes {
+impl<'a> Includes<'a> {
pub fn new() -> Self {
Includes::default()
}
@@ -101,13 +101,13 @@
}
}
-impl<'a> Extend<&'a Include> for Includes {
- fn extend<I: IntoIterator<Item = &'a Include>>(&mut self, iter: I) {
+impl<'i, 'a> Extend<&'i Include> for Includes<'a> {
+ fn extend<I: IntoIterator<Item = &'i Include>>(&mut self, iter: I) {
self.custom.extend(iter.into_iter().cloned());
}
}
-impl<'a> From<&'a syntax::Include> for Include {
+impl<'i> From<&'i syntax::Include> for Include {
fn from(include: &syntax::Include) -> Self {
Include {
path: include.path.clone(),
@@ -116,15 +116,15 @@
}
}
-impl Deref for Includes {
- type Target = Content;
+impl<'a> Deref for Includes<'a> {
+ type Target = Content<'a>;
fn deref(&self) -> &Self::Target {
&self.content
}
}
-impl DerefMut for Includes {
+impl<'a> DerefMut for Includes<'a> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.content
}
diff --git a/gen/src/out.rs b/gen/src/out.rs
index 606a586..6867a76 100644
--- a/gen/src/out.rs
+++ b/gen/src/out.rs
@@ -10,16 +10,16 @@
pub header: bool,
pub opt: &'a Opt,
pub types: &'a Types<'a>,
- pub include: Includes,
- pub builtin: Builtins,
- content: RefCell<Content>,
+ pub include: Includes<'a>,
+ pub builtin: Builtins<'a>,
+ content: RefCell<Content<'a>>,
}
#[derive(Default)]
-pub struct Content {
+pub struct Content<'a> {
bytes: String,
section_pending: bool,
- blocks_pending: Vec<Block>,
+ blocks_pending: Vec<Block<'a>>,
}
impl<'a> OutFile<'a> {
@@ -39,11 +39,11 @@
self.content.get_mut().next_section();
}
- pub fn begin_block(&mut self, block: Block) {
+ pub fn begin_block(&mut self, block: Block<'a>) {
self.content.get_mut().begin_block(block);
}
- pub fn end_block(&mut self, block: Block) {
+ pub fn end_block(&mut self, block: Block<'a>) {
self.content.get_mut().end_block(block);
}
@@ -74,20 +74,20 @@
}
}
-impl Write for Content {
+impl<'a> Write for Content<'a> {
fn write_str(&mut self, s: &str) -> fmt::Result {
self.write(s);
Ok(())
}
}
-impl PartialEq for Content {
+impl<'a> PartialEq for Content<'a> {
fn eq(&self, _other: &Content) -> bool {
true
}
}
-impl Content {
+impl<'a> Content<'a> {
fn new() -> Self {
Content::default()
}
@@ -96,11 +96,11 @@
self.section_pending = true;
}
- pub fn begin_block(&mut self, block: Block) {
+ pub fn begin_block(&mut self, block: Block<'a>) {
self.blocks_pending.push(block);
}
- pub fn end_block(&mut self, block: Block) {
+ pub fn end_block(&mut self, block: Block<'a>) {
if self.blocks_pending.pop().is_none() {
Block::write_end(&block, &mut self.bytes);
self.section_pending = true;
diff --git a/gen/src/write.rs b/gen/src/write.rs
index a1f168f..0b6a5aa 100644
--- a/gen/src/write.rs
+++ b/gen/src/write.rs
@@ -57,7 +57,7 @@
}
}
-fn gen_namespace_contents(out: &mut OutFile, ns_entries: &NamespaceEntries) {
+fn gen_namespace_contents<'a>(out: &mut OutFile<'a>, ns_entries: &NamespaceEntries<'a>) {
let apis = ns_entries.direct_content();
let mut methods_for_type = HashMap::new();
@@ -128,9 +128,10 @@
}
for (namespace, nested_ns_entries) in ns_entries.nested_content() {
- out.begin_block(Block::UserDefinedNamespace(namespace.clone()));
+ let block = Block::UserDefinedNamespace(namespace);
+ out.begin_block(block);
gen_namespace_contents(out, nested_ns_entries);
- out.end_block(Block::UserDefinedNamespace(namespace.clone()));
+ out.end_block(block);
}
}