beaumont-macros 0.1.2

Algorithmic trading for quantitative financial applications
Documentation
#![deny(missing_docs)]
//!
//! A collection of procedural macros for the beaumont crates.
//!
//! <div class="warning">This crate is in an early stage of development and
//! <strong>not</strong> production ready yet.<br>Use with caution!</div>
//!

use proc_macro::TokenStream;
use syn::parse_macro_input;

// The inner implementation of the literal macro
mod decimals;

/// Allow custom literals of `Decimal` numbers
///
/// Useful for creating decimal numbers the way you would normally create integer or floating
/// numbers, but appending the custom `d` suffix to the literal (instead of the `i32` or `f32`
/// usual suffixes). Also, useful for creating decimal numbers from string literals, still by appending the
/// custom `d` suffix instead of explicitly invoking a parser.
///
/// # Examples
/// ```ignore
/// use beaumont_numbers::Decimal;
/// use beaumont_macros::decimals;
///
/// #[allow_decimals]
/// fn do_something() {
///     // Create a decimal number from integer literals
///     let d1 = 12d;
///
///     // Create a decimal number from float literals
///     let d2 = 12.00d;
///     let d3 = -56712.3489d;
///
///     // Create a decimal number from string literals
///     let d4 = "190928.05"d;
/// }
/// ```
///
/// # Unhygienic
/// This macro is unhygienic, as it depends on the presence of the `Decimal` local name, referring
/// to any type for which an implementation of the `std::str::FromStr` trait exists.
/// While you can bring any `Decimal` you like, you're recommended to bring it as follows:
///
/// 1. either by using `beaumont_number::Decimal`,
/// 2. or by using `beaumont::Decimal` (which is a re-export of the same).
///
#[proc_macro_attribute]
pub fn allow_decimals(_attr: TokenStream, item: TokenStream) -> TokenStream {
    decimals::transform(parse_macro_input!(item)).into()
}


mod vector;

/// Create mathematical `Vector` from fixed-size array
///
/// # Unhygienic
/// This macro is unhygienic, as it depends on the presence of the `Vector` local name, referring
/// to any type for which an implementation of `core::convert::From<Box[A]>` trait exists.
/// While you can bring any `Vector` you wish, you're recommended to bring it as follows:
///
/// 1. either by using `beaumont_liner_algebra::Vector`,
/// 2. or by using `beaumont::Vector` (which is a re-export of the same).
///
/// Moreover, this macro can transform decimal literals (those ending with the `d` prefix)
/// without the need to annotate your functions with the `allow_decimals` macro.
///
/// # Examples
/// ```ignore
/// use beaumont_macros::vector;
/// use beaumont_numbers::Decimal;
/// use beaumont_linear_algebra::Vector;
///
/// let v: Vector<Decimal> = vector![1.0d, 2.0d, 3.0d];
/// assert_eq!(v.len(), 3);
/// ```
#[proc_macro]
pub fn vector(item: TokenStream) -> TokenStream {
    vector::transform(parse_macro_input!(item)).into()
}