Skip to content
This repository has been archived by the owner on Jun 6, 2021. It is now read-only.

Product Types #13

Open
Vengarioth opened this issue Aug 12, 2017 · 0 comments
Open

Product Types #13

Vengarioth opened this issue Aug 12, 2017 · 0 comments

Comments

@Vengarioth
Copy link
Member

Syntax proposal : Product Types

Product types to model tuples and units.

examples

a function returning the unit type (empty tuple)

fn main() {
    // implementation
}

a function returning a product type (tuple)

fn main() -> (f32, i32) {
    return (0.0, 1);
}

constructing a product type

this example creates a product type (f32, i32, Foo).

let my_product_type_value = (0.0, 1, Foo::new());

destructuring a product type

both values of the tuple are available as local foo and bar

fn get_foo_bar() -> (Foo, Bar) {
    return (Foo::new(), Bar::new());
}

fn main() {
    let (foo, bar) = get_foo_bar();
}

omitting a value during destructuring

only foo is available since the second value was discarded with the _ operator

fn get_foo_bar() -> (Foo, Bar) {
    return (Foo::new(), Bar::new());
}

fn main() {
    let (foo, _) = get_foo_bar();
}

accessing single values from a product type

let my_product_type_value = (0.0, 1, Foo::new());
let foo = my_product_type_value.2;
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant