1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#![allow(dead_code)]
mod gen;
mod syntax;
pub use crate::gen::{GeneratedCode, Opt};
use proc_macro2::TokenStream;
use std::error::Error as StdError;
use std::fmt::{self, Debug, Display};
pub struct Error(crate::gen::Error);
pub fn generate_header_and_cc(rust_source: TokenStream, opt: &Opt) -> Result<GeneratedCode, Error> {
let syntax = syn::parse2(rust_source)
.map_err(crate::gen::Error::from)
.map_err(Error)?;
gen::generate(syntax, opt).map_err(Error)
}
impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Display::fmt(&self.0, f)
}
}
impl Debug for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
Debug::fmt(&self.0, f)
}
}
impl StdError for Error {
fn source(&self) -> Option<&(dyn StdError + 'static)> {
self.0.source()
}
}