Move syntax Include to gen Include conversion to From impl

This commit is contained in:
David Tolnay 2020-10-28 15:43:35 -07:00
parent 2cc2e3a4d1
commit 353d98cdd9
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
2 changed files with 13 additions and 7 deletions

View File

@ -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<Include>) {
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 {

View File

@ -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);
}
}