How Do You Troubleshoot the Cargo/Rust Error “use of undeclared type or module”?

Problem Scenario
You run a “cargo run” command. You get an error like one or more of the following:

use of undeclared type or module api

use of undeclared type or module serde_json

use of undeclared type or module async-std

What should you do?

Solution
Update the Cargo.toml file. The dependencies section should have an entry like one of the following (but the version number may or may not differ):

[package]
name = “in3-tutorial”
version = “0.0.1”
authors = [”reader@medium.com”]
edition = “2018”

[dependencies]
in3 = “0.1.7”
async-std = “1.5.0”
futures-executor = “0.3.5”
serde_json = “1.0”
ethabi = “13.0.0”
ethereum_abi = “0.2.0”
ethbloom = “0.10.0”

[[bin]]
name = “in3”
path = “/home/jdoe/rust/contint.rs”

If you are not sure what version is valid,

How Do You Troubleshoot “cp: cannot stat …: No such file or directory” when Running build_rust.sh?

Problem scenario
You are running build_rust.sh to use Blockchains’ Incubed. But you get an error message like this:

cp: cannot stat ‘c/CMakeLists.txt’: No such file or directory
cp: cannot stat ‘c/macro.cmake’: No such file or directory
cp: cannot stat ‘c/compiler.cmake’: No such file or directory
cp: cannot stat ‘c/docs’: No such file or directory
cp: cannot stat ‘c/src’: No such file or directory
cp: cannot stat ‘c/include’: No such file or directory
cp: cannot stat ‘CMakeLists.txt’: No such file or directory

What should you do?

How Do You Get Python to Search a Web Page for a Specific Pattern?

Problem scenario
How do you write a Python 3 program to parse the text of a web page and determine if a string is on the web page or not?

Solution
Change the “yoururl” variable assignment and the “searchterm” assignment below to what you desire. Then run the program below:

import re
import requests
yoururl = ‘https://www.continualintegration.com/’
searchterm = “learned”
r = requests.get(yoururl)
found = re.search(searchterm, …

How Do You Write a Python Program to Test if Integers Are in Order?

Problem scenario
You need to write a Python program to see if a list of unique integers is in order. You can copy the list and sort it to compare the ideal state to the list provided. The program must print out a relevant message if a swap of two numbers can place those two numbers in the correct order. The program must print out if a given number is already in order.

How Do You Troubleshoot “/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:83:in `require’: cannot load such file — winrm-elevated (LoadError)”?

Problem scenario
You run a Vagrant command. But you get this message: “/usr/share/rubygems/rubygems/core_ext/kernel_require.rb:83:in `require’: cannot load such file — winrm-elevated (LoadError)”

What should you do?

Solution
Run this command:

vagrant plugin install winrm-elevated …

How Do You Write a “Hello World” Command in Rust?

Problem scenario
You want to write a basic program in Rust to know you have it installed correctly. What do you do?

Solution

  1. Install Rust. If you need assistance, try this command:

sudo curl –proto ‘=https’ –tlsv1.2 -sSf https://sh.rustup.rs | sh

2. Create a file called contint.rs with the following four lines:

// We recommend calling this contint.rs
fn main() {
println!(“Hello World!”); …

What Does the “-> str” Syntax Signify in Python Functions?

Problem scenario
You see Python code with this “-str” syntax. What does it do?

Answer
It is purely for readability. To help your coworkers we recommend using the “-str” syntax if a function returns a string. Otherwise the way to find out is to read the code or temporarily change the code and use type(variable_returned) to show the data type of that which is/was returned.

In Object-Oriented Programming What Is an Object’s Operation’s Signature?

Question
You are learning about OOP. You know object’s have operations. You read about operations having signatures. What are signatures?

Answer
An object’s operation’s signature is the composite of these three things:

  1. the operation’s name
  2. the parameter objects the operation accepts
  3. the return value of the operation

(This was paraphrased from page 13 of Design Patterns).