Category "rust"

Using Rust with C API and mut/pointer problems with types

I'm trying to interact with a low-level C API using Rust. It requires calling to get the size of an array, then calling again with an allocated array of structs

Why is this match pattern unreachable when using non-literal patterns?

The following code (playground) let max_column = 7; edge = match current_column { 0 => Edge::Left, max_column => Edge::Right, _ => Edge::N

How should I handle smart contract structure change in NEAR protocol?

Suppose I have a contract ... pub struct Contract { collection_a: Vector<String>, } After I deploy this version, when I change the data structure of my

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