Class: Codify::Rust::Newtype

Inherits:
Definition show all
Defined in:
lib/codify/rust/newtype.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) ⇒ Newtype

Returns a new instance of Newtype.

Parameters:

  • name (String, #to_s)
  • type (Type)
  • derives (Array<Symbol, #to_sym>, #to_a)
  • comment (String, #to_s)
  • block (Proc)

Raises:

  • (ArgumentError)


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

def initialize(name, type, **kwargs, &block)
  super(name, **kwargs)
  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)


21
22
23
# File 'lib/codify/rust/newtype.rb', line 21

def defaultible?
  @type.defaultible?
end

#typesArray<Type>

Returns:



27
# File 'lib/codify/rust/newtype.rb', line 27

def types() [@type] end

#write(out) ⇒ void

This method returns an undefined value.

Parameters:

  • out (IO)


32
33
34
35
# File 'lib/codify/rust/newtype.rb', line 32

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