@@ -65,15 +65,26 @@ let deref!(x) = Box::new(NoCopy) else { unreachable!() };
6565drop :: <NoCopy >(x );
6666```
6767
68- Additionally, when ` deref_patterns ` is enabled, string literal patterns may be written where ` str `
69- is expected. Likewise, byte string literal patterns may be written where ` [u8] ` or ` [u8; _] ` is
70- expected. This lets them be used in ` deref!(_) ` patterns:
68+ Additionally, ` deref_patterns ` implements changes to string and byte string literal patterns,
69+ allowing then to be used in deref patterns:
7170
7271``` rust
7372# #![feature(deref_patterns)]
7473# #![allow(incomplete_features)]
75- match (" test" . to_string (), b " test" . to_vec ()) {
76- (deref! (" test" ), deref! (b " test" )) => {}
74+ match (" test" . to_string (), Box :: from (" test" ), b " test" . to_vec ()) {
75+ (" test" , " test" , b " test" ) => {}
76+ _ => panic! (),
77+ }
78+
79+ // This works through multiple layers of reference and smart pointer:
80+ match (& Box :: new (& " test" . to_string ()), && & " test" ) {
81+ (" test" , " test" ) => {}
82+ _ => panic! (),
83+ }
84+
85+ // `deref!("...")` syntax may also be used:
86+ match " test" . to_string () {
87+ deref! (" test" ) => {}
7788 _ => panic! (),
7889}
7990
@@ -82,10 +93,16 @@ match *"test" {
8293 " test" => {}
8394 _ => panic! (),
8495}
96+ match * b " test" {
97+ b " test" => {}
98+ _ => panic! (),
99+ }
100+ match * (b " test" as & [u8 ]) {
101+ b " test" => {}
102+ _ => panic! (),
103+ }
85104```
86105
87- Implicit deref pattern syntax is not yet supported for string or byte string literals.
88-
89106[ `box_patterns` ] : ./box-patterns.md
90107[ `string_deref_patterns` ] : ./string-deref-patterns.md
91108[ smart pointers in the standard library ] : https://doc.rust-lang.org/std/ops/trait.DerefPure.html#implementors
0 commit comments