provekit_nargo_cli 1.0.0-beta.20-alpha.1

Noir's package manager
Documentation
---
source: tooling/nargo_cli/tests/execute.rs
expression: expanded_code
---
struct Foo {
    bar: Field,
    array: [Field; 2],
}

impl Foo {
    fn default(x: Field, y: Field) -> Self {
        Self { bar: 0_Field, array: [x, y] }
    }
}

struct Pair {
    first: Foo,
    second: Field,
}

impl Pair {
    fn foo(p: Self) -> Foo {
        p.first
    }

    fn bar(self) -> Field {
        Self::foo(self).bar
    }
}

struct Nested {
    a: Field,
    b: Field,
}

struct MyStruct {
    my_bool: bool,
    my_int: u32,
    my_nest: Nested,
}

fn test_struct_in_tuple(a_bool: bool, x: Field, y: Field) -> (MyStruct, bool) {
    let my_struct: MyStruct =
        MyStruct { my_bool: a_bool, my_int: 5_u32, my_nest: Nested { a: x, b: y } };
    (my_struct, a_bool)
}

struct Animal {
    legs: Field,
    eyes: u8,
}

fn get_dog() -> Animal {
    let dog: Animal = Animal { legs: 4_Field, eyes: 2_u8 };
    dog
}

struct Unit {}

fn main(x: Field, y: Field) {
    let unit: Unit = Unit {};
    let first: Foo = Foo::default(x, y);
    let p: Pair = Pair { first: first, second: 1_Field };
    assert(p.bar() == x);
    assert(p.second == y);
    assert(p.first.array[0_u32] != p.first.array[1_u32]);
    let (struct_from_tuple, a_bool): (MyStruct, bool) = test_struct_in_tuple(true, x, y);
    assert(struct_from_tuple.my_bool == true);
    assert(a_bool == true);
    assert(struct_from_tuple.my_int == 5_u32);
    assert(struct_from_tuple.my_nest.a == 0_Field);
    let Animal { legs, eyes }: Animal = get_dog();
    let six: Field = legs + (eyes as Field);
    assert(six == 6_Field);
    let Animal { legs: _, eyes: _ }: Animal = get_dog();
}