3 ms·
Surely Rust can infer the type in your example? It just doesn't provide Zig's syntax to use the inferred type to manually initialize. If you wrote some_fn() her
by tialaramex 1y ago
Surely Rust can infer the type in your example? It just doesn't provide Zig's syntax to use the inferred type to manually initialize. If you wrote some_fn() here where some_fn's return type was genericised, Rust would ask for the appropriately typed some_fn not say it doesn't know the type.
- flohofwoe 1y ago> Surely Rust can infer the type in your example? Well in Rust code like this: pass_action.colors[0] = sg::ColorAttachmentAction { load_action: sg::LoadAction::Clear, clear_value: sg::Color { r: 0.25, g: 0.5, b: 0.75, a: 1.0 }, ..Default::default() }; ...I cannot write: pass_action.colors[0] = { load_action: sg::LoadAction::Clear, clear_value: { r: 0.25, g: 0.5, b: 0.75, a: 1.0 }, ..Default::default() }; ...even though the Rust compiler has all the type information it needs (from the 'left-hand-side'). For comparison, in Zig it would look like this: pass_action.colors[0] = .{ .load_action = .Clear, .clear_value = .{ .r=0.25, .g=0.5, .b=0.75, .a=1.0 }, }; ...Zig is still only halfway there compared to C99 (e.g. Zig doesn't allow designator chaining and is much less flexible for initializing nested arrays - in those areas it's closer to Rust than C).
- tialaramex 1y agoRight but your call to Default::default() gives the game away that we do have inference. Default::default() is generic, if we didn't have inference we'd need to tell it which of the enormous number of implementations of that trait it should call. Would you take syntax like clear_value: _ { r: 0.25, g: 0.5, g: 0.75, a: 1.0 } ?? Then we're saying that we know we need to pick a type here but the type can be inferred where our underscore was, just like when we let words: Vec<_> = "A sentence broken by spaces".split_whitespace().collect();