在 Rust 中,我试图声明一个自定义结构的静态实例。
因为默认情况下我不能分配 const 以外的其他值,所以我尝试使用lazy_static。
这是我的自定义结构:
pub struct MyStruct {
field1: String,
field2: String,
field3: u32
}
Run Code Online (Sandbox Code Playgroud)
这是我尝试实例化它的方式:
lazy_static! {
static ref LATEST_STATE: MyStruct = {
field1: "".to_string(),
field2: "".to_string(),
field3: 0
};
}
Run Code Online (Sandbox Code Playgroud)
此代码无法编译并出现以下错误:
error: expected type, found `""``
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
在 Golang 中,使用 MongoDB,我尝试存储 GeoJSON 对象,同时保留 2dsphere 索引。
我无法声明一个可以处理“点”和“多边形”的通用结构,因为“点”有一个[]float64坐标字段,而“多边形”有一个[][]float64坐标字段。
您知道如何声明这样的结构吗?
当我在活动中使用它时,Butterknife运行良好,但当我尝试在片段中使用它时,它不起作用:
public class SettingsFragment extends Fragment {
private static final String TAG = "SettingsFragment";
@BindView(R.id.settings_email) TextView _settingsMail;
@BindView(R.id.settings_password) TextView _passwordMail;
@BindView(R.id.settings_token) TextView _tokenMail;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//returning our layout file
final View view = inflater.inflate(R.layout.fragment_3_settings, container, false);
ButterKnife.bind(this, view);
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getContext());
String email = prefs.getString("email", null);
String passwd = prefs.getString("password", null);
String token = prefs.getString("token", null);
_settingsMail.setText(email);
_passwordMail.setText(passwd);
_tokenMail.setText(token);
return inflater.inflate(R.layout.fragment_3_settings, container, false);
}
Run Code Online (Sandbox Code Playgroud)