A library for extracting #[no_mangle] pub extern "C" functions (https://docs.rust-embedded.org/book/interoperability/rust-with-c.html#no_mangle)

Overview

A library for extracting #[no_mangle] pub extern "C" functions

In order to expose a function with C binary interface for interoperability with other programming languages, Rust developers should use #[no_mangle] attribute and specify ABI for the declared function.

#[no_mangle]
pub extern "C" fn func_name () /* -> ... */ {
    // ...
}

You can read about it more here

This library allows to perform syn-driven parsing for obtaining the information about location of these no-mangle-pub-extern-C functions.

Example

main.rs

use no_mangle_pub_export_c_fn::{parse_for_no_mangle_pub_extern_c_fns, ParsedFile};

fn main() {
    let crate_root = std::env::var("CARGO_MANIFEST_DIR").unwrap();
    let parsed_files: Vec<ParsedFile> = parse_for_no_mangle_pub_extern_c_fns(crate_root.as_str());
    println!("{:#?}", parsed_files);
}

unused.rs

#[no_mangle]
pub extern "C" fn s() {
    // test
}

Output on Windows

[
ParsedFile {
    path: "...\\no_mangle_pub_export_c_fn\\src\\lib.rs",
    no_mangle_pub_export_c_fns: NoManglePubExportCFns {
        no_mangle_pub_export_c_fn_vec: [],
    },
},
ParsedFile {
    path: "...\\no_mangle_pub_export_c_fn\\src\\main.rs",
    no_mangle_pub_export_c_fns: NoManglePubExportCFns {
        no_mangle_pub_export_c_fn_vec: [],
    },
},
ParsedFile {
    path: "...\\no_mangle_pub_export_c_fn\\src\\unused.rs",
    no_mangle_pub_export_c_fns: NoManglePubExportCFns {
        no_mangle_pub_export_c_fn_vec: [
            NoManglePubExportCFnEnds {
                start_line: 1,
                start_column: 0,
                end_line: 4,
                end_column: 1,
            },
        ],
    },
},
]

Seralization & Deserialization

All structures in this library implement Serialize and Deserialize traits from serde. Because of that you can convert into many data formats supporting serde.

Data formats

  • JSON, the ubiquitous JavaScript Object Notation used by many HTTP APIs.
  • Bincode, a compact binary format used for IPC within the Servo rendering engine.
  • CBOR, a Concise Binary Object Representation designed for small message size without the need for version negotiation.
  • YAML, a self-proclaimed human-friendly configuration language that ain't markup language.
  • MessagePack, an efficient binary format that resembles a compact JSON.
  • TOML, a minimal configuration format used by Cargo.
  • Pickle, a format common in the Python world.
  • RON, a Rusty Object Notation.
  • BSON, the data storage and network transfer format used by MongoDB.
  • Avro, a binary format used within Apache Hadoop, with support for schema definition.
  • JSON5, a superset of JSON including some productions from ES5.
  • Postcard, a no_std and embedded-systems friendly compact binary format.
  • URL query strings, in the x-www-form-urlencoded format.
  • Envy, a way to deserialize environment variables into Rust structs. (deserialization only)
  • Envy Store, a way to deserialize AWS Parameter Store parameters into Rust structs. (deserialization only)
  • S-expressions, the textual representation of code and data used by the Lisp language family.
  • D-Bus's binary wire format.
  • FlexBuffers, the schemaless cousin of Google's FlatBuffers zero-copy serialization format.
  • DynamoDB Items, the format used by rusoto_dynamodb to transfer data to and from DynamoDB.

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
You might also like...
Book - Actix user guides

User guides Actix User Guide Actix API Documentation (Development) Actix API Documentation (Releases) Actix Web User Guide Actix Web API Documentation

Complete code for the larger example programs from the book.

Code Examples for Programming Rust This repository contains complete code for the larger example programs from the book “Programming Rust”, by Jim Bla

Majestic Lisp book and implementation, in Brazillian Portuguese.

