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
/// Macro to try to evaluate an expression as a pattern and extract its fields.
/// # Examples:
/// ```
/// use cairo_lang_utils::try_extract_matches;
///
/// #[derive(Debug, Clone, Copy)]
/// struct Point {
/// x: u32,
/// y: u32,
/// }
/// #[derive(Debug)]
/// enum MyEnum {
/// Point(Point),
/// Value(u32),
/// }
/// let p = MyEnum::Point(Point { x: 3, y: 5 });
/// if let Some(Point { x, y: _ }) = try_extract_matches!(p, MyEnum::Point) {
/// assert_eq!(x, 3);
/// }
/// ```
/// Macro to verify an expression matches a pattern and extract its fields.
/// # Examples:
/// ```
/// use cairo_lang_utils::extract_matches;
///
/// #[derive(Debug, Clone, Copy)]
/// struct Point {
/// x: u32,
/// y: u32,
/// }
/// #[derive(Debug)]
/// enum MyEnum {
/// Point(Point),
/// Value(u32),
/// }
/// let p = MyEnum::Point(Point { x: 3, y: 5 });
/// let Point { x, y: _ } = extract_matches!(p, MyEnum::Point);
/// assert_eq!(x, 3);
///
/// // Would panic with 'Variant extract failed: `Point(Point { x: 3, y: 5 })` is not of variant `MyEnum::Value`:
/// // Expected a point!'
/// // let _value = extract_matches!(p, MyEnum::Value, "Expected a point!");
/// ```