instruct-macros

Crates.ioinstruct-macros
lib.rsinstruct-macros
version0.1.8
sourcesrc
created_at2024-06-22 11:26:55.247576
updated_at2024-07-08 11:05:45.449215
descriptioninstruct-macros are a collection of simple macros that we're using in Instructor-AI to generate json schema from Serde Objects
homepage
repository
max_upload_size
id1280384
size31,109
Ivan Leo (ivanleomk)

documentation

README

Instruct Macros

Instruct Macros are a set of procedural macros that expose a get_info() method which is meant to help you get reflection in your objects by default, exposing field names+ types along with the object name.

You can use it by doing

use instruct_macros::InstructMacro; // Ensure this is a derive macro
use instruct_macros_types::{ParameterInfo, StructInfo}; // Import the trait

#[derive(InstructMacro, Deserialize, Serialize, Debug)]
/// This is a model which represents a single individual user
struct UserInfo {
    /// This is the name of the user
    #[serde(deserialize_with = "uppercase_name")]
    name: String,
    /// This is the age of the user
    age: u8,
    /// This is the city of the user
    city: String,
}

This in turn will expose a get_info() method on your struct that returns a body that looks omsething like this

Commit count: 0

cargo fmt