Learning Rust :safe:

Announcing Rust 1.56.0 and Rust 2021

https://doc.rust-lang.org/edition-guide/rust-2021/index.html

7 Likes

Certainly.

300k satoshi should be easily attainable if you have the skills.

4 Likes

Looks like Jack is also getting on the train.

2 Likes

I’ve just completed a Redbin format for serde. Now I can transfer values (function arguments and return values) easily in my Red ↔ Safenet ffi bindings project. Learned a lot about Rust. Everyone feel free to review the code and drop me an issue or PR :-), thanks.

7 Likes

I’m thinking of using vdash soon (an terminal GUI app for those running a Safe Network Node) so if anyone fancies working with me to update vdash and learn a bit of Rust with my support let me know. It’s a good way to learn programming or a new language.

I always learned by taking existing code and modifying it to do what I want, so it’s a good opportunity to scratch that itch. And when that code is being used by others there’s a real buzz.

Topic about vdash:

6 Likes

I don’t have time now, but I want to learn Rust properly later. Thx (‘고마워요.’) @happybeing

3 Likes

Any time!

Ten chars

1 Like

In case anyone is interested in a free online Rust course this, just tweeted by a friend:

4 Likes

…and just got stuck :-/

Now I’m working on implementing deserialization into &str (needed for deserialization of arguments like Option<&Path> in Safe::connect) and ran into a lifetime problem (error E0495). Please, if anybody could help me with this, will have my gratitude to the end of my life! I’ve spent 4 days on it already :-/

it’s in separate branch: GitHub - loziniak/redbin at str_de2

I’m not sure I can exactly explain where the problem is, but I’ve tried to clean everything up, so if you run cargo test, there is only the mentioned error left (repeated in 3 places).

2 Likes

Damn you @happybeing, I have not slept since yesterday cos this Replit

WTF is wrong here?

 cargo run --bin combiner
   Compiling fcc-rust-in-replit v0.1.0 (/home/runner/Rust-in-Replit)
warning: unused import: `ImageFormat`
 --> combiner/src/main.rs:6:39
  |
6 | use image::{io::Reader, DynamicImage, ImageFormat};
  |                                       ^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error[E0308]: mismatched types
  --> combiner/src/main.rs:17:10
   |
13 | fn find_image_from_path(path: String) -> DynamicImage {
   |                                          ------------ expected `DynamicImage` because of return type
...
17 |   return (image, image_format);
   |          ^^^^^^^^^^^^^^^^^^^^^ expected enum `DynamicImage`, found tuple
   |
   = note: expected enum `DynamicImage`
             found tuple `(DynamicImage, ImageFormat)`

error: aborting due to previous error; 1 warning emitted

For more information about this error, try `rustc --explain E0308`.
error: could not compile `fcc-rust-in-replit`

Does this deserve a wee award for Most Unhelpful Error Msg Ever?

13 | fn find_image_from_path(path: String) -> DynamicImage {
   |                                          ------------ expected `DynamicImage` because of return type
1 Like

The error is saying what you are returning is not DynamicImage but something else. What you are returning is the tuple return (image, image_format); :wink: So you need to change the return type or change what you are returning.

5 Likes

The lesson instructions are

LESSON #32

You have learnt about the empty tuple type (). Now, you will use a tuple to return multiple values. Unlike other types, a tuple can contain more than one type.

// The Vec type can only contain one type.
let my_vec = vec![1u8, 2u16, 3u32];
// Tuples can contain multiple types.
let my_tuple = (1u8, 2u16, 3u32);

Task: From find_image_from_path, return a tuple containing the DynamicImage and ImageFormat of the image, in that order.

Run cargo test --bin combiner to see if you correctly completed the task.

When you are done, type the following for the next lesson:
$ fcc 33

fn find_image_from_path(path: String) -> (DynamicImage, ImageFormat) {
  let image_reader = Reader::open(path).unwrap();
  let image_format = image_reader.format().unwrap();
  let image = image_reader.decode().unwrap();
  return (image, image_format);
}

passes the tests but panics later so its progress :slight_smile: Thanks David :slight_smile:

Once I work my way through this another few dozen times, the syntax will hopefully start to stick with me but its a sair fecht…

1 Like

It’s just some contextual info about the expected return type. The real error is in line 17.

2 Likes

Unstuck: Trouble with lifetimes in serde format implementation - help - The Rust Programming Language Forum

Turned out it’s not possible to do what I wanted, because Redbin string encoding is not compatible with UTF-8, so I implemented only for ASCII:

2 Likes

Some issues for anyone wanting to learn a bit of Rust while helping out with vdash:

7 Likes

Anybody else watching this channel? Let’s Get Rusty

Im slowly working my way through all his videos and beginning to understand more and more. Still finding a few things that go wrong when trying to follow along, I suspect my extensions in VSCode are being very strict.

Let me know if you have tried to follow along and what issues you hit.

Heres me scratching my head worrying about a comma while doing a tutorial on Structs

the build_user function is


fn build_user(email: String, username: String) -> User {
    User {
        email,
        username,
        active: true,
        sign_in_count: 1,
    }
5 Likes
build_user(String::from("asd"), String::from("dsa"));

without “email:” & “username:”

2 Likes

and then there was a LOT less red squiggles :slight_smile:

Thank you.

Just had this delivered :slight_smile:

4 Likes

Here’s a link to the Lets Get Rusty discord server
Let's Get Rusty.

3 Likes