cairo-lang-plugins 2.5.0-dev.1

Cairo core plugin implementations.
Documentation
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
//! > Test expansion of derive.

//! > test_runner_name
test_expand_plugin(expect_diagnostics: false)

//! > cairo_code
#[derive(Copy, Debug, Default, Drop, Hash)]
struct A{}

#[derive(Copy, Debug, Default, Drop, Hash)]
struct B{}

#[derive(Clone, Debug, Default, Destruct, Hash, PanicDestruct, PartialEq, Serde)]
struct TwoMemberStruct {
    a: A,
    b: B,
}

#[derive(Copy, Debug, Destruct, PanicDestruct, Default, Hash)]
struct GenericStruct<T> {
    a: T,
}


trait SomeTrait<T, U> {}

#[derive(Drop, Debug, Clone, PartialEq, Serde, Hash)]
struct TwoMemberGenericStruct<T, U, impl USomeTrait: SomeTrait<U, T>> {
    a: T,
    b: U,
}

#[derive(Clone, Debug, Default, Destruct, Hash, PanicDestruct, PartialEq, Serde)]
enum TwoVariantEnum {
    First: A,
    #[default]
    Second: B,
}

#[derive(Copy, Drop)]
extern type ExternType;

//! > expanded_cairo_code
#[derive(Copy, Debug, Default, Drop, Hash)]
struct A{}

#[derive(Copy, Debug, Default, Drop, Hash)]
struct B{}

#[derive(Clone, Debug, Default, Destruct, Hash, PanicDestruct, PartialEq, Serde)]
struct TwoMemberStruct {
    a: A,
    b: B,
}

#[derive(Copy, Debug, Destruct, PanicDestruct, Default, Hash)]
struct GenericStruct<T> {
    a: T,
}


trait SomeTrait<T, U> {}

#[derive(Drop, Debug, Clone, PartialEq, Serde, Hash)]
struct TwoMemberGenericStruct<T, U, impl USomeTrait: SomeTrait<U, T>> {
    a: T,
    b: U,
}

#[derive(Clone, Debug, Default, Destruct, Hash, PanicDestruct, PartialEq, Serde)]
enum TwoVariantEnum {
    First: A,
    #[default]
    Second: B,
}

#[derive(Copy, Drop)]
extern type ExternType;
impl ACopy of core::traits::Copy::<A>;
impl ADebug of core::fmt::Debug::<A> {
    fn fmt(self: @A, ref f: core::fmt::Formatter) -> core::result::Result::<(), core::fmt::Error> {
        write!(f, "A {{")?;
        write!(f, " }}")
    }
}
impl ADefault of core::traits::Default::<A> {
    fn default() -> A {
        A {
            
        }
    }
}
impl ADrop of core::traits::Drop::<A>;
impl AHash<
    __State,
    impl __SHashState: core::hash::HashStateTrait<__State>,
    +Drop<__State>
> of core::hash::Hash<A, __State, __SHashState> {
    #[inline(always)]
    fn update_state(state: __State, value: A) -> __State {
        
        state
    }
}
impl BCopy of core::traits::Copy::<B>;
impl BDebug of core::fmt::Debug::<B> {
    fn fmt(self: @B, ref f: core::fmt::Formatter) -> core::result::Result::<(), core::fmt::Error> {
        write!(f, "B {{")?;
        write!(f, " }}")
    }
}
impl BDefault of core::traits::Default::<B> {
    fn default() -> B {
        B {
            
        }
    }
}
impl BDrop of core::traits::Drop::<B>;
impl BHash<
    __State,
    impl __SHashState: core::hash::HashStateTrait<__State>,
    +Drop<__State>
