Adjusted project data.

Properly pointed to the repository location.

Changed the rust edition.
This commit is contained in:
2025-07-29 17:54:46 -04:00
parent 4357a3aff3
commit a370d13f7a
9 changed files with 114 additions and 196 deletions

79
.rustfmt.toml Normal file
View File

@ -0,0 +1,79 @@
max_width = 80
hard_tabs = false
tab_spaces = 3
newline_style = "Unix"
indent_style = "Visual"
use_small_heuristics = "Default"
fn_call_width = 60
attr_fn_like_width = 70
struct_lit_width = 18
struct_variant_width = 35
array_width = 60
chain_width = 60
single_line_if_else_max_width = 50
single_line_let_else_max_width = 50
wrap_comments = true
format_code_in_doc_comments = true
doc_comment_code_block_width = 80
comment_width = 80
normalize_comments = true
normalize_doc_attributes = true
format_strings = true
format_macro_matchers = true
format_macro_bodies = true
skip_macro_invocations = []
hex_literal_case = "Preserve"
empty_item_single_line = true
struct_lit_single_line = true
fn_single_line = false
where_single_line = true
imports_indent = "Visual"
imports_layout = "Horizontal"
imports_granularity = "Module"
group_imports = "StdExternalCrate"
reorder_imports = true
reorder_modules = true
reorder_impl_items = true
type_punctuation_density = "Wide"
space_before_colon = false
space_after_colon = true
spaces_around_ranges = false
binop_separator = "Back"
remove_nested_parens = true
combine_control_expr = false
short_array_element_width_threshold = 10
overflow_delimited_expr = false
struct_field_align_threshold = 0
enum_discrim_align_threshold = 0
match_arm_blocks = true
match_arm_leading_pipes = "Never"
force_multiline_blocks = true
fn_params_layout = "Compressed"
brace_style = "AlwaysNextLine"
control_brace_style = "AlwaysNextLine"
trailing_semicolon = true
trailing_comma = "Never"
match_block_trailing_comma = false
blank_lines_upper_bound = 3
blank_lines_lower_bound = 0
edition = "2021"
style_edition = "2021"
inline_attribute_width = 0
format_generated_files = true
generated_marker_line_search_limit = 5
merge_derives = true
use_try_shorthand = false
use_field_init_shorthand = false
force_explicit_abi = true
condense_wildcard_suffixes = false
color = "Always"
required_version = "1.8.0"
unstable_features = true
disable_all_formatting = false
skip_children = false
show_parse_errors = true
error_on_line_overflow = false
error_on_unformatted = false
ignore = []
emit_mode = "Files"
make_backup = false

View File

@ -1,10 +1,10 @@
[package]
name = "binding"
version = "0.1.0"
version = "0.2.0"
description = "Defines macros and functions used when binding to C libraries."
repository = "https://workshop.cybermages.tech/CyberMages/binding.git"
repository = "https://workshop.cybermages.tech/CyberMages/binding"
keywords = ["binding", "c types", "c enums", "c flags", "c strings"]
edition = "2021"
edition = "2024"
documentation = ""
authors = ["CyberMages LLC <Software@CyberMagesLLC.com>", "Jason Travis Smith <Myrddin@CyberMages.tech>"]
readme = "README.md"

View File

