Skip to content

Commit eaa8ab1

Browse files
committed
update unstable book to mention string/bytestring typing
1 parent 0a92d84 commit eaa8ab1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/doc/unstable-book/src/language-features/deref-patterns.md

+21
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,25 @@ if let [b] = &mut *v {
5454
assert_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

0 commit comments

Comments
 (0)