> of core::hash::Hash<B, __State, __SHashState> {
    #[inline(always)]
    fn update_state(state: __State, value: B) -> __State {
        
        state
    }
}
impl TwoMemberStructClone of core::clone::Clone::<TwoMemberStruct> {
    fn clone(self: @TwoMemberStruct) -> TwoMemberStruct {
        TwoMemberStruct {
            a: core::clone::Clone::clone(self.a),
            b: core::clone::Clone::clone(self.b),
        }
    }
}
impl TwoMemberStructDebug of core::fmt::Debug::<TwoMemberStruct> {
    fn fmt(self: @TwoMemberStruct, ref f: core::fmt::Formatter) -> core::result::Result::<(), core::fmt::Error> {
        write!(f, "TwoMemberStruct {{")?;
        write!(f, " a: ")?;
        core::fmt::Debug::fmt(self.a, ref f)?;
        write!(f, ",")?;
        write!(f, " b: ")?;
        core::fmt::Debug::fmt(self.b, ref f)?;
        write!(f, " }}")
    }
}
impl TwoMemberStructDefault of core::traits::Default::<TwoMemberStruct> {
    fn default() -> TwoMemberStruct {
        TwoMemberStruct {
            a: core::traits::Default::default(),
            b: core::traits::Default::default(),
        }
    }
}
impl TwoMemberStructDestruct of core::traits::Destruct::<TwoMemberStruct> {
    fn destruct(self: TwoMemberStruct) nopanic {
        let TwoMemberStruct { a, b } = self;
        core::traits::Destruct::destruct(a);
        core::traits::Destruct::destruct(b);
    }
}
impl TwoMemberStructHash<
    __State,
    impl __SHashState: core::hash::HashStateTrait<__State>,
    +Drop<__State>
> of core::hash::Hash<TwoMemberStruct, __State, __SHashState> {
    #[inline(always)]
    fn update_state(state: __State, value: TwoMemberStruct) -> __State {
        let state = core::hash::Hash::update_state(state, value.a);
        let state = core::hash::Hash::update_state(state, value.b);
        state
    }
}
impl TwoMemberStructPanicDestruct of core::traits::PanicDestruct::<TwoMemberStruct> {
    fn panic_destruct(self: TwoMemberStruct, ref panic: Panic) nopanic {
        let TwoMemberStruct { a, b } = self;
        core::traits::PanicDestruct::panic_destruct(a, ref panic);
        core::traits::PanicDestruct::panic_destruct(b, ref panic);
    }
}
impl TwoMemberStructPartialEq of core::traits::PartialEq::<TwoMemberStruct> {
    fn eq(lhs: @TwoMemberStruct, rhs: @TwoMemberStruct) -> bool {
        lhs.a == rhs.a && lhs.b == rhs.b
    }
    #[inline(always)]
    fn ne(lhs: @TwoMemberStruct, rhs: @TwoMemberStruct) -> bool {
        !(lhs == rhs)
    }
}
impl TwoMemberStructSerde of core::serde::Serde::<TwoMemberStruct> {
    fn serialize(self: @TwoMemberStruct, ref output: core::array::Array<felt252>) {
        core::serde::Serde::serialize(self.a, ref output);
        core::serde::Serde::serialize(self.b, ref output)
    }
    fn deserialize(ref serialized: core::array::Span<felt252>) -> core::option::Option<TwoMemberStruct> {
        core::option::Option::Some(TwoMemberStruct {
            a: core::serde::Serde::deserialize(ref serialized)?,
            b: core::serde::Serde::deserialize(ref serialized)?,
        })
    }
}
impl GenericStructCopy<T, +core::traits::Copy<T>> of core::traits::Copy::<GenericStruct<T>>;
impl GenericStructDebug<T, +core::fmt::Debug<T>> of core::fmt::Debug::<GenericStruct<T>> {
    fn fmt(self: @GenericStruct<T>, ref f: core::fmt::Formatter) -> core::result::Result::<(), core::fmt::Error> {
        write!(f, "GenericStruct {{")?;
        write!(f, " a: ")?;
        core::fmt::Debug::fmt(self.a, ref f)?;
        write!(f, " }}")
    }
}
impl GenericStructDestruct<T, +core::traits::Destruct<T>> of core::traits::Destruct::<GenericStruct<T>> {
    fn destruct(self: GenericStruct<T>) nopanic {
        let GenericStruct { a } = self;
        core::traits::Destruct::destruct(a);
    }
}
impl GenericStructPanicDestruct<T, +core::traits::PanicDestruct<T>> of core::traits::PanicDestruct::<GenericStruct<T>> {
    fn panic_destruct(self: GenericStruct<T>, ref panic: Panic) nopanic {
        let GenericStruct { a } = self;
        core::traits::PanicDestruct::panic_destruct(a, ref panic);
    }
}
impl GenericStructDefault<T, +core::traits::Default<T>, +core::traits::Destruct<T>> of core::traits::Default::<GenericStruct<T>> {
    fn default() -> GenericStruct<T> {
        GenericStruct {
            a: core::traits::Default::default(),
        }
    }
}
impl GenericStructHash<
    __State,
    impl __SHashState: core::hash::HashStateTrait<__State>,
    +Drop<__State>,
    T, +core::hash::Hash<T, __State, __SHashState>, +Drop<T>
