Category "rust"

How to remove Smart Contract in NEAR Protocol?

I am new to blockchain and Near Protocol. I have created 2 smart contracts on Near Protocol. The first one was successfully done but when I try to deploy the se

Serialize/Deserialize json array to struct

I have incoming data in a json array that I deserialize into a struct, but I can't seem figure out how to serialize it back into an array instead of an object.

How do you check if an arithmetic operation will overflow?

I am coming from looking at Rust and How do I detect unsigned integer multiply overflow? where in Rust they have checked_add, which is implemented like this: pu

Deserialize using a function of the tag

An API with this internally tagged field structure, with "topic" being the tag: { "topic": "Car" "name": "BMW" "HP": 250 } This can be deserialized

Avoid using partially moved value in match statement

The solution provided in question 38553513 does not work for me. Consider these types and functions: pub enum Parameter { ParameterTypeA { n: i32 }, Par

Error in thread 'main' panicked at 'Building libffi',

System: Ubuntu 22.04 LTS (Wayland). I am trying to build a simple rsmpi code (Rust+MPI), but I am unable to build it because of the error : thread 'main' panick

Decoupling ownership from vector

I'm creating factory methods for objects with shared references. The compiler cannot see that the objects from a Vec are not referenced outside the local scope,

How do you implement a trait for T where T: Foo OR Bar

In rust, you can automatically implement a trait for any type that implements some other combination of traits. Ie: impl<T: Foo + Bar> SomeTrait for T {

How to use local project files in build.rs script?

How do I use local files without including their absolute paths in build.rs? I have, for example let proto_file_glob_paths: Paths = glob("../proto/**/*.proto").

Implementing Borrow trait for a type with a lifetime

I'm trying to use. strongly typed wrapper for a "keys" in my program, so that I don't mistake arbitrary strings for a Key. I have: #[derive(Debug, Clone, Partia

Poll raw file descriptor for data

I would like to poll a raw file descriptor for data and process it as it gets written to. This needs to be done on a separate thread so that my main thread is

How to send prompt input to std::process::Command in rust?

I'm writing a cli tool for automate the archlinux installation, that is based on toml config files... Currently i have this problem... Once the base system is i

cargo install cargo-generate --features vendored-openssl failed

I am trying to install terrain from terra-money. For that, the instructions said to follow the commands. I have run these instructions on ubuntu 20.04 1. Set 's

How to use .cargo/config.toml file with both stable and nightly rust toolchain?

I have installed both nightly and stable rust toolchains and make some -Z ... compile flags for nightly, but the stable rust can't recognize it and stops compil

How to use nom to parse until a string is found?

It's easy to use nom to parse a string until a character is found. How to use nom to gobble a string until a delimiter or the end? deals with this. How do I do

Newtype pattern error: cannot move out of dereference of

I want to create a Wrapper around an existing type/struct. According to the Newtype pattern, as per Rust Book ch 19, "implementing Deref trait on the Wrapper to

Cargo error: duplicate lang item in crate `casper_contract` (which `contract` depends on): `panic_impl`

I am trying to use the standard casper demo project as generated by command "cargo casper my-project" but with some std::io. I want to read a value from the con

Problem trying to install diesel (Mac air m1)

I am following the diesel guide: LINK When i try this: cargo install diesel_cli --no-default-features --features postgres i receive this error: error: failed t

Generic lifetime parameter and local scope

piet is a drawing library with generic backends (cairo, for example). I want to have a trait Renderable that can render to any piet backend (=context). pub trai

Custom openapi schema with rust, rocket and okapi

I am developing an API with Rust, using Rocket as main framework. To create the Swagger docs I use Okapi, which allows me to create the docs automatically. use