Class: Codify::Rust::TypeAlias

Inherits:
Definition show all
Defined in:
lib/codify/rust/type_alias.rb

Instance Attribute Summary

Attributes inherited from Definition

#cfg_derives, #comment, #derives, #name

Instance Method Summary collapse

Methods inherited from Definition

#comment?, #primitive?, #to_rust_code, #to_s

Methods included from Type

#definition?, #each_subtype, #primitive?, #to_rust

Constructor Details

#initialize(name, type, **kwargs, &block) ⇒ TypeAlias

Returns a new instance of TypeAlias.

Parameters:

  • name (String, #to_s)
  • type (Type)
  • comment (String, #to_s)
  • block (Proc)

Raises:

  • (ArgumentError)


11
12
13
14
15
16
# File 'lib/codify/rust/type_alias.rb', line 11

def initialize(name, type, **kwargs, &block)
  super(name, **kwargs, derives: [], cfg_derives: [])
  raise ArgumentError, "#{type.inspect}" unless type.is_a?(Type)
  @type = type
  block.call(self) if block_given?
end

Instance Method Details

#defaultible?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/codify/rust/type_alias.rb', line 20

def defaultible?
  @type.defaultible?
end

#typesArray<Type>

Returns:



26
# File 'lib/codify/rust/type_alias.rb', line 26

def types() [@type] end

#write(out) ⇒ void

This method returns an undefined value.

Parameters:

  • out (IO)


31
32
33
34
# File 'lib/codify/rust/type_alias.rb', line 31

def write(out)
  super(out)
  out.puts "pub type #{@name} = #{@type};"
end