#macro #generate #instruct #object #schema #string #instruct-macro

macro instruct-macros

instruct-macros are a collection of simple macros that we're using in Instructor-AI to generate json schema from Serde Objects

5 releases

0.1.8 Jul 8, 2024
0.1.7 Jul 8, 2024
0.1.3 Jun 25, 2024
0.1.1 Jun 23, 2024
0.1.0 Jun 22, 2024

#1094 in Procedural macros

Download history 14/week @ 2024-07-23 6/week @ 2024-07-30 63/week @ 2024-08-27 8/week @ 2024-09-10 5/week @ 2024-09-17 9/week @ 2024-09-24 3/week @ 2024-10-01

219 downloads per month
Used in instructor-ai

MIT/Apache

16KB
306 lines

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

Dependencies

~0.7–1.6MB
~34K SLoC