Struct SyntaxGenerator

Source
pub struct SyntaxGenerator;
Expand description

Utility for generating syntax-aware code using the quote crate

Implementations§

Source§

impl SyntaxGenerator

Source

pub fn new() -> Self

Creates a new SyntaxGenerator

Source

pub fn generate_trait_impl( &self, trait_name: &str, type_name: &str, methods: HashMap<String, String>, ) -> String

Generates a trait implementation for a type

§Parameters
  • trait_name - Name of the trait to implement
  • type_name - Name of the type to implement the trait for
  • methods - Map of method names to method bodies
§Returns

Generated trait implementation as a string

Source

pub fn generate_import(&self, path: &str, items: &[&str]) -> String

Generates an import statement

§Parameters
  • path - Path to import
  • items - Items to import from the path
§Returns

Generated import statement as a string

Source

pub fn generate_struct( &self, struct_name: &str, fields: HashMap<String, String>, derive_traits: Option<Vec<&str>>, ) -> String

Generates a struct definition

§Parameters
  • struct_name - Name of the struct
  • fields - Map of field names to field types
  • derive_traits - Optional list of traits to derive
§Returns

Generated struct definition as a string

Source

pub fn generate_enum( &self, enum_name: &str, variants: HashMap<String, Option<String>>, derive_traits: Option<Vec<&str>>, ) -> String

Generates an enum definition

§Parameters
  • enum_name - Name of the enum
  • variants - Map of variant names to optional variant types
  • derive_traits - Optional list of traits to derive
§Returns

Generated enum definition as a string

Source

pub fn generate_function( &self, fn_name: &str, params: HashMap<String, String>, return_type: Option<&str>, body: &str, ) -> String

Generates a function definition

§Parameters
  • fn_name - Name of the function
  • params - Map of parameter names to parameter types
  • return_type - Optional return type
  • body - Function body
§Returns

Generated function definition as a string

Source

pub fn generate_method_call( &self, object: &str, method_name: &str, args: &[&str], ) -> String

Generates a method call

§Parameters
  • object - Object to call the method on
  • method_name - Name of the method to call
  • args - Arguments to pass to the method
§Returns

Generated method call as a string

Trait Implementations§

Source§

impl Debug for SyntaxGenerator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SyntaxGenerator

Source§

fn default() -> SyntaxGenerator

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more