Crate pendzl_lang

Source
Expand description

§Pendzl functionality and utils

The library is organized into three main components

§1. Code Generation Module (codegen)

This module contains the implementations of macros used for code generation in the library.

  • Contains:

    • Implementation of the codegen::implementation macro:
      • Implements the implementation macro, which injects default fn implementations (& overrides) of standard traits.
    • Boilerplate code for implementations injecting:
      • Every implementation of a trait (PSP22, PSP34, PSP22Metadata etc) is injected with the default implementation of the trait.
    • Implementation of the codegen::storage_item macro:
      • Implements functionality for the storage_item macro, handling storage-related code generation.
    • Implementation of the codegen::storage_field_getter_derive macro:
      • Contains the implementation for deriving the StorageFieldGetter trait for storage structures.

See more about the code generation module here.

§2. Macro Definitions Module (macro)

This module defines the public macros that are exposed to end users.

  • Contains:
    • Definition of the implementation macro:
      • Utilizes codegen::implementation internally to provide default implementations of standard traits.
    • Definition of the storage_item macro:
      • Uses codegen::storage_item to handle storage-related macros.
    • Definition of the StorageFieldGetter derive macro:
      • Employs codegen::storage_field_getter_derive to automatically derive getter methods for storage fields.

§3. Source Module (src)

This module serves as the main entry point and provides utility functions and re-exports for end users.

  • Features:
    • Re-exports the macro module:
      • Makes the macros defined in the macro module available to users.
    • Contains mathematical utilities:
      • Provides utility functions for mathematical operations used in the library.
    • Includes various trait and type helpers:
      • Contains helper traits and types to assist both the library and end users in developing smart contracts.

Modules§

Macros§

  • Return the hash of the format!(“{}::{}”, ::core::module_path!(), struct_name). Also, if field naming is provided, it will return the hash of the format!(“{}::{}::{}”, ::core::module_path!(), struct_name, field_name). It cam be used to generate unique storage key of the struct.

Attribute Macros§

  • This macro implements the default traits defined in pendzl, while also allowing users to override them with #[overrider] attribute. #[overrider] is used when you want to change the behavior of the method by your implementation.
  • The macro implements ink::storage_item macro for the struct, which means that it prepares your struct to be a part of contract’s storage. Also, inside of struct marked by this macro you can use #[lazy] attribute to mark fields, that should be lazily loaded and wrapped in ::ink::storage::Lazy. The macro also generates constant storage keys for every mapping or lazy field and inserts them into type definition following recomendation from https://use.ink/datastructures/storage-layout