Class: Codify::Rust::EnumVariant
- Inherits:
-
Object
- Object
- Codify::Rust::EnumVariant
- Includes:
- Codify::Rust
- Defined in:
- lib/codify/rust/enum_variant.rb
Instance Attribute Summary collapse
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#default ⇒ Object
readonly
Returns the value of attribute default.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#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 = nil, default: nil, serde: nil, &block) ⇒ EnumVariant
constructor
A new instance of EnumVariant.
- #types ⇒ Array<Type>
- #write(out) ⇒ void
Constructor Details
#initialize(name, type = nil, default: nil, serde: nil, &block) ⇒ EnumVariant
Returns a new instance of EnumVariant.
11 12 13 14 15 16 17 18 |
# File 'lib/codify/rust/enum_variant.rb', line 11 def initialize(name, type = nil, default: nil, serde: nil, &block) @name = name.to_sym @type = type raise ArgumentError, "#{type.inspect}" unless type.nil? || type.is_a?(Type) @default = default @serde = serde || {} # :untagged, :other, :rename 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/enum_variant.rb', line 9 def comment @comment end |
#default ⇒ Object (readonly)
Returns the value of attribute default.
8 9 10 |
# File 'lib/codify/rust/enum_variant.rb', line 8 def default @default end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/codify/rust/enum_variant.rb', line 8 def name @name end |
#summary ⇒ Object (readonly)
Returns the value of attribute summary.
8 9 10 |
# File 'lib/codify/rust/enum_variant.rb', line 8 def summary @summary end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
8 9 10 |
# File 'lib/codify/rust/enum_variant.rb', line 8 def type @type end |
Instance Method Details
#comment? ⇒ Boolean
28 29 30 |
# File 'lib/codify/rust/enum_variant.rb', line 28 def comment? self.comment && !self.comment.empty? end |
#defaultible? ⇒ Boolean
22 23 24 |
# File 'lib/codify/rust/enum_variant.rb', line 22 def defaultible? self.default end |
#types ⇒ Array<Type>
34 |
# File 'lib/codify/rust/enum_variant.rb', line 34 def types() [@type].compact end |
#write(out) ⇒ void
This method returns an undefined value.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/codify/rust/enum_variant.rb', line 39 def write(out) out.puts " #[default]" if @default if @serde serde = [] serde << 'untagged' if @serde[:untagged] serde << 'other' if @serde[:other] serde << 'rename = "' + @serde[:rename].to_s + '"' if @serde[:rename] out.puts " #[cfg_attr(feature = \"serde\", serde(#{serde.join(', ')}))]" unless serde.empty? end if !@type out.puts " #{@name}," else out.puts " #{@name}(#{@type})," end end |