pub struct ItemType {
pub type_name: String,
pub description: Option<String>,
pub items: Option<Box<JsonItem>>,
}
Expand description
Represents a single property or item type within a JSON schema.
This structure defines the type and characteristics of individual properties in a JSON schema. It can represent simple types (string, number, boolean) or complex types (arrays, objects) with nested structures.
§Fields
type_name
- The JSON type of this item (e.g., “string”, “number”, “array”, “object”)description
- Optional human-readable description of the propertyitems
- For array types, defines the structure of array elements
§Supported Types
- “string”: Text values
- “number”: Numeric values (integers and floats)
- “boolean”: True/false values
- “array”: Lists of items with defined structure
- “object”: Complex nested objects
§Example
use openai_tools::json_schema::ItemType;
// Simple string property
let name_prop = ItemType::new(
"string".to_string(),
Some("The user's full name".to_string())
);
// Numeric property
let age_prop = ItemType::new(
"number".to_string(),
Some("Age in years".to_string())
);
Fields§
§type_name: String
§description: Option<String>
§items: Option<Box<JsonItem>>
Implementations§
Source§impl ItemType
impl ItemType
Sourcepub fn new(type_name: String, description: Option<String>) -> Self
pub fn new(type_name: String, description: Option<String>) -> Self
Creates a new ItemType
with the specified type and optional description.
§Arguments
type_name
- The JSON type name (e.g., “string”, “number”, “boolean”, “array”, “object”)description
- Optional description explaining the purpose of this property
§Returns
A new ItemType
instance with the specified type and description.
§Example
use openai_tools::json_schema::ItemType;
// Create a string property with description
let email = ItemType::new(
"string".to_string(),
Some("A valid email address".to_string())
);
// Create a number property without description
let count = ItemType::new("number".to_string(), None);
Sourcepub fn clone(&self) -> Self
pub fn clone(&self) -> Self
Creates a deep clone of this ItemType
instance.
This method performs a deep copy of all nested structures, including
any complex items
that may be present for array types.
§Returns
A new ItemType
instance that is an exact copy of this one.
§Note
This method is more explicit than the auto-derived Clone
trait
and ensures proper deep copying of nested Box