Unverified Commit 14d93244 authored by Steven Fackler's avatar Steven Fackler Committed by GitHub
Browse files

Merge pull request #1566 from sfackler/corresponds

Use a macro to reference the OpenSSL function a method calls
parents 160e6f42 bd191bca
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ jobs:
      - uses: actions/checkout@v2
      - uses: sfackler/actions/rustup@master
        with:
          version: 1.46.0
          version: 1.48.0
      - run: echo "::set-output name=version::$(rustc --version)"
        id: rust-version
      - uses: actions/cache@v1
+1 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
members = [
    "openssl",
    "openssl-errors",
    "openssl-macros",
    "openssl-sys",
    "systest",
]
+12 −0
Original line number Diff line number Diff line
[package]
name = "openssl-macros"
version = "0.1.0"
edition = "2018"

[lib]
proc-macro = true

[dependencies]
proc-macro2 = "1"
quote = "1"
syn = { version = "1", features = ["full"] }
+30 −0
Original line number Diff line number Diff line
use proc_macro::TokenStream;
use proc_macro2::Ident;
use quote::quote;
use syn::{parse_macro_input, ItemFn};

#[proc_macro_attribute]
pub fn corresponds(attr: TokenStream, item: TokenStream) -> TokenStream {
    let function = parse_macro_input!(attr as Ident);
    let item = parse_macro_input!(item as ItemFn);

    let function = function.to_string();
    let line = format!(
        "This corresponds to [`{0}`](https://www.openssl.org/docs/manmaster/man3/{0}.html).",
        function
    );

    let attrs = item.attrs;
    let vis = item.vis;
    let sig = item.sig;
    let block = item.block;

    let out = quote! {
        #(#attrs)*
        #[doc = ""]
        #[doc = #line]
        #[doc(alias = #function)]
        #vis #sig #block
    };
    out.into()
}
+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ foreign-types = "0.3.1"
libc = "0.2"
once_cell = "1.5.2"

openssl-macros = { path = "../openssl-macros" }
ffi = { package = "openssl-sys", version = "0.9.69", path = "../openssl-sys" }

[dev-dependencies]
Loading