File: destructure.rs

package info (click to toggle)
rust-multiversion 0.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 168 kB
  • sloc: makefile: 2
file content (43 lines) | stat: -rw-r--r-- 1,196 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
struct Foo {
    x: i64,
    y: i64,
}

#[multiversion::multiversion(targets("x86_64+avx", "aarch64+neon"))]
fn destructure_tuple_multiversion((x, y): (i64, i64)) -> (i64, i64) {
    (x, y)
}

#[multiversion::multiversion(targets("x86_64+avx", "aarch64+neon"))]
fn destructure_struct_multiversion(Foo { x, y }: Foo) -> (i64, i64) {
    (x, y)
}

#[multiversion::multiversion(targets("x86_64+avx", "aarch64+neon"))]
fn destructure_tuple((x, y): (i64, i64)) -> (i64, i64) {
    (x, y)
}

#[multiversion::multiversion(targets("x86_64+avx", "aarch64+neon"))]
fn destructure_struct(Foo { x, y }: Foo) -> (i64, i64) {
    (x, y)
}

#[multiversion::multiversion(targets("x86_64+avx", "aarch64+neon"))]
fn destructure_tuple_generic<T>((x, y): (T, T)) -> (T, T) {
    (x, y)
}

#[cfg(test)]
mod test {
    use super::*;

    #[test]
    fn destructure() {
        assert_eq!(destructure_tuple((1, 2)), (1, 2));
        assert_eq!(destructure_tuple_multiversion((3, 4)), (3, 4));
        assert_eq!(destructure_struct(Foo { x: 1, y: 2 }), (1, 2));
        assert_eq!(destructure_struct_multiversion(Foo { x: 3, y: 4 }), (3, 4));
        assert_eq!(destructure_tuple_generic((1i64, 2i64)), (1, 2));
    }
}