我收到这个奇怪的错误:
cargo build
Updating crates.io index
error: failed to get `anyhow` as a dependency of package `FlexDB v0.1.0 (E:\projects\FlexDB)`
Caused by:
failed to load source for dependency `anyhow`
Caused by:
Unable to update registry `crates-io`
Caused by:
failed to fetch `https://github.com/rust-lang/crates.io-index`
Caused by:
missing delta bases; class=Indexer (15)
Run Code Online (Sandbox Code Playgroud)
我的cargo.toml文件如下所示:
[package]
name = "FlexDB"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1"
Run Code Online (Sandbox Code Playgroud)
我不知道该怎么办,我做了:
rustup update我是 MongoDB 新手。我想将用户数据存储在数组中。数据是单个唯一的文档。可以说文档是这样的。
User { id: number, name: string }
Run Code Online (Sandbox Code Playgroud)
{
_id : 001,
room: User[],
}
Run Code Online (Sandbox Code Playgroud)
我想做一些这样的事情...
room[]如果没有则推送元素(用户) 。upsert就像更新操作中有选项一样。
DB.Collection.updateOne(
{ _id: "001" },
{ $set: { name: "Bar" } },
{ upsert: true }
);
Run Code Online (Sandbox Code Playgroud)
我怎样才能在文档数组中做这样的事情?
所以我正在做的是,我有 2 个文件,一个包含一个脚本,可以生成一个令牌,第二个文件处理该令牌。
问题在于,记录令牌的第二个脚本只会记录收到的第一个令牌。
这是我处理令牌的方式:
const first_file = require("./first_file.js");
first_file.first_file().then((res) => {
console.log(res);
});
Run Code Online (Sandbox Code Playgroud)
显然这是行不通的,因为它没有用更新的值更新。
first_file = async () => {
return new Promise(async (resolve, reject) => {
//Generating the token
(async () => {
while (true) {
console.log("Resolving...");
resolve(token);
await sleep(5000);
resolved_token = token;
}
})();
});
};
module.exports = { first_file };
Run Code Online (Sandbox Code Playgroud)
我在这里做的是,我尝试做一个,while..loop以便我继续解析令牌。但它没有,有没有办法直接导出变量,这样任务会更容易?
我创建了一个这样的 Obj。
interface obj {
x: number;
y: number;
deep?: {
z: number;
};
}
let obj: obj = {}; // Type '{}' is missing the following properties from type 'obj': x, y
^^^
Run Code Online (Sandbox Code Playgroud)
我可以使用可选字段。但是当我想访问可选字段时,我必须使用空运算符。
// But I don't want to use nullish operator
obj.deep?.z;
// without nullish operator.
obj.deep.z; // Object is possibly 'undefined'.
^^^^^^^^
// this is valid unless some condition (like is async function where its not "undefined" anymore);
Run Code Online (Sandbox Code Playgroud)
因为可选字段需要空运算符。我需要某种方法来忽略“必需属性”类型错误。