> of core::hash::Hash<GenericStruct<T>, __State, __SHashState> {
    #[inline(always)]
    fn update_state(state: __State, value: GenericStruct<T>) -> __State {
        let state = core::hash::Hash::update_state(state, value.a);
        state
    }
}
impl TwoMemberGenericStructDrop<T, U, impl USomeTrait: SomeTrait<U, T>, +core::traits::Drop<T>, +core::traits::Drop<U>> of core::traits::Drop::<TwoMemberGenericStruct<T, U, USomeTrait>>;
impl TwoMemberGenericStructDebug<T, U, impl USomeTrait: SomeTrait<U, T>, +core::fmt::Debug<T>, +core::fmt::Debug<U>> of core::fmt::Debug::<TwoMemberGenericStruct<T, U, USomeTrait>> {
    fn fmt(self: @TwoMemberGenericStruct<T, U, USomeTrait>, ref f: core::fmt::Formatter) -> core::result::Result::<(), core::fmt::Error> {
        write!(f, "TwoMemberGenericStruct {{")?;
        write!(f, " a: ")?;
        core::fmt::Debug::fmt(self.a, ref f)?;
        write!(f, ",")?;
        write!(f, " b: ")?;
        core::fmt::Debug::fmt(self.b, ref f)?;
        write!(f, " }}")
    }
}
impl TwoMemberGenericStructClone<T, U, impl USomeTrait: SomeTrait<U, T>, +core::clone::Clone<T>, +Destruct<T>, +core::clone::Clone<U>, +Destruct<U>> of core::clone::Clone::<TwoMemberGenericStruct<T, U, USomeTrait>> {
    fn clone(self: @TwoMemberGenericStruct<T, U, USomeTrait>) -> TwoMemberGenericStruct<T, U, USomeTrait> {
        TwoMemberGenericStruct {
            a: core::clone::Clone::clone(self.a),
            b: core::clone::Clone::clone(self.b),
        }
    }
}
impl TwoMemberGenericStructPartialEq<T, U, impl USomeTrait: SomeTrait<U, T>, +core::traits::PartialEq<T>, +core::traits::PartialEq<U>> of core::traits::PartialEq::<TwoMemberGenericStruct<T, U, USomeTrait>> {
    fn eq(lhs: @TwoMemberGenericStruct<T, U, USomeTrait>, rhs: @TwoMemberGenericStruct<T, U, USomeTrait>) -> bool {
        lhs.a == rhs.a && lhs.b == rhs.b
    }
    #[inline(always)]
    fn ne(lhs: @TwoMemberGenericStruct<T, U, USomeTrait>, rhs: @TwoMemberGenericStruct<T, U, USomeTrait>) -> bool {
        !(lhs == rhs)
    }
}
impl TwoMemberGenericStructSerde<T, U, impl USomeTrait: SomeTrait<U, T>, +core::serde::Serde<T>, +core::traits::Destruct<T>, +core::serde::Serde<U>, +core::traits::Destruct<U>> of core::serde::Serde::<TwoMemberGenericStruct<T, U, USomeTrait>> {
    fn serialize(self: @TwoMemberGenericStruct<T, U, USomeTrait>, ref output: core::array::Array<felt252>) {
        core::serde::Serde::serialize(self.a, ref output);
        core::serde::Serde::serialize(self.b, ref output)
    }
    fn deserialize(ref serialized: core::array::Span<felt252>) -> core::option::Option<TwoMemberGenericStruct<T, U, USomeTrait>> {
        core::option::Option::Some(TwoMemberGenericStruct {
            a: core::serde::Serde::deserialize(ref serialized)?,
            b: core::serde::Serde::deserialize(ref serialized)?,
        })
    }
}
impl TwoMemberGenericStructHash<
    __State,
    impl __SHashState: core::hash::HashStateTrait<__State>,
    +Drop<__State>,
    T, U, impl USomeTrait: SomeTrait<U, T>, +core::hash::Hash<T, __State, __SHashState>, +Drop<T>, +core::hash::Hash<U, __State, __SHashState>, +Drop<U>
