Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add docs for starknet-macros #642

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading