Skip to content

Releases: yvt/try_match-rs

0.4.2

25 Jul 16:10
@yvt yvt
Compare
Choose a tag to compare
  • Add a new macro match_or_default! that returns Default::default() on match failure

    assert_eq!(match_or_default!(Var1(42), Var1(x)), 42);
    assert_eq!(match_or_default!(Var0,     Var1(x)), 0);

0.4.1

18 May 03:42
@yvt yvt
Compare
Choose a tag to compare
  • (inner 0.5.1) Fix field shorthands in struct patterns causing a syntax error

    error: expected `,`
       --> tests/test.rs:201:16
        |
    201 |     assert_eq!(match_ok!(A { x: 42 }, A { x }), Some(42));
        |                ^^^^^^^^^^^^^^^^^^^^^^^-^^^^^^^
        |                                       |
        |                                       while parsing the fields for this pattern
    
  • Fix struct expressions causing a syntax error when used as a scrutinee expression

    error: struct literals are not allowed here
       --> tests/test.rs:181:26
        |
    181 |     assert_eq!(match_ok!(A { x: 42 }, A { x }), Some(42));
        |                          ^^^^^^^^^^^
    

0.4.0

05 May 12:24
@yvt yvt
Compare
Choose a tag to compare
  • Breaking: Use heuristics based on the standard naming conventions to distinguish constant patterns from variable bindings (#6)

    let _: Result<i32, i32> = try_match!(42, zero); // binding
    
    const ZERO: i32 = 0;
    let _: Result<(), i32>  = try_match!(42, ZERO); // constant pattern
  • Support partial application (#3)

    let _:                  Result<i32, _> = try_match!(Var1(42), Var1(x));
    let _: fn(Enum<i32>) -> Result<i32, _> = try_match!(        , Var1(x));
  • Add a new macro match_ok! that returns Option instead of Result (#8)

    let array = [Var1(42), Var2, Var1(10)];
    let filtered: Vec<_> = array
        .iter()
        .filter_map(match_ok!(, &Var1(_0) if _0 > 20))
        .collect();
    
    assert_eq!(filtered, [42]);
  • Add a new macro unwrap_match! that panics on failure (#5)

    assert_eq!(unwrap_match!(Var1(42), Var1(x) if x > 20, "oops"), 42);
  • Suppress clippy::just_underscores_and_digits in implicit tuple mapping (#2)

  • Handle parentheses and inline const patterns (#7)

  • Allow trailing commas in macro invocations (#9)

  • Increase MSRV to 1.56.0

0.3.0

03 May 10:21
@yvt yvt
Compare
Choose a tag to compare
  • Breaking: Change the syntax to be compatible with core::matches! and other similar macros

    assert_eq!(try_match!(Var1(x) = Var1(42)), Ok(42)); // old
    assert_eq!(try_match!(Var1(42), Var1(x)), Ok(42));  // new
  • Support if guards

    assert_eq!(try_match!(Var1(42), Var1(x) if x < 20), Err(Var1(42)));
  • Remove std from the default Cargo feature set

  • Remove proc-macro-hack dependency

  • Increase MSRV to 1.45

0.2.3

03 May 10:21
@yvt yvt
Compare
Choose a tag to compare
  • Allow multiple arms in a top-level pattern (pat1 | pat2 | ...)
  • Implement Debug on a generated anonymous type regardless of cfg(feature = "std")
  • Produce a pretty compile error when implicit mapping is used without a necessary Cargo feature

0.2.2

30 May 05:09
@yvt yvt
Compare
Choose a tag to compare
  • try_match_inner 0.1.1: Support proc-macro-error 1.x
  • Work-around various issues with nightly-2020-05-30

0.2.1

30 May 05:08
@yvt yvt
Compare
Choose a tag to compare
  • Omit proc-macro-hack when implicit_map is disabled

0.2.0

30 May 05:07
@yvt yvt
Compare
Choose a tag to compare
  • Breaking:Fix input being evaluated twice