Struct kotlin_poet_rs::spec::Class
source · pub struct Class { /* private fields */ }
Expand description
Defines Kotlin’s class like entity. This could represent any ‘flavour’ of class: enum, interface, e.t.c. To change type of class please use Class::inheritance_modifier.
#Example
§Simple class
use kotlin_poet_rs::io::RenderKotlin;
use kotlin_poet_rs::spec::{Class, Name};
let class = Class::new(Name::from("Person"));
assert_eq!(class.render_string(), "public final class Person {\n\n}");
§Interface
use kotlin_poet_rs::io::RenderKotlin;
use kotlin_poet_rs::spec::{Class, ClassInheritanceModifier, Name};
let class = Class::new(Name::from("Person"))
.inheritance_modifier(ClassInheritanceModifier::Interface);
assert_eq!(class.render_string(), "public interface Person {\n\n}");
Implementations§
source§impl Class
impl Class
sourcepub fn visibility_modifier(
self,
visibility_modifier: VisibilityModifier,
) -> Self
pub fn visibility_modifier( self, visibility_modifier: VisibilityModifier, ) -> Self
Set’s class visibility modifier
sourcepub fn inheritance_modifier(
self,
inheritance_modifier: ClassInheritanceModifier,
) -> Self
pub fn inheritance_modifier( self, inheritance_modifier: ClassInheritanceModifier, ) -> Self
Changes class type
sourcepub fn property(self, property: Property) -> Self
pub fn property(self, property: Property) -> Self
Adds property to this class. Properties in body will appear in order this method is called.
sourcepub fn function(self, function: Function) -> Self
pub fn function(self, function: Function) -> Self
Adds function to this class. Functions in body will appear in order this method is called.
sourcepub fn subclass(self, subclass: Class) -> Self
pub fn subclass(self, subclass: Class) -> Self
Adds subclass to this class. Subclasses in body will appear in order this method is called.
sourcepub fn enum_instance<NameLike: Into<Name>>(
self,
name: NameLike,
arguments: Vec<Argument>,
) -> Self
pub fn enum_instance<NameLike: Into<Name>>( self, name: NameLike, arguments: Vec<Argument>, ) -> Self
Adds enum instance to this class. Enum instances in body will appear in order this method is called. This method is only valid for enum classes. To change class type to enum please use Class::inheritance_modifier.
sourcepub fn primary_constructor(
self,
primary_constructor: PrimaryConstructor,
) -> Self
pub fn primary_constructor( self, primary_constructor: PrimaryConstructor, ) -> Self
Adds primary constructor to this class.
sourcepub fn secondary_constructor(
self,
secondary_constructor: SecondaryConstructor,
) -> Self
pub fn secondary_constructor( self, secondary_constructor: SecondaryConstructor, ) -> Self
Adds secondary constructor to this class. Secondary constructors in body will appear in order this method is called.
sourcepub fn init<CodeBlockLike: Into<CodeBlock>>(self, block: CodeBlockLike) -> Self
pub fn init<CodeBlockLike: Into<CodeBlock>>(self, block: CodeBlockLike) -> Self
Adds init block to this class. Init blocks in body will appear in order this method is called.
sourcepub fn companion_object(self, companion_object: CompanionObject) -> Self
pub fn companion_object(self, companion_object: CompanionObject) -> Self
Adds companion object to this class.
sourcepub fn generic_parameter(self, generic_parameter: GenericParameter) -> Self
pub fn generic_parameter(self, generic_parameter: GenericParameter) -> Self
Adds GenericParameter to this class. Could be called multiple times to have multiple generic parameters.
sourcepub fn inherits<TypeLike: Into<Type>>(self, parent_type: TypeLike) -> Self
pub fn inherits<TypeLike: Into<Type>>(self, parent_type: TypeLike) -> Self
Adds parent class / interface to this class.
sourcepub fn annotation(self, annotation: Annotation) -> Self
pub fn annotation(self, annotation: Annotation) -> Self
Adds Annotation to this entity. They will appear in order this method is called.
Trait Implementations§
source§impl RenderKotlin for Class
impl RenderKotlin for Class
source§fn render_string(&self) -> String
fn render_string(&self) -> String
Auto Trait Implementations§
impl Freeze for Class
impl RefUnwindSafe for Class
impl Send for Class
impl Sync for Class
impl Unpin for Class
impl UnwindSafe for Class
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)