ModularM
Modular3y ago
ct

How to add an instance of a struct to a DynamicVector

A total newbie question. Example:

struct Item:
var name: StringLiteral
fn init(inout self):
self.name = "Unnamed"

fn main():
var dv = DynamicVectorItem
var it = Item()
dv.push_back(it)

Generates error: invalid call to 'push_back': method argument #0 cannot bind generic !mlirtype to memory-only type 'Item'

I don't understand the error message.

I cannot find in https://docs.modular.com/mojo/programming-manual.html the syntax for this.

Is there an equivalent to c++ vector::emplace(...)?
Was this page helpful?