Skip to content

Commit

Permalink
docs: add docs for starknet-macros (#642)
Browse files Browse the repository at this point in the history
  • Loading branch information
xJonathanLEI authored Jul 29, 2024
1 parent 7d8395f commit d0d42d4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
//!
//! Contains procedural macros useful for this crate.
#![deny(missing_docs)]

#[doc = include_str!("../assets/CORE_README.md")]
pub mod core {
pub use starknet_core::*;
Expand Down
13 changes: 12 additions & 1 deletion starknet-macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
//! Procedural macros for the `starknet` crate. This crate provides macros that help make defining
//! certain compile-time constants easier.
#![deny(missing_docs)]

use proc_macro::TokenStream;
use starknet_core::{
types::Felt,
utils::{cairo_short_string_to_felt, get_selector_from_name},
};
use syn::{parse_macro_input, LitStr};

/// Defines a compile-time constant for a entrypoint selector of a Starknet contract.
#[proc_macro]
pub fn selector(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as LitStr);
Expand All @@ -26,6 +32,7 @@ pub fn selector(input: TokenStream) -> TokenStream {
.unwrap()
}

/// Defines a compile-time constant for a Cairo short string encoding from a human-readable string.
#[proc_macro]
pub fn short_string(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as LitStr);
Expand All @@ -47,6 +54,8 @@ pub fn short_string(input: TokenStream) -> TokenStream {
.unwrap()
}

/// Defines a compile-time constant for a field element from its decimal or hexadecimal
/// representation.
#[proc_macro]
pub fn felt(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as LitStr);
Expand All @@ -73,6 +82,7 @@ pub fn felt(input: TokenStream) -> TokenStream {
.unwrap()
}

/// Defines a compile-time constant for a field element from its decimal representation.
#[proc_macro]
pub fn felt_dec(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as LitStr);
Expand All @@ -94,6 +104,7 @@ pub fn felt_dec(input: TokenStream) -> TokenStream {
.unwrap()
}

/// Defines a compile-time constant for a field element from its hexadecimal representation.
#[proc_macro]
pub fn felt_hex(input: TokenStream) -> TokenStream {
let input = parse_macro_input!(input as LitStr);
Expand All @@ -116,7 +127,7 @@ pub fn felt_hex(input: TokenStream) -> TokenStream {
}

#[cfg(feature = "use_imported_type")]
fn field_element_path() -> &'static str {
const fn field_element_path() -> &'static str {
"Felt"
}

Expand Down

0 comments on commit d0d42d4

Please sign in to comment.