Class: Codify::Rust::StructField
- Inherits:
-
Object
- Object
- Codify::Rust::StructField
- Includes:
- Codify::Rust
- Defined in:
- lib/codify/rust/struct_field.rb
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#rename ⇒ Object
Returns the value of attribute rename.
-
#summary ⇒ Object
readonly
Returns the value of attribute summary.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #comment? ⇒ Boolean
- #defaultible? ⇒ Boolean
-
#initialize(name, type, &block) ⇒ StructField
constructor
A new instance of StructField.
- #types ⇒ Array<Type>
- #write(out) ⇒ void
Constructor Details
#initialize(name, type, &block) ⇒ StructField
Returns a new instance of StructField.
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
#comment ⇒ Object
Returns the value of attribute comment.
9 10 11 |
# File 'lib/codify/rust/struct_field.rb', line 9 def comment @comment end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/codify/rust/struct_field.rb', line 8 def name @name end |
#rename ⇒ Object
Returns the value of attribute rename.
9 10 11 |
# File 'lib/codify/rust/struct_field.rb', line 9 def rename @rename end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary.
8 9 10 |
# File 'lib/codify/rust/struct_field.rb', line 8 def summary @summary end |
#type ⇒ Object (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
26 27 28 |
# File 'lib/codify/rust/struct_field.rb', line 26 def comment? self.comment && !self.comment.empty? end |
#defaultible? ⇒ Boolean
20 21 22 |
# File 'lib/codify/rust/struct_field.rb', line 20 def defaultible? @type.defaultible? end |
#types ⇒ Array<Type>
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.
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 |