我在使用react-hook-form 和material-ui 时遇到了困难。
我准备了一个codesandbox示例。
import { TextField } from "@material-ui/core";
import React from "react";
import { useForm } from "react-hook-form";
import "./styles.css";
interface IMyForm {
vasarlo: string;
}
export default function App() {
const {
handleSubmit,
formState: { errors },
register
} = useForm<IMyForm>();
const onSubmit = (data: IMyForm) => {
alert(JSON.stringify(data));
};
return (
<form onSubmit={handleSubmit(onSubmit)}>
<label>First Name</label>
<TextField
variant="outlined"
margin="none"
label="Test"
{...register("vasarlo", {
required: "error text"
})}
error={errors?.vasarlo ? true : false}
helperText={errors?.vasarlo ? errors.vasarlo.message : …Run Code Online (Sandbox Code Playgroud) 我想要一个排序数组,其中包含 f64 作为键和 f64 作为值。我需要通过找到正确的键来更新、删除和插入该数组。我需要获取前 1000 个排序条目,以及第一个条目。这些操作必须很快。
通过阅读文档,我认为 BTreeMap 对我有好处。
但是,当我尝试插入它时,我收到以下错误消息:
the trait bound `f64: Ord` is not satisfied
the trait `Ord` is not implemented for `f64`rustcE0277
Run Code Online (Sandbox Code Playgroud)
使用 Rust 执行此操作的推荐方法是什么?
我的代码:
use std::collections::BTreeMap;
pub struct MyStruct {
pub map: BTreeMap<f64, f64>
}
impl MyStruct {
pub fn new() -> MyStruct {
MyStruct {
map: BTreeMap::new()
}
}
}
fn main() {
let mut my_struct = MyStruct::new();
my_struct.map.insert(1.0, 2.0);
}
Run Code Online (Sandbox Code Playgroud)