我在Win8-64上使用0.8学习Rust.我有一个测试程序,我正在处理一个处理参数输入的函数返回一个包含这些参数的结构.这很好用.然后我改变了程序以将&struct传递给函数,现在我得到一个编译器错误,我试图分配给一个不可变字段.
我应该如何传递对结构的指针/引用以防止此错误?
导致错误的代码(我尝试了一些变化):
let mut ocParams : cParams = cParams::new(); //!!!!!! This is the struct passed
fInputParams(&ocParams); // !!!!!!! this is passing the struct
if !ocParams.tContinue {
return;
}
.......
struct cParams {
iInsertMax : i64,
iUpdateMax : i64,
iDeleteMax : i64,
iInstanceMax : i64,
tFirstInstance : bool,
tCreateTables : bool,
tContinue : bool
}
impl cParams {
fn new() -> cParams {
cParams {iInsertMax : -1, iUpdateMax : -1, iDeleteMax : -1, iInstanceMax : -1,
tFirstInstance : false, tCreateTables …Run Code Online (Sandbox Code Playgroud)