Initialization without Default trait requirements
hornyjailfish opened this issue · 3 comments
I cant initialize grid with defined size because struct i use not impl Default
I dont understand bound to Default trait because its possible to create vec and even Vec<Vec> with Vec::with_capacity() function
@hornyjailfish could you explain a bit what you try to achive? new
does depend on the 'Default' trait right now because it will init a 2d grid with the default values of the given type. What would be your expectation on calling new(1,1)
on a grid type without a Default trait bound?
Or in general, what can be achived with Vec<Vec<>> that can't be done with grid
?
want to create 2d grid for game with bevy like struct Field { ids: Grid<(Entity, Status)> }
because Entity
from the crate i cant impl Default
for it but i want to init grid beforehand.
I resolved it with dumb value and fill()
and its ok for my case but could be hard for complex structs without Default
I could imagine that something like grid_with_capacity
would help in such case? It does not exist yet. Changing new
is not that easy, because it initializes a grid with concrete values and without having a default for the given type it is not defined how those values will look like. So I don't really see a better approach here right now