rust函数返回重新借用的参考,创建多个可变参考

时间:2019-06-29 11:04:47

标签: rust ownership

基于 https://www.reddit.com/r/rust/comments/46qwjv/why_can_i_use_an_mut_reference_twice/

函数返回实际编译的@OnTouch(R.id.old_pwd) boolean toChangePasswordText(View v, MotionEvent event) { final int DRAWABLE_RIGHT = 2; if (event.getAction() == MotionEvent.ACTION_UP) { if (event.getRawX() >= (old_pwd.getRight() - old_pwd.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) { if (old_pwd.getInputType() == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD) { old_pwd.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD); old_pwd.setCompoundDrawablesWithIntrinsicBounds(null, null, context.getResources().getDrawable(R.mipmap.icn_eye), null); old_pwd.setSelection(old_pwd.getText().length()); } else { old_pwd.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD); old_pwd.setCompoundDrawablesWithIntrinsicBounds(null, null, context.getResources().getDrawable(R.mipmap.icn_eyecross), null); old_pwd.setSelection(old_pwd.getText().length()); } return true; } } return false; } 引用

re-borrowed

现在我们同时具有对同一变量// rustc version = rustc 1.35.0 (3c235d560 2019-05-20) fn mutate(val: &mut i32) -> &mut i32 { *val += 1; val // &mut *y returned? } fn main() { let mut x = 0; let y = &mut x; let z = mutate(y); // re-borrow &mut *y *z += 1; *y += 1; // this goes first will cause error println!("{}", x); } 的2个可变引用吗?这个奇怪的事情与x有关系吗? non-lexical lifetimey有什么区别,谢谢。

0 个答案:

没有答案