cairo-lang-plugins 2.1.2

Cairo core plugin implementations.
Documentation
//! > Test expansion of generate_trait with one generic parameter.

//! > test_runner_name
test_expand_plugin

//! > cairo_code
#[generate_trait]
impl SomeImpl<T> of SomeTrait<T> {
    fn by_val(self: T) -> T {
        self
    }
    fn by_snap(self: @T) -> T {
        self
    }
    fn by_ref(ref a: T) {
    }
    fn with_mut(mut a: usize) {
        a += 1;
    }
    fn multi_val(ref a: T, b: T, c: @T) {
    }
    fn with_generics<V>(ref a: V, b: Box<T>, c: Box<V>) -> Box<(T, V)> {
        box::into_box((box::unbox(b), box::unbox(c)))
    }
    fn with_nopanic(self: T) -> T nopanic {
        self
    }
    fn with_implicits(self: T) -> T implicits (RangeCheck) {
        self
    }
}

//! > generated_cairo_code
#[generate_trait]
impl SomeImpl<T> of SomeTrait<T> {
    fn by_val(self: T) -> T {
        self
    }
    fn by_snap(self: @T) -> T {
        self
    }
    fn by_ref(ref a: T) {
    }
    fn with_mut(mut a: usize) {
        a += 1;
    }
    fn multi_val(ref a: T, b: T, c: @T) {
    }
    fn with_generics<V>(ref a: V, b: Box<T>, c: Box<V>) -> Box<(T, V)> {
        box::into_box((box::unbox(b), box::unbox(c)))
    }
    fn with_nopanic(self: T) -> T nopanic {
        self
    }
    fn with_implicits(self: T) -> T implicits (RangeCheck) {
        self
    }
}
trait SomeTrait<T>  {
    fn by_val(self: T)-> T ;

    fn by_snap(self: @T)-> T ;

    fn by_ref(ref a: T);

    fn with_mut(a: usize);

    fn multi_val(ref a: T, b: T, c: @T);

    fn with_generics<V>(ref a: V, b: Box<T>, c: Box<V>)-> Box<(T, V)> ;

    fn with_nopanic(self: T)-> T nopanic ;

    fn with_implicits(self: T)-> T implicits (RangeCheck) ;
}

//! > expected_diagnostics

//! > ==========================================================================

//! > Test expansion of generate_trait with one generic parameter and custom attributes.

//! > test_runner_name
test_expand_plugin

//! > cairo_code
#[generate_trait(trait_attrs(some(attr), other(attr2)))]
impl OtherImpl<T> of TraitWithAttrs<T>;

//! > generated_cairo_code
#[generate_trait(trait_attrs(some(attr), other(attr2)))]
impl OtherImpl<T> of TraitWithAttrs<T>;
#[some(attr)]
#[other(attr2)]
trait TraitWithAttrs<T>  {
}

//! > expected_diagnostics

//! > ==========================================================================

//! > Test expansion of generate_trait without generic parameters.

//! > test_runner_name
test_expand_plugin

//! > cairo_code
#[generate_trait]
impl SomeImpl of SomeTrait {
    fn foo() {}
    fn bar(a: usize) -> usize {
        a
    }
}

//! > generated_cairo_code
#[generate_trait]
impl SomeImpl of SomeTrait {
    fn foo() {}
    fn bar(a: usize) -> usize {
        a
    }
}
trait SomeTrait {
    fn foo();

    fn bar(a: usize)-> usize ;
}

//! > expected_diagnostics

//! > ==========================================================================

//! > Test diagnostics of generate_trait.

//! > test_runner_name
test_expand_plugin

//! > cairo_code
#[generate_trait]
impl ImplWithBadTrait<T> of Some::Path::To::Trait<T> {
}

#[generate_trait]
impl ImplNotMAtchingGenerics<T> of TraitNotMAtchingGenerics<S> {
}

#[generate_trait]
impl ImplWithUnsupportedAttributeArg<T> of OtherTrait<T> {
}

//! > expected_diagnostics
error: Generated trait must have a single element path.
 --> dummy_file.cairo:2:29
impl ImplWithBadTrait<T> of Some::Path::To::Trait<T> {
                            ^**********************^

error: Generated trait must have generic args matching the impl's generic params.
 --> dummy_file.cairo:6:36
impl ImplNotMAtchingGenerics<T> of TraitNotMAtchingGenerics<S> {
                                   ^*************************^

//! > generated_cairo_code
#[generate_trait]
impl ImplWithBadTrait<T> of Some::Path::To::Trait<T> {
}


#[generate_trait]
impl ImplNotMAtchingGenerics<T> of TraitNotMAtchingGenerics<S> {
}

trait TraitNotMAtchingGenerics<T>  {
}


#[generate_trait]
impl ImplWithUnsupportedAttributeArg<T> of OtherTrait<T> {
}
trait OtherTrait<T>  {
}