Struct subxt_codegen::TypeGenerator
source · pub struct TypeGenerator<'a> { /* private fields */ }Expand description
Generate a Rust module containing all types defined in the supplied PortableRegistry.
Implementations§
source§impl<'a> TypeGenerator<'a>
impl<'a> TypeGenerator<'a>
sourcepub fn new(
type_registry: &'a PortableRegistry,
root_mod: &'static str,
type_substitutes: TypeSubstitutes,
derives: DerivesRegistry,
crate_path: CratePath,
should_gen_docs: bool
) -> Self
pub fn new( type_registry: &'a PortableRegistry, root_mod: &'static str, type_substitutes: TypeSubstitutes, derives: DerivesRegistry, crate_path: CratePath, should_gen_docs: bool ) -> Self
Construct a new TypeGenerator.
sourcepub fn generate_types_mod(&self) -> Result<Module, CodegenError>
pub fn generate_types_mod(&self) -> Result<Module, CodegenError>
Generate a module containing all types defined in the supplied type registry.
sourcepub fn resolve_type(&self, id: u32) -> Type<PortableForm>
pub fn resolve_type(&self, id: u32) -> Type<PortableForm>
Panics
If no type with the given id found in the type registry.
sourcepub fn resolve_field_type_path(
&self,
id: u32,
parent_type_params: &[TypeParameter],
original_name: Option<&str>
) -> TypePath
pub fn resolve_field_type_path( &self, id: u32, parent_type_params: &[TypeParameter], original_name: Option<&str> ) -> TypePath
Get the type path for a field of a struct or an enum variant, providing any generic type parameters from the containing type. This is for identifying where a generic type parameter is used in a field type e.g.
struct S<T> {
a: T, // `T` is the "parent" type param from the containing type.
b: Vec<Option<T>>, // nested use of generic type param `T`.
}This allows generating the correct generic field type paths.
Panics
If no type with the given id found in the type registry.
sourcepub fn resolve_type_path(&self, id: u32) -> TypePath
pub fn resolve_type_path(&self, id: u32) -> TypePath
Get the type path for the given type identifier.
Panics
If no type with the given id found in the type registry.
sourcepub fn default_derives(&self) -> &Derives
pub fn default_derives(&self) -> &Derives
Returns the derives to be applied to all generated types.
sourcepub fn types(&self) -> &PortableRegistry
pub fn types(&self) -> &PortableRegistry
Returns the type registry.
sourcepub fn type_derives(
&self,
ty: &Type<PortableForm>
) -> Result<Derives, CodegenError>
pub fn type_derives( &self, ty: &Type<PortableForm> ) -> Result<Derives, CodegenError>
Returns the derives to be applied to a generated type.