首先,我不是问&mut和ref mut本身有什么区别.
我在问,因为我想:
let ref mut a = MyStruct
Run Code Online (Sandbox Code Playgroud)
是相同的
let a = &mut MyStruct
Run Code Online (Sandbox Code Playgroud)
考虑从函数返回特征对象.你可以退还一个Box<Trait>或一个&Trait.如果您希望对其方法进行可变访问,是否可以返回&mut Trait?
鉴于这个例子:
trait Hello {
fn hello(&mut self);
}
struct English;
struct Spanish;
impl Hello for English {
fn hello(&mut self) {
println!("Hello!");
}
}
impl Hello for Spanish {
fn hello(&mut self) {
println!("Hola!");
}
}
Run Code Online (Sandbox Code Playgroud)
该方法接收可变参考用于演示目的.
这不会编译:
fn make_hello<'a>() -> &'a mut Hello {
&mut English
}
Run Code Online (Sandbox Code Playgroud)
也不是这样
fn make_hello<'a>() -> &'a …Run Code Online (Sandbox Code Playgroud) 这是我的问题,我有一个非常简单的布局,显示2个EditText,一个用于标题,另一个用于描述。这是xml文件:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<EditText
android:layout_width="match_parent"
android:layout_height="63dp"
android:id="@+id/title_field"
android:background="#ffffffff"
android:hint="@string/titleFieldHint"
android:padding="20dp"
android:textSize="8.5pt"
android:maxLines="1"/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"/>
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/description_field"
android:hint="@string/descriptionHint"
android:gravity="top"
android:padding="20dp"
android:scrollbars="vertical"
android:textSize="8.5pt"
android:background="#ffffff"
android:inputType="textMultiLine"
android:textIsSelectable="true"
android:focusableInTouchMode="true" android:layout_weight="1"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
当我使用此布局启动活动时,键盘显示聚焦的title_field,因此我可以编写并单击另一个字段(当键盘仍处于打开状态)并编写说明。但是,如果我隐藏键盘,除非单击title_field,否则它将不会再次显示(键盘),因此description_field不响应,此外title_field支持开箱即用的选择(包括上下文操作栏),而description_field不会让我甚至选择。
我才刚刚开始android开发,我缺少什么吗?