trixy 0.4.0

A rust crate used to generate multi-language apis for your application
Documentation
/*
* Copyright (C) 2023 - 2024:
* The Trinitrix Project <soispha@vhack.eu, antifallobst@systemausfall.org>
* SPDX-License-Identifier: GPL-3.0-or-later
*
* This file is part of the Trixy crate for Trinitrix.
*
* Trixy is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* and the GNU General Public License along with this program.
* If not, see <https://www.gnu.org/licenses/>.
*/

//! Trixy contains the types used by the [`trixy-macros`] crate to provide ffi safe types
pub mod error;
pub mod newtypes;
pub mod traits;
pub mod types_list;

pub use types_list::*;

macro_rules! header {
    ($path:expr) => {
        ($path, include_str!(concat!("./c_headers/", $path)))
    };
}

/// These are the "primitive" types used in Trixy, you can use any of them to create new structures
/// The str is the name, the index represents the expected generic arguments
///
// NOTE: Every type here must have the [`Convertible`] implemented on it (@soispha)
// And be added to the `convert/c/auxiliary/idendentifier/mod.rs` file
// And add it to the types list (`./types_list.rs`)
pub const BASE_TYPES: [(&'static std::primitive::str, usize); 15] = [
    // Unsigned
    ("u8", 0),
    ("u16", 0),
    ("u32", 0),
    ("u64", 0),
    // Signed
    ("i8", 0),
    ("i16", 0),
    ("i32", 0),
    ("i64", 0),
    // Float
    ("f32", 0),
    ("f64", 0),
    // Other
    ("void", 0),
    ("String", 0),
    ("Result", 2),
    ("Option", 1),
    ("Vec", 1),
];

/// The first value is the file name, the second it's contents
pub const C_TYPE_HEADER: [(&'static std::primitive::str, &'static std::primitive::str); 6] = [
    header!("common.h"),
    header!("errno.h"),
    header!("string.h"),
    header!("vec.h"),
    header!("result.h"),
    header!("option.h"),
];

pub fn header_names() -> std::string::String {
    C_TYPE_HEADER
        .iter()
        .map(|(name, _)| name)
        // .chain(iter::once(&"generated.h"))
        .fold(std::string::String::new(), |acc, name| {
            format!("{}#include \"{}\"\n", acc, name)
        })
}