rust

How is “git pull” done with the git2-rs Rust crate?

ぃ、小莉子 提交于 2021-02-08 15:16:39
问题 I'm using git2-rs to implement some standard git functionality in a Rust application. I've been reading up on git internals and understand that at a high level "git pull" is a "git fetch" followed by a "git merge", but am still having trouble understanding how to make it work with git2-rs. There is a discussion on an issue here where it's agreed that a git2-rs "git pull" example would be nice, but one was never created. There is an example of doing a hard reset in that discussion, but I want

When compiling Rust to wasm (web assembly), how can I sleep for 10 milliseconds?

强颜欢笑 提交于 2021-02-08 15:15:26
问题 My rust program is managing memory for a 2d html canvas context, and I'm trying to hit ~60fps. I can calculate the delta between each frame easily, and it turns out to be roughly ~5ms. I'm unclear on how to put my Rust webassembly program to sleep for the remaining 11ms. One option would be to have JavaScript call into Rust on every requestAnimationFrame and use that as the driver, but I'm curious to keep it all in Rust if possible. I'm effectively looking for the Rust equivalent of

Documenting a function created with a macro in Rust [duplicate]

吃可爱长大的小学妹 提交于 2021-02-08 15:14:30
问题 This question already has an answer here : Generating documentation in macros (1 answer) Closed 4 years ago . I tried to do #![deny(missing_docs)] in Rust. And I found that /// comments are just ignored when a function is created with a macro like this: /// docs py_module_initializer!(libx, initlibx PyInit_libx |py, m| { Ok(()) }); with: error: missing documentation for a function 113 | py_module_initializer!(libx initlibx PyInit_libx |py, m| { | ^ I thought a macro will just add a function

Documenting a function created with a macro in Rust [duplicate]

我怕爱的太早我们不能终老 提交于 2021-02-08 15:13:38
问题 This question already has an answer here : Generating documentation in macros (1 answer) Closed 4 years ago . I tried to do #![deny(missing_docs)] in Rust. And I found that /// comments are just ignored when a function is created with a macro like this: /// docs py_module_initializer!(libx, initlibx PyInit_libx |py, m| { Ok(()) }); with: error: missing documentation for a function 113 | py_module_initializer!(libx initlibx PyInit_libx |py, m| { | ^ I thought a macro will just add a function

How is “git pull” done with the git2-rs Rust crate?

回眸只為那壹抹淺笑 提交于 2021-02-08 15:13:05
问题 I'm using git2-rs to implement some standard git functionality in a Rust application. I've been reading up on git internals and understand that at a high level "git pull" is a "git fetch" followed by a "git merge", but am still having trouble understanding how to make it work with git2-rs. There is a discussion on an issue here where it's agreed that a git2-rs "git pull" example would be nice, but one was never created. There is an example of doing a hard reset in that discussion, but I want

Can a vector be moved and modified without an extra allocation?

孤街醉人 提交于 2021-02-08 15:10:53
问题 Consider the following code: let u: Vec<u8> = (64..74).collect(); let v: Vec<u8> = u.iter().map(|i| i + 1).collect(); u was not moved, therefore v was inevitably newly allocated. But if I do the following: let w: Vec<u8> = u.into_iter().map(|i| i + 1).collect(); u was moved and w is the name of its transformation. Here is some pseudo-code representing what I mean: mark u as "moved" for i = 0..10: u[i] += 1 w = u There is (in my opinion) no need for a new allocation, since we map a type to

When compiling Rust to wasm (web assembly), how can I sleep for 10 milliseconds?

亡梦爱人 提交于 2021-02-08 15:10:19
问题 My rust program is managing memory for a 2d html canvas context, and I'm trying to hit ~60fps. I can calculate the delta between each frame easily, and it turns out to be roughly ~5ms. I'm unclear on how to put my Rust webassembly program to sleep for the remaining 11ms. One option would be to have JavaScript call into Rust on every requestAnimationFrame and use that as the driver, but I'm curious to keep it all in Rust if possible. I'm effectively looking for the Rust equivalent of

When compiling Rust to wasm (web assembly), how can I sleep for 10 milliseconds?

空扰寡人 提交于 2021-02-08 15:09:27
问题 My rust program is managing memory for a 2d html canvas context, and I'm trying to hit ~60fps. I can calculate the delta between each frame easily, and it turns out to be roughly ~5ms. I'm unclear on how to put my Rust webassembly program to sleep for the remaining 11ms. One option would be to have JavaScript call into Rust on every requestAnimationFrame and use that as the driver, but I'm curious to keep it all in Rust if possible. I'm effectively looking for the Rust equivalent of

How to wrap a native library with init/exit semantics

被刻印的时光 ゝ 提交于 2021-02-08 14:46:05
问题 I made a wrapper around a C library which creates a device that you must explicitly close. Writing the raw FFI functions was easy, but how do I make it ergonomic Rust in a higher level wrapper? Specifically, should I be doing it the RAII style and only using Drop to ensure the close is called when it goes out of scope, instead of exposing the close() method to the caller? Which way is the most idiomatic in Rust? There are basically 3 options: Thin wrapper that requires the same close() calls

Iterator that returns each Nth value

人盡茶涼 提交于 2021-02-08 14:39:05
问题 I have an iterator iter ; is it possible to convert it into an iterator that iterates over each Nth element? Something like iter.skip_each(n - 1) ? 回答1: As of Rust 1.26, there is the Iterator::step_by method in the standard library: Basic usage: let a = [0, 1, 2, 3, 4, 5]; let mut iter = a.iter().step_by(2); assert_eq!(iter.next(), Some(&0)); assert_eq!(iter.next(), Some(&2)); assert_eq!(iter.next(), Some(&4)); assert_eq!(iter.next(), None); 回答2: As Dogbert said, use itertools' step. You are