> of core::hash::Hash<TwoMemberGenericStruct<T, U, USomeTrait>, __State, __SHashState> {
    #[inline(always)]
    fn update_state(state: __State, value: TwoMemberGenericStruct<T, U, USomeTrait>) -> __State {
        let state = core::hash::Hash::update_state(state, value.a);
        let state = core::hash::Hash::update_state(state, value.b);
        state
    }
}
impl TwoVariantEnumClone of core::clone::Clone::<TwoVariantEnum> {
    fn clone(self: @TwoVariantEnum) -> TwoVariantEnum {
        match self {
            TwoVariantEnum::First(x) => TwoVariantEnum::First(core::clone::Clone::clone(x)),
            TwoVariantEnum::Second(x) => TwoVariantEnum::Second(core::clone::Clone::clone(x)),
        }
    }
}
impl TwoVariantEnumDebug of core::fmt::Debug::<TwoVariantEnum> {
    fn fmt(self: @TwoVariantEnum, ref f: core::fmt::Formatter) -> core::result::Result::<(), core::fmt::Error> {
        match self {
            TwoVariantEnum::First(x) => {
                write!(f, "TwoVariantEnum::First(")?;
                core::fmt::Debug::fmt(x, ref f)?;
                write!(f, ")")
            },

            TwoVariantEnum::Second(x) => {
                write!(f, "TwoVariantEnum::Second(")?;
                core::fmt::Debug::fmt(x, ref f)?;
                write!(f, ")")
            },

        }
    }
}
impl TwoVariantEnumDefault of core::traits::Default::<TwoVariantEnum> {
    fn default() -> TwoVariantEnum {
        TwoVariantEnum::Second(core::traits::Default::default())
    }
}
impl TwoVariantEnumDestruct of core::traits::Destruct::<TwoVariantEnum> {
    fn destruct(self: TwoVariantEnum) nopanic {
        match self {
            TwoVariantEnum::First(x) => core::traits::Destruct::destruct(x),
            TwoVariantEnum::Second(x) => core::traits::Destruct::destruct(x),
        }
    }
}
impl TwoVariantEnumHash<
    __State,
    impl __SHashState: core::hash::HashStateTrait<__State>,
    +Drop<__State>
