File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
src/doc/unstable-book/src/language-features Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -54,4 +54,25 @@ if let [b] = &mut *v {
5454assert_eq! (v , [Box :: new (Some (2 ))]);
5555```
5656
57+ Additionally, when ` deref_patterns ` is enabled, string literal patterns may be written where ` str `
58+ is expected. Likewise, byte string literal patterns may be written where ` [u8] ` or ` [u8; _] ` is
59+ expected. This lets them be used in ` deref!(_) ` patterns:
60+
61+ ``` rust
62+ # #![feature(deref_patterns)]
63+ # #![allow(incomplete_features)]
64+ match (" test" . to_string (), b " test" . to_vec ()) {
65+ (deref! (" test" ), deref! (b " test" )) => {}
66+ _ => panic! (),
67+ }
68+
69+ // Matching on slices and arrays using literals is possible elsewhere as well:
70+ match * " test" {
71+ " test" => {}
72+ _ => panic! (),
73+ }
74+ ```
75+
76+ Implicit deref pattern syntax is not yet supported for string or byte string literals.
77+
5778[ smart pointers in the standard library ] : https://doc.rust-lang.org/std/ops/trait.DerefPure.html#implementors
You can’t perform that action at this time.
0 commit comments