diff --git a/gen/src/include.rs b/gen/src/include.rs index 705ca246..309d8c3d 100644 --- a/gen/src/include.rs +++ b/gen/src/include.rs @@ -1,5 +1,5 @@ use crate::gen::out::OutFile; -use crate::syntax::IncludeKind; +use crate::syntax::{self, IncludeKind}; use std::fmt::{self, Display}; /// The complete contents of the "rust/cxx.h" header. @@ -84,8 +84,8 @@ impl Includes { Includes::default() } - pub fn insert(&mut self, include: Include) { - self.custom.push(include); + pub fn insert(&mut self, include: impl Into) { + self.custom.push(include.into()); } } @@ -95,6 +95,15 @@ impl<'a> Extend<&'a Include> for Includes { } } +impl<'a> From<&'a syntax::Include> for Include { + fn from(include: &syntax::Include) -> Self { + Include { + path: include.path.clone(), + kind: include.kind, + } + } +} + impl Display for Includes { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { for include in &self.custom { diff --git a/gen/src/write.rs b/gen/src/write.rs index f1c7a110..01617cab 100644 --- a/gen/src/write.rs +++ b/gen/src/write.rs @@ -1,4 +1,3 @@ -use crate::gen::include::Include; use crate::gen::out::OutFile; use crate::gen::{include, Opt}; use crate::syntax::atom::Atom::{self, *}; @@ -25,9 +24,7 @@ pub(super) fn gen( out.include.extend(&opt.include); for api in apis { if let Api::Include(include) = api { - let path = include.path.clone(); - let kind = include.kind; - out.include.insert(Include { path, kind }); + out.include.insert(include); } }