@ -3,10 +3,7 @@
use binding::c_enum;
c_enum!
{
c_enum! {
/// Test enum is a simple enum testing the
/// capabilities of creating a C enum.
enum TestEnum: i32
@ -22,8 +19,6 @@ c_enum!
}
}
pub fn main()
{
let cenum: TestEnum;

View File

@ -3,10 +3,7 @@
use binding::c_flags;
c_flags!
{
c_flags! {
/// A sample of flags useful for the EvDev library.
flags ReadFlags: u32
{
@ -25,7 +22,6 @@ c_flags!
}
}
pub fn main()
{
let flag: ReadFlags;

View File

@ -3,9 +3,9 @@
/// A C Pointer to an undefined structure.
///
/// A lot of C libraries return a pointer to an undefined structure.
/// This is easily wrapped as an empty enum. This keeps users from being
/// able to create an instance of the value.
/// Many C libraries return pointers to opaque or incomplete types.
/// This macro declares an equivalent Rust type that cannot be
/// instantiated directly but can safely be used as a pointer target.
#[macro_export]
macro_rules! c_ptr
{
@ -13,6 +13,13 @@ macro_rules! c_ptr
$name: ident
} =>
{
pub enum $name {}
#[repr(C)]
pub struct $name { _private: __opaque::Private }
};
}
mod __opaque
{
#[allow(dead_code)]
pub enum Private {}
}

View File

@ -3,54 +3,10 @@
//! This defines the primitive types that may be seen
//! when creating 'C' bindings.
//!
//! There are several places where the target architecture and the OS
//! require special consideration. These are handled
//! with configuration statements.
// Character types.
#[cfg(any(target_os="android", target_os="emscripten",
all(target_os="linux",
any(target_arch="aarch64", target_arch="arm",
target_arch="powerpc", target_arch="powerpc64"))))]
pub type CChar = u8;
#[cfg(not(any(target_os="android", target_os="emscripten",
all(target_os="linux",
any(target_arch="aarch64", target_arch="arm",
target_arch="powerpc", target_arch="powerpc64")))))]
pub type CChar = i8;
pub type CUChar = u8;
// Integer types.
#[cfg(any(target_pointer_width="32", target_os="windows"))]
pub type CLong = i32;
#[cfg(any(target_pointer_width="32", target_os="windows"))]
pub type CULong = u32;
#[cfg(all(target_pointer_width="64", not(target_os="windows")))]
pub type CLong = i32;
#[cfg(all(target_pointer_width="64", not(target_os="windows")))]
pub type CULong = u32;
pub type CShort = i16;
pub type CUShort = u16;
pub type CInt = i32;
pub type CUInt = u32;
pub type CLongLong = i64;
pub type CULongLong = u64;
pub type CFloat = f32;
pub type CDouble = f64;
/// CVoid acts as a 'C' void pointer to pass to functions. **DO NOT**
/// use this as a return type from a 'C' function. If a 'C' function
/// returns void, then use the CReturnVoid type for that.
pub use std::ffi::{c_char as CChar, c_double as CDouble, c_float as CFloat, c_int as CInt, c_long as CLong, c_longlong as CLongLong, c_short as CShort, c_uchar as CUChar, c_uint as CUInt, c_ulong as CULong, c_ulonglong as CULongLong, c_ushort as CUShort, c_void as CVoid, CStr};
// Void types.
/// To return void from a 'C' function it should return an empty tuple ().
@ -58,38 +14,5 @@ pub type CDouble = f64;
/// as an argument to a function. Use the CVoid type for that.
pub type CReturnVoid = ();
/// This acts as a 'C' void pointer to pass to functions. **DO NOT**
/// use this as a return type from a 'C' function. If a 'C' function
/// returns void, then use the CReturnVoid type for that.
#[repr(u8)]
pub enum CVoid
{
#[doc(hidden)]
_Variant,
#[doc(hidden)]
_Variant2
}
// String types.
/*
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone)]
pub struct CString
{
chars: Box<[u8]>
}
#[derive(Hash)]
pub struct CStr
{
inner: [CChar]
}
*/
#[cfg(feature="use_std")]
pub type CStr = ::std::ffi::CStr;
#[cfg(feature = "use_std")]
pub type CString = ::std::ffi::CString;
#[cfg(feature="use_std")]
pub type NullByteError = ::std::ffi::NulError;

View File

@ -17,11 +17,6 @@
#[cfg(not(feature = "use_std"))]
extern crate core as std;
// Macros to help create bindings to FFI libraries.
mod macros;
// Basic C type macro modules.
mod c_enum;
mod c_flags;
@ -32,13 +27,7 @@ mod c_types;
// Raw platform data retrieval.
mod raw;
#[cfg(feature = "use_std")]
pub use self::c_types::{CStr, CString, NullByteError};
pub use self::c_types::{CChar, CUChar};
pub use self::c_types::{CShort, CUShort, CInt, CUInt, CLong, CULong};
pub use self::c_types::{CLongLong, CULongLong, CFloat, CDouble};
pub use self::c_types::{CVoid, CReturnVoid};
pub use self::raw::{AsRaw, AsRawMut, AsRawPtr, AsRawMutPtr, FromRaw, IntoRaw};
pub use self::c_types::{from_c_string, to_c_string, CString, NullByteError};
pub use self::c_types::{CChar, CDouble, CFloat, CInt, CLong, CLongLong, CReturnVoid, CShort, CStr, CUChar, CUInt, CULong, CULongLong, CUShort, CVoid};
pub use self::raw::{AsRaw, AsRawMut, AsRawMutPtr, AsRawPtr, FromRaw, IntoRaw};

