pub struct StructGen { /* private fields */ }Expand description
Main builder for generating Rust structs
§Examples
ⓘ
use unistructgen_core::api::{StructGen, FieldType};
let code = StructGen::new()
.name("User")
.doc("Represents a user in the system")
.field("id", FieldType::I64)
.field("username", FieldType::String)
.field_optional("email", FieldType::String)
.field_with(|f| f
.doc("User's age")
.range(0.0, 150.0)
, "age", FieldType::I32)
.with_serde()
.with_debug()
.with_clone()
.generate()?;Implementations§
Source§impl StructGen
impl StructGen
Sourcepub fn field_optional(self, name: impl Into<String>, ty: FieldType) -> Self
pub fn field_optional(self, name: impl Into<String>, ty: FieldType) -> Self
Add an optional field
Sourcepub fn field_with<F>(
self,
builder_fn: F,
name: impl Into<String>,
ty: FieldType,
) -> Self
pub fn field_with<F>( self, builder_fn: F, name: impl Into<String>, ty: FieldType, ) -> Self
Add a field with full builder customization
Sourcepub fn with_serde(self) -> Self
pub fn with_serde(self) -> Self
Add serde derives (Serialize, Deserialize)
Sourcepub fn with_debug(self) -> Self
pub fn with_debug(self) -> Self
Add Debug derive
Sourcepub fn with_clone(self) -> Self
pub fn with_clone(self) -> Self
Add Clone derive
Sourcepub fn with_default(self) -> Self
pub fn with_default(self) -> Self
Add Default derive
Sourcepub fn with_partial_eq(self) -> Self
pub fn with_partial_eq(self) -> Self
Add PartialEq derive
Sourcepub fn with_common_derives(self) -> Self
pub fn with_common_derives(self) -> Self
Add all common derives (Debug, Clone, PartialEq, Eq, Hash, Default)
Sourcepub fn nested_struct(self, nested: StructGen) -> Self
pub fn nested_struct(self, nested: StructGen) -> Self
Add a nested struct type
Sourcepub fn nested_enum(self, nested: EnumGen) -> Self
pub fn nested_enum(self, nested: EnumGen) -> Self
Add a nested enum type
Sourcepub fn build_ir_struct(&self) -> IRStruct
pub fn build_ir_struct(&self) -> IRStruct
Build the IR struct (without generating code)
Sourcepub fn into_ir_struct(self) -> IRStruct
pub fn into_ir_struct(self) -> IRStruct
Consume and build the IR struct
Sourcepub fn build_ir_module(self) -> IRModule
pub fn build_ir_module(self) -> IRModule
Build the IR module containing this struct and nested types
Sourcepub fn generate_with_options(self, options: RenderOptions) -> ApiResult<String>
pub fn generate_with_options(self, options: RenderOptions) -> ApiResult<String>
Generate with custom render options
Trait Implementations§
Auto Trait Implementations§
impl Freeze for StructGen
impl RefUnwindSafe for StructGen
impl Send for StructGen
impl Sync for StructGen
impl Unpin for StructGen
impl UnsafeUnpin for StructGen
impl UnwindSafe for StructGen
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more