Class: Codify::Rust::Newtype
- Inherits:
-
Definition
- Object
- Definition
- Codify::Rust::Newtype
- Defined in:
- lib/codify/rust/newtype.rb
Instance Attribute Summary
Attributes inherited from Definition
#cfg_derives, #comment, #derives, #name
Instance Method Summary collapse
- #defaultible? ⇒ Boolean
-
#initialize(name, type, **kwargs, &block) ⇒ Newtype
constructor
A new instance of Newtype.
- #types ⇒ Array<Type>
- #write(out) ⇒ void
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.
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
21 22 23 |
# File 'lib/codify/rust/newtype.rb', line 21 def defaultible? @type.defaultible? end |
#write(out) ⇒ void
This method returns an undefined value.
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 |