Compound data type: Difference between revisions

Content added Content deleted
Line 1,513: Line 1,513:


=={{header|Rust}}==
=={{header|Rust}}==
===Structs===
==Structs==
There are three kinds of <code>struct</code>s in Rust, two of which would be suitable to represent a point.
There are three kinds of <code>struct</code>s in Rust, two of which would be suitable to represent a point.


====C struct====
===C-like struct===
<lang rust> // Defines a generic struct where x and y can be of any type T
<lang rust> // Defines a generic struct where x and y can be of any type T
struct Point<T> {
struct Point<T> {
Line 1,527: Line 1,527:
} </lang>
} </lang>


====Tuple struct====
===Tuple struct===
These are basically just named tuples.
These are basically just named tuples.
<lang rust>struct Point<T>(T, T);
<lang rust>struct Point<T>(T, T);
Line 1,534: Line 1,534:
println!("{},{}", p.0, p.1);
println!("{},{}", p.0, p.1);
}</lang>
}</lang>
===Tuples===
==Tuples==
<lang rust> fn main() {
<lang rust> fn main() {
let p = (0.0, 2.4);
let p = (0.0, 2.4);