tuple-struct

How can I unpack a tuple struct like I would a classic tuple?

六眼飞鱼酱① 提交于 2019-12-22 03:36:44
问题 I can unpack a classic tuple like this: let pair = (1, true); let (one, two) = pair; If I have a tuple struct such as struct Matrix(f32, f32, f32, f32) and I try to unpack it, I get an error about "unexpected type": struct Matrix(f32, f32, f32, f32); let mat = Matrix(1.1, 1.2, 2.1, 2.2); let (one, two, three, four) = mat; Results in this error: error[E0308]: mismatched types --> src/main.rs:47:9 | 47 | let (one, two, three, four) = mat; | = note: expected type `Matrix` found type `(_, _, _, _

How can I unpack a tuple struct like I would a classic tuple?

谁说胖子不能爱 提交于 2019-12-05 01:06:20
I can unpack a classic tuple like this: let pair = (1, true); let (one, two) = pair; If I have a tuple struct such as struct Matrix(f32, f32, f32, f32) and I try to unpack it, I get an error about "unexpected type": struct Matrix(f32, f32, f32, f32); let mat = Matrix(1.1, 1.2, 2.1, 2.2); let (one, two, three, four) = mat; Results in this error: error[E0308]: mismatched types --> src/main.rs:47:9 | 47 | let (one, two, three, four) = mat; | = note: expected type `Matrix` found type `(_, _, _, _)` How can I unpack a tuple struct? Do I need to convert it explicitly to a tuple type? Or do I need to

Tuple struct constructor complains about private fields

巧了我就是萌 提交于 2019-11-30 08:02:34
问题 I am working on a basic shell interpreter to familiarize myself with Rust. While working on the table for storing suspended jobs in the shell, I have gotten stuck at the following compiler error message: error: cannot invoke tuple struct constructor with private fields [E0450] let jobs = job::JobsList(vec![]); ^~~~~~~~~~~~~ It's unclear to me what is being seen as private here. As you can see below, both of the structs are tagged with pub in my module file. So, what's the secret sauce? mod

Tuple struct constructor complains about private fields

泪湿孤枕 提交于 2019-11-29 05:35:48
I am working on a basic shell interpreter to familiarize myself with Rust. While working on the table for storing suspended jobs in the shell, I have gotten stuck at the following compiler error message: error: cannot invoke tuple struct constructor with private fields [E0450] let jobs = job::JobsList(vec![]); ^~~~~~~~~~~~~ It's unclear to me what is being seen as private here. As you can see below, both of the structs are tagged with pub in my module file. So, what's the secret sauce? mod job { use std::fmt; pub struct Job { jid: isize, pid: isize, cmd: String, } pub struct JobsList(Vec<Job>)