Learning Rust :safe:

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:
https://www.amazon.co.uk/dp/B09QFQ3Y64/ref=dp_kinw_strp_1

4 Likes

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

3 Likes

Blah blahblah help @Southside

Free ebook by Mara Bos.

5 Likes

Wow, that’s amazing, I missed that when I landed on the page before. People recommended it as a great Rust book, but I saw the prices for the physical edition and was deterred. Is there any guarantee though that she keeps that digital version up for free? :grimacing:

3 Likes

I’ll be uploading it to the next testnet :slight_smile:

 safe cat "safe://hyryyry1bg1xdudnamk8uyzqo8w854tmpabf19qm16d5cijot18oi3cttdrnra?v=hj3jne1zd5i4oodrh1a9kkfiq9iyb391g74rkr8kzi4i56uqp467o"
Files of FilesContainer (version hj3jne1zd5i4oodrh1a9kkfiq9iyb391g74rkr8kzi4i56uqp467o) at "safe://hyryyry1bg1xdudnamk8uyzqo8w854tmpabf19qm16d5cijot18oi3cttdrnra?v=hj3jne1zd5i4oodrh1a9kkfiq9iyb391g74rkr8kzi4i56uqp467o":
+---------------------------------+-----------------+--------+------------+------------+--------------------------------------------------------------------+
| Name                            | Type            | Size   | Created    | Modified   | Link                                                               |
|---------------------------------+-----------------+--------+------------+------------+--------------------------------------------------------------------|
| /atomics                        | inode/directory | 0      | 1672990287 | 1672990287 |                                                                    |
|---------------------------------+-----------------+--------+------------+------------+--------------------------------------------------------------------|
| /atomics/alt                    | inode/directory | 0      | 1672990287 | 1672990287 |                                                                    |
|---------------------------------+-----------------+--------+------------+------------+--------------------------------------------------------------------|
| /atomics/alt/3-1.html           | text/html       | 4285   | 1672990287 | 1672990287 | safe://hy8oyrymt63im4178dhyn3ta4wh8mpw7wx1z6nu3ort4dna8wcinh894uqh |
|---------------------------------+-----------------+--------+------------+------------+--------------------------------------------------------------------|
| /atomics/alt/3-2.html           | text/html       | 4385   | 1672990287 | 1672990287 | safe://hy8oyrypoxx1ykhocfhkdjf54zaosq8mzneqdbinrzmft3tpnqbrpbtkpfa |
|---------------------------------+-----------------+--------+------------+------------+--------------------------------------------------------------------|
| /atomics/alt/3-3.html           | text/html       | 4836   | 1672990287 | 1672990287 | safe://hy8oyryj6f5rdnsyq69cs59adcqrptajn4h63s9ryzmfq8bgs1tpgh74pia |
|---------------------------------+-----------------+--------+------------+------------+--------------------------------------------------------------------|
3 Likes

This is the best intro to rust I’ve come across

10 Likes

It only became available for free yesterday.
Way beyond my needs or understanding but figured it may be of use to some :smile:

2 Likes

Speed up build times using a new super fast linker: mold

cc @chriso

2 Likes

It’s actively for sale and for macos it is "sold which is a shame

2 Likes