Skip to content

Commit

Permalink
Move syntax Include to gen Include conversion to From impl
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Oct 28, 2020
1 parent 2cc2e3a commit 353d98c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
15 changes: 12 additions & 3 deletions gen/src/include.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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());
}
}

Expand All @@ -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 {
Expand Down
5 changes: 1 addition & 4 deletions gen/src/write.rs
Original file line number Diff line number Diff line change
@@ -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, *};
Expand All @@ -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);
}
}

Expand Down

0 comments on commit 353d98c

Please sign in to comment.