noir by example

strings

strings are fixed length values in noir str<N>

use dep::std;

fn main(
    message : pub str<11>,
    hex_as_string : str<4>,
    hex_as_field : Field,
) {
    assert(message == "hello world");
    
    std::println(hex_as_string);
    std::println(hex_as_field);

    // this fails to compile, type mismatch between str[4] and Field
    // assert(hex_as_string != hex_as_field);
}

#[test]
fn test_main() {
    main("hello world", "0x41", 0x41);
}

#[test]
fn test_printing_strings() {
    let message = "hello world!";

    std::println(message);
    std::println("goodbye world");

    let array = [1, 2, 3, 5, 8];
    std::println(array);

    let hash = std::hash::pedersen_hash(array);
    std::println(hash);

    let s = Test { a: 1, b: 2, c: [3, 4] };
    std::println(s);
}

struct Test {
    a: Field,
    b: Field,
    c: [Field; 2],
}

try it out install the noir toolchain if you haven't yet:
        curl -L https://noirup.org/install | bash
        noirup --nightly
        
then checkout and run the example:
        git clone https://github.com/sambarnes/noir-by-example.git
        cd noir-by-example/circuits/examples/strings
        nargo test --show-output
        

prev (if / else) next (loops)