Does Rust have syntax for initializing a struct field with an earlier field? -
example code, not compile:
pub struct s { pub a: int, pub b: int } impl s { pub fn new(input: int) -> s { s { a: input + 1, b: } } }
the b: a
bit isn't valid syntax, there way in current rust? [rustc 0.13.0-nightly (eedfc0779 2014-11-25 22:36:59 +0000)]
obviously repeat input + 1
or use temporary variable, i'm curious using already-initialized field input field.
no, there not that, nor reasonable expect there ever be; rust’s ownership semantics make of little value apply well, references too.copy
types
the alternatives simple complicating language such feature pretty guaranteed not happen.
Comments
Post a Comment