rust

Rust/Webassembly/wasm-bindgen - getting values from `js_sys' Promise

拈花ヽ惹草 提交于 2020-12-13 07:47:48
问题 I'm playing with wasm-bindgen ( https://github.com/rustwasm/wasm-bindgen ), just out of curiosity. While playing with the Navigator ( web_sys crate) I stumbled upon this method: https://docs.rs/web-sys/0.3.36/web_sys/struct.MediaDevices.html#method.enumerate_devices it returns a Result<Promise, JsValue> ..now, I'm new to Rust, and my question is how can I fetch the value of the Promise ? How the Closure::wrap works? How to use it with then method to fetch the results? I wonder if someone

Rust/Webassembly/wasm-bindgen - getting values from `js_sys' Promise

孤街醉人 提交于 2020-12-13 07:47:40
问题 I'm playing with wasm-bindgen ( https://github.com/rustwasm/wasm-bindgen ), just out of curiosity. While playing with the Navigator ( web_sys crate) I stumbled upon this method: https://docs.rs/web-sys/0.3.36/web_sys/struct.MediaDevices.html#method.enumerate_devices it returns a Result<Promise, JsValue> ..now, I'm new to Rust, and my question is how can I fetch the value of the Promise ? How the Closure::wrap works? How to use it with then method to fetch the results? I wonder if someone

Why is transmuting &T to &mut T Undefined Behaviour?

家住魔仙堡 提交于 2020-12-13 06:28:18
问题 I want to reinterpret an immutable reference to a mutable reference (in an unsafe block) and be responsible for the safety checks on my own, yet it appears I cannot use mem::transmute() to do so. let map_of_vecs: HashMap<usize, Vec<_>> = ...; let vec = map_of_vecs[2]; /// obtain a mutable reference to vec here I do not want to wrap the Vec s into Cell s because that would affect all other areas of code that use map_of_vecs and I only need mutability in one line. I do not have mutable access

How do I allocate a Vec<u8> that is aligned to the size of the cache line?

守給你的承諾、 提交于 2020-12-13 03:41:52
问题 I need to allocate a buffer for reading from a File , but this buffer must be aligned to the size of the cache line (64 bytes). I am looking for a function somewhat like this for Vec : pub fn with_capacity_and_aligned(capacity: usize, alignment: u8) -> Vec<T> which would give me the 64 byte alignment that I need. This obviously doesn't exist, but there might be some equivalences (i.e. "hacks") that I don't know about. So, when I use this function (which will give me the desired alignment), I

“cstdarg file not found” when running jextract on the C binding for a Rust project

痴心易碎 提交于 2020-12-13 03:29:07
问题 I'm trying to get a simple integer addition function written in Rust working with Java's Project Panama. Having generated the bindings using cbindgen crate, I get the following error when running jextract: jextract -t org.adder -L . -l adder-java --record-library-path -I /Library/Developer/CommandLineTools/usr/include/c++/v1/cstdarg bindings.h -o adder-java.jar java.lang.RuntimeException: /Users/ash/Code/adder/bindings.h:1:10: fatal error: 'cstdarg' file not found I've looked at the examples

“cstdarg file not found” when running jextract on the C binding for a Rust project

旧巷老猫 提交于 2020-12-13 03:25:54
问题 I'm trying to get a simple integer addition function written in Rust working with Java's Project Panama. Having generated the bindings using cbindgen crate, I get the following error when running jextract: jextract -t org.adder -L . -l adder-java --record-library-path -I /Library/Developer/CommandLineTools/usr/include/c++/v1/cstdarg bindings.h -o adder-java.jar java.lang.RuntimeException: /Users/ash/Code/adder/bindings.h:1:10: fatal error: 'cstdarg' file not found I've looked at the examples

Parsing number with nom 5.0

情到浓时终转凉″ 提交于 2020-12-13 03:04:21
问题 I'm trying to parse a large file (tens of GB) streaming using Nom 5.0. One piece of the parser tries to parse numbers: use nom::IResult; use nom::character::streaming::{char, digit1}; // use nom::character::complete::{char, digit1}; use nom::combinator::{map, opt}; use nom::multi::many1; use nom::sequence::{preceded, tuple}; pub fn number(input: &str) -> IResult<&str, &str> { map( tuple(( opt(char('-')), many1(digit1), opt(preceded(char('.'), many1(digit1))) )), |_| "0" )(input) } (Obviously,

Is it possible to apply a patch to external code in Cargo.toml?

只愿长相守 提交于 2020-12-13 03:01:10
问题 I read the Cargo manual about the patch option but it is still unclear to me. Is it possible to instruct Cargo: Get the code from this repository. Apply this patch file (my_cool_change.patch) to that code. Is making my own fork of the project the only way to do it? 回答1: It is not possible to instruct Cargo to do something like "take version 1.2.3 of crate foo-bar from crates.io and apply these arbitrary changes to the source code before compiling it". The Cargo documentation is not lying to

Is it possible to apply a patch to external code in Cargo.toml?

喜欢而已 提交于 2020-12-13 02:56:35
问题 I read the Cargo manual about the patch option but it is still unclear to me. Is it possible to instruct Cargo: Get the code from this repository. Apply this patch file (my_cool_change.patch) to that code. Is making my own fork of the project the only way to do it? 回答1: It is not possible to instruct Cargo to do something like "take version 1.2.3 of crate foo-bar from crates.io and apply these arbitrary changes to the source code before compiling it". The Cargo documentation is not lying to

专科程序员与本科程序员之间有什么区别?

孤街浪徒 提交于 2020-12-13 00:55:27
点击上方“ 程序员的成长之路 ”,选择“置顶公众号” 技术文章第一时间送达! 先来一张图片,郑重声明一下,它全貌是这样的。 想歪的朋友面壁思过去~~~ 早上好,各位小伙伴们,新的一天开始了。 好看的人都会点文章右下角的好看哦! 程序员就只分为 专科程序员与本科程序员 两种嘛?这种 鄙视链难道就这么短 ?? 必须要这么分: 每类人群,一般是后者瞧不起前者。 首先,你得按照学历来分 - 胎教程序员 - 学前班程序员 - 大班程序员 - 小学程序员 - 普通初中程序员 - 重点初中程序员 - 普通高中程序员 - 重点高中程序员 - 专科程序员 - 普通本科程序员 - 重点本科程序员 当然,你最好加上专业来区分 - 艺术转过来的程序员 - 文科转过来的程序员 - 社科转过来的程序员 - 理科转过来的程序员 - 非科班的工科转过来的程序员 - 法学转过来的程序员 - 商科转过来的程序员 - 科班程序员 其次,你得按照家庭情况来分 - 农村背景 - 四线城市背景 - 三线城市背景 - 二线城市背景 - 一线城市背景 然后,你得按照方向来分 - PC 端工程师 - 安卓工程师 - IOS 工程师 - 运维工程师 - 网络工程师 - 前端工程师 - 后端工程师 - 系统工程师 接着,你得按照开发语言来分 - Java 程序员 - C# 程序员 - Python 程序员 - Rust 程序员 -