View File

@ -1,74 +0,0 @@
// SPDX-License-Identifier: Apache-2.0
// Sealed with Magistamp.
#[macro_export]
macro_rules! c_library
{
{
$(statics:
{
$($(#[$satter: meta])* $sname: ident: $stype: ty);+;
}
)?
$(functions:
{
$($(#[$fatter: meta])* $fname: ident($($farg: ident: $fargt: ty),*) -> $fret:ty);+;
}
)?
$(varargs:
{
$($(#[$vatter: meta])* $vname: ident($($vargs: ident: $vargst: ty),+) -> $vret:ty);+;
}
)?
} =>
{
extern "C"
{
$($($(#[$satter])* pub static $sname: $stype;)+)?
$($($(#[$fatter])* pub fn $fname($($farg: $fargt),*) -> $fret;)+)?
$($($(#[$vatter])* pub fn $vname($(vargs: $vargst),+ , ...) -> $vret;)+)?
}
};
}
#[macro_export]
macro_rules! external_library
{
{
$name: ident: $link: expr =>
{
$(statics:
{
$($(#[$satter: meta])* $sname: ident: $stype: ty);+;
}
)?
$(functions:
{
$($(#[$fatter: meta])* $fname: ident($($farg: ident: $fargt: ty),*) -> $fret:ty);+;
}
)?
$(varargs:
{
$($(#[$vatter: meta])* $vname: ident($($vargs: ident: $vargst: ty),+) -> $vret:ty);+;
}
)?
}
} =>
{
#[link(name=$link)]
extern "C"
{
$($($(#[$satter])* pub static $sname: $stype;)+)?
$($($(#[$fatter])* pub fn $fname($($farg: $fargt),*) -> $fret;)+)?
$($($(#[$vatter])* pub fn $vname($(vargs: $vargst),+ , ...) -> $vret;)+)?
}
};
}

View File

@ -9,11 +9,11 @@
//! to help with understanding the code and to remind the programmer
//! where values are coming from.
/// Some times there are types that need to return a platform specific
/// data type that can be used by the platform specific functions. This
/// type creates a path to easily get that data.
pub trait AsRaw<T> where T: Sized
pub trait AsRaw<T>
where T: Sized
{
fn as_raw(&self) -> &T;
}
@ -21,7 +21,8 @@ pub trait AsRaw<T> where T: Sized
/// Some times there are types that need to return a platform specific
/// data type that can be used by the platform specific functions. This
/// type creates a path to easily get that data in a mutable manner.
pub trait AsRawMut<T> where T: Sized
pub trait AsRawMut<T>
where T: Sized
{
fn as_raw_mut(&mut self) -> &mut T;
}
@ -29,7 +30,8 @@ pub trait AsRawMut<T> where T: Sized
/// Some times there are types that need to return a platform specific
/// data type that can be used by the platform specific functions. This
/// type creates a path to easily get that data as a raw const pointer.
pub trait AsRawPtr<T> where T: Sized
pub trait AsRawPtr<T>
where T: Sized
{
fn as_raw_ptr(&self) -> *const T;
}
@ -37,7 +39,8 @@ pub trait AsRawPtr<T> where T: Sized
/// Some times there are types that need to return a platform specific
/// data type that can be used by the platform specific functions. This
/// type creates a path to easily get that data as a raw mutable pointer.
pub trait AsRawMutPtr<T> where T: Sized
pub trait AsRawMutPtr<T>
where T: Sized
{
fn as_raw_mut_ptr(&mut self) -> *mut T;
}