Majestic Lisp Criado e desenvolvido por Lucas S. Vieira lucasvieira at protonmail dot com. Seja bem-vindo(a) a Majestic Lisp, um dialeto de Lisp cuj

Generate SUMMARY.md files based on your book's file structure

mdbook-autosummary Generate a SUMMARY.md for your mdBook based on your folder structure! Warning The implementation is hacky and has several limitatio

Generate rust structs & query functions from diesel schema files

dsync A utility to generate database structs and querying code from diesel schema files. Primarily built for create-rust-app. Currently, it's more adv

A Rust crate providing utility functions and macros.

介绍 此库提供四类功能:异常处理、http post收发对象、格式转换、语法糖。 在 Cargo.toml 里添加如下依赖项 [dependencies.xuanmi_base_support] git = "https://github.com/taiyi-research-institute/x

Functions for mapping plaintexts to a u64 while preserving sort order

ore_encoding.rs This is a companion package to ore.rs that can generate and manipulate u64 plaintexts before they are encrypted by ore.rs. Being able

proc-macro to help with using surrealdb's custom functions

SurrealDB Functions This is a proc-macro crate that given a path to a .surql file or a folder of .surql files, will parse DEFINE FUNCTION fn::s inside

Trying embedded Rust on the Pinecil GD32VF103 RISC-V device.
Trying embedded Rust on the Pinecil GD32VF103 RISC-V device.

Pinecil GD32VF103 RISC-V Rust Demos My personal collection of Rust demos running on the PINE64 Pinecil portable soldering iron, featuring a GD32VF103T

Owner
Dmitrii - Demenev
Rust developer trying his best to make the world a better place
Dmitrii - Demenev
clone of grep cli written in Rust. From Chapter 12 of the Rust Programming Language book

minigrep is a clone of the grep cli in rust Minigrep will find a query string in a file. To test it out, clone the project and run cargo run body poem

Raunak Singh 1 Dec 14, 2021
The ray tracer challenge in rust - Repository to follow my development of "The Raytracer Challenge" book by Jamis Buck in the language Rust

The Ray Tracer Challenge This repository contains all the code written, while step by implementing Ray Tracer, based on the book "The Ray Tracer Chall

Jakob Westhoff 54 Dec 25, 2022
A minimal version of 'grep' implemented in Rust. Exercise in the "The Rust Programming Language" book.

Minigrep - A simple grep-like tool implemented in Rust This simple CLI tool searches for a given pattern in a specified file and as a result, it print

Filip Szutkowski 3 Mar 15, 2024
This repository contains the source of "The Rust Programming Language" book.

The Rust Programming Language This repository contains the source of "The Rust Programming Language" book. The book is available in dead-tree form fro

The Rust Programming Language 11.2k Jan 8, 2023
Source code for the book Rust in Action

Welcome to Rust in Action source code This source code repository is a companion to the Rust in Action book available from Manning Publications. Suppo

Rust in Action 1.3k Dec 30, 2022
Code to follow along the "Zero To Production" book on API development in Rust.

Zero To Production / Code (Chapter 10 - Part 1) Zero To Production In Rust is an opinionated introduction to backend development using Rust. This repo

Luca Palmieri 2.8k Dec 31, 2022
Rust crate to implement a counterpart to the PBRT book's (3rd edition) C++ code.

Rust crate to implement a counterpart to the PBRT book's (3rd edition) C++ code.

Jan Walter 763 Dec 27, 2022
High Assurance Rust - A free book about developing secure and robust systems software.

High Assurance Rust - A free book about developing secure and robust systems software.

Tiemoko Ballo 1.1k Jan 9, 2023
Learn programming with Rust as a first language (book)

Learn programming with Rust as first language This is a book to learn programming from scratch. Read the book here: https://deavid.github.io/lprfl/ LI

David Martínez Martí 2 May 21, 2022
Search and read 'The Rust Book' from the terminal

TheBook TheBook is a command line utility that allows you to SEARCH and READ The Rust Programming Language (popularly known as 'The Book' ) from the t

0xHiro 技術者 239 Jan 4, 2023