> of core::hash::Hash<TwoVariantEnum, __State, __SHashState> {
    #[inline(always)]
    fn update_state(state: __State, value: TwoVariantEnum) -> __State {
        match value {
            TwoVariantEnum::First(x) => {
                let state = core::hash::Hash::update_state(state, 0);
                core::hash::Hash::update_state(state, x)
            },
            TwoVariantEnum::Second(x) => {
                let state = core::hash::Hash::update_state(state, 1);
                core::hash::Hash::update_state(state, x)
            },
        }
    }
}
impl TwoVariantEnumPanicDestruct of core::traits::PanicDestruct::<TwoVariantEnum> {
    fn panic_destruct(self: TwoVariantEnum, ref panic: Panic) nopanic {
        match self {
            TwoVariantEnum::First(x) => core::traits::PanicDestruct::panic_destruct(x, ref panic),
            TwoVariantEnum::Second(x) => core::traits::PanicDestruct::panic_destruct(x, ref panic),
        }
    }
}
impl TwoVariantEnumPartialEq of core::traits::PartialEq::<TwoVariantEnum> {
    fn eq(lhs: @TwoVariantEnum, rhs: @TwoVariantEnum) -> bool {
        match lhs {
            TwoVariantEnum::First(x) => match rhs {
                TwoVariantEnum::First(y) => x == y,
                TwoVariantEnum::Second(_y) => false,
            },
            TwoVariantEnum::Second(x) => match rhs {
                TwoVariantEnum::First(_y) => false,
                TwoVariantEnum::Second(y) => x == y,
            },
        }
    }
    #[inline(always)]
    fn ne(lhs: @TwoVariantEnum, rhs: @TwoVariantEnum) -> bool {
        !(lhs == rhs)
    }
}
impl TwoVariantEnumSerde of core::serde::Serde::<TwoVariantEnum> {
    fn serialize(self: @TwoVariantEnum, ref output: core::array::Array<felt252>) {
        match self {
            TwoVariantEnum::First(x) => { core::serde::Serde::serialize(@0, ref output); core::serde::Serde::serialize(x, ref output); },
            TwoVariantEnum::Second(x) => { core::serde::Serde::serialize(@1, ref output); core::serde::Serde::serialize(x, ref output); },
        }
    }
    fn deserialize(ref serialized: core::array::Span<felt252>) -> core::option::Option<TwoVariantEnum> {
        let idx: felt252 = core::serde::Serde::deserialize(ref serialized)?;
        core::option::Option::Some(
            if idx == 0 { TwoVariantEnum::First(core::serde::Serde::deserialize(ref serialized)?) }
            else if idx == 1 { TwoVariantEnum::Second(core::serde::Serde::deserialize(ref serialized)?) }
            else { return core::option::Option::None; }
        )
    }
}
impl ExternTypeCopy of core::traits::Copy::<ExternType>;
impl ExternTypeDrop of core::traits::Drop::<ExternType>;

//! > expected_diagnostics

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

//! > Test diagnostics of derive.

//! > test_runner_name
test_expand_plugin(expect_diagnostics: true)

//! > cairo_code
#[derive()]
struct EmptyArgs{}

#[derive(1)]
struct NotPath{}

#[derive(Unsupported)]
struct UnsupportedTrait{}

#[derive(long::path)]
struct NonSimplePath{}

#[derive(Clone)]
extern type NotClonable;

#[derive(Default)]
enum NoDefaultValue {
    First,
    Second,
}

#[derive(Default)]
enum TooManyDefaultValues {
    #[default]
    First,
    #[default]
    Second,
}

//! > expanded_cairo_code
#[derive()]
struct EmptyArgs{}

#[derive(1)]
struct NotPath{}

#[derive(Unsupported)]
struct UnsupportedTrait{}

#[derive(long::path)]
struct NonSimplePath{}

#[derive(Clone)]
extern type NotClonable;

#[derive(Default)]
enum NoDefaultValue {
    First,
    Second,
}

#[derive(Default)]
enum TooManyDefaultValues {
    #[default]
    First,
    #[default]
    Second,
}
impl TooManyDefaultValuesDefault of core::traits::Default::<TooManyDefaultValues> {
    fn default() -> TooManyDefaultValues {
        TooManyDefaultValues::First(core::traits::Default::default())
    }
}

//! > expected_diagnostics
error: Expected args.
 --> test_src/lib.cairo:1:9
#[derive()]
        ^^

error: Expected path.
 --> test_src/lib.cairo:4:10
#[derive(1)]
         ^

error: Unsupported trait for derive for extern types.
 --> test_src/lib.cairo:13:10
#[derive(Clone)]
         ^***^

error: derive `Default` for enum only supported with a default variant.
 --> test_src/lib.cairo:16:10
#[derive(Default)]
         ^*****^

error: Multiple variants annotated with `#[default]`
 --> test_src/lib.cairo:26:5
    #[default]
    ^********^