Class: Codify::Rust::StructField

Inherits:
Object
  • Object
show all
Includes:
Codify::Rust
Defined in:
lib/codify/rust/struct_field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, &block) ⇒ StructField

Returns a new instance of StructField.

Raises:

  • (ArgumentError)


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

def initialize(name, type, &block)
  @name = name.to_s.gsub('[]', '').gsub('.', '_')
  @type = type
  raise ArgumentError, "#{type.inspect}" unless type.is_a?(Type)
  block.call(self) if block_given?
end

Instance Attribute Details

#commentObject

Returns the value of attribute comment.



9
10
11
# File 'lib/codify/rust/struct_field.rb', line 9

def comment
  @comment
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/codify/rust/struct_field.rb', line 8

def name
  @name
end

#renameObject

Returns the value of attribute rename.



9
10
11
# File 'lib/codify/rust/struct_field.rb', line 9

def rename
  @rename
end

#summaryObject (readonly)

Returns the value of attribute summary.



8
9
10
# File 'lib/codify/rust/struct_field.rb', line 8

def summary
  @summary
end

#typeObject (readonly)

Returns the value of attribute type.



8
9
10
# File 'lib/codify/rust/struct_field.rb', line 8

def type
  @type
end

Instance Method Details

#comment?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/codify/rust/struct_field.rb', line 26

def comment?
  self.comment && !self.comment.empty?
end

#defaultible?Boolean

Returns:

  • (Boolean)


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

def defaultible?
  @type.defaultible?
end

#typesArray<Type>

Returns:



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

def types
  [@type]
end

#write(out) ⇒ void

This method returns an undefined value.

Parameters:

  • out (IO)


39
40
41
42
# File 'lib/codify/rust/struct_field.rb', line 39

def write(out)
  out.puts "    #[cfg_attr(feature = \"serde\", serde(rename = \"#{self.rename}\"))]" if self.rename
  out.puts "    pub r##{@name}: #{@type},"
end