Rust语言
文章平均质量分 60
mutourend
Code for ZKP
展开
-
代码即文档?介绍Cargo spec
1. 引言在 David Wong 2022年3月博客The code is the specification? Introducing cargo spec 中,介绍了其在Kimchi项目中使用的cargo-spec工具。2. 说明文档很重要大多数在用的密码学方案都应附有详细的规范说明文档,类似于RFC,但RFC并不是唯一的标准。说明文档具有多重目的:1)用于帮助他人实现某算法或协议。这通常是RFC的目的。2)用于帮助他人理解某协议的工作原理。在仅有代码的情况下,若想要理解某协议,将需要对原创 2022-03-28 12:32:40 · 657 阅读 · 0 评论 -
rust程序性能分析with Flame Graphs
https://github.com/cambrian/accumulator/blob/master/flamegraph.sh中有利用火焰图进行性能分析。dtrace在linux 4.15系统版本上编译安装存在Redefinition of `struct in6_addr’ 问题。参考资料:[1] https://github.com/brendangregg/FlameGraph[...原创 2019-12-12 16:57:42 · 1425 阅读 · 0 评论 -
rust切换老版本及卸载指定版本
1. 查看当前系统已安装的rust版本ls /root/.rustup/toolchains/2. 切换回过去的某个指定版本rustup default xxxxx若提示当前rust版本使用中,可修改相应的toolchain文件即可。具体参照 https://users.rust-lang.org/t/how-can-i-revert-to-older-version-of-ru...原创 2019-08-27 17:12:49 · 17720 阅读 · 4 评论 -
Secp256k1 库
Parity团队的库:https://github.com/paritytech/libsecp256k1 (Rust语言)在该库中,支持no_std,当前,已实现了:Convert a private key to a public keySign messagesSignature verificationPublic key recovery from signed messagesShared secrets...原创 2021-08-31 18:41:41 · 518 阅读 · 0 评论 -
Rust高并发读写
1. dashmapdashmap:为blazingly fast concurrent map in Rust.DashMap is an implementation of a concurrent associative array/hashmap in Rust.原创 2021-08-20 13:53:42 · 1001 阅读 · 0 评论 -
Rust array
参考资料[1] ArrayVec[2] collect_array[3] Provide a means of turning iterators into fixed-size arrays[4] array primitive[5] Implement Debug trait for large array type[6] Why are Rust Arrays Limited To 32 Values?原创 2021-08-12 14:59:13 · 196 阅读 · 0 评论 -
Rust中的channel
1. std::sync::mpsc::channel支持多Sender,仅支持1个Receiver,可保证接收消息的顺序与发送的顺序一致。pub fn channel<T>() -> (Sender<T>, Receiver<T>)会创建新的async channel,返回的是sender/receiver对。所有经由Sender发送的数据顺序,与 在Receiver端收到的数据顺序是一致的。没有任何send操作可阻塞线程,该channel可认为是具有原创 2021-08-05 19:54:57 · 2933 阅读 · 0 评论 -
Rust std VS no_std
嵌入式编程的范围很广:从 仅具有几KB的RAM和ROM的8位MCU到 具有32位或64位 4核 CPU和1GB RAM的树莓派但,嵌入式编程主要可分为2大类:Hosted Environment:类似于有特殊用途的PC环境。具有类似 POSIX 的System Interface 来与 文件系统、网络、内存管理、线程等进行交互。libstd 提供了一些通用接口来访问OS abstractions,同时提供了runtime。在no_std环境下没有这种runtime。Bare Metal En原创 2021-06-22 23:06:22 · 1254 阅读 · 0 评论 -
Rust跨语言调用FFI外部函数接口
1. 背景知识FFI(Foreign Function Interface)外部函数接口:用于规范语言间调用的语言特征。FFI技术的主要功能是:将一种编程语言的语义和调用约定与另一种编程语言的语义和调用约定相匹配。所谓匹配是指:不管哪种编程语言,无论是编译执行还是解释执行,最终都会到达处理器指令环节,在该环节,编程语言之间的语法、数据类型等语义差异均已消除,只需匹配调用约定即可,从而可以实现不同编程语言之间的相互调用。匹配调用约定,需要用到应用程序二进制接口(ABI)。何为ABI?ABI是一个原创 2020-06-03 19:54:46 · 2750 阅读 · 0 评论 -
Rust dependencies依赖管理crates.io原理梳理
1. 背景知识本文针对的是Cargo 1.37版本。Rust项目的依赖主要在Cargo.toml文件[dependencies]段落中定义,常见的依赖方式有:基于rust官方仓库crates.io,通过版本说明来描述;基于项目源代码的git仓库地址,通过URL来描述;基于本地项目的绝对路径或者相对路径,通过类Unix模式的路径来描述。[dependencies]typemap = "0.3" #基于rust官方仓库crates.ioplugin = "0.2*" #基于rust官方仓库c原创 2020-05-28 22:41:14 · 7679 阅读 · 0 评论 -
Rust的hex::encode
对应的crate为hex,在Cargo.toml中配置相应的依赖:[dependencies]hex = {version = "0.3", default-features = false, optional = true}pub fn encode<T: AsRef<[u8]>>(data: T) -> String会将data转换为以小写字母表示的十...翻译 2019-09-17 17:51:31 · 1698 阅读 · 1 评论 -
rust std::mem::swap
pub fn swap<T>(x: &mut T, y: &mut T)Swaps the values at two mutable locations, without deinitializing either one.举例:use std::mem;let mut x = 5;let mut y = 42;mem::swap(&mut ...转载 2019-10-11 16:29:42 · 952 阅读 · 0 评论 -
rust Trait subtle::ConditionallySelectable常量时间执行及应用举例
Trait subtle::ConditionallySelectablepub trait ConditionallySelectable: Copy { fn conditional_select(a: &Self, b: &Self, choice: Choice) -> Self; fn conditional_assign(&mut sel...转载 2019-07-17 11:23:03 · 255 阅读 · 0 评论 -
rust基础库及实用小工具
1. rayonrayon为Rust实现的多线程并发库。2. std::borrow::Cowpub enum Cow<'a, B> where B: 'a + ToOwned + ?Sized, { Borrowed(&'a B), Owned(<B as ToOwned>::Owned),}A clone-on-wri...原创 2019-11-07 11:50:17 · 2147 阅读 · 0 评论