about summary refs log tree commit diff
diff options
context:
space:
mode:
authordianne <diannes.gm@gmail.com>2025-04-18 21:49:40 -0700
committerdianne <diannes.gm@gmail.com>2025-04-22 13:19:20 -0700
commit4c7e866fc8e0d4025c3e9c97dde8688b4a0dd8f8 (patch)
tree853042ab91ba6dad7063767c6da2c6ea9cc12c3e
parent32503440cd40975ea6f0779e4abbaaca389582fe (diff)
downloadrust-4c7e866fc8e0d4025c3e9c97dde8688b4a0dd8f8.tar.gz
rust-4c7e866fc8e0d4025c3e9c97dde8688b4a0dd8f8.zip
update unstable book to mention string/bytestring typing
-rw-r--r--src/doc/unstable-book/src/language-features/deref-patterns.md21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/doc/unstable-book/src/language-features/deref-patterns.md b/src/doc/unstable-book/src/language-features/deref-patterns.md
index d0102a665b0..d0a64538e8c 100644
--- a/src/doc/unstable-book/src/language-features/deref-patterns.md
+++ b/src/doc/unstable-book/src/language-features/deref-patterns.md
@@ -54,4 +54,25 @@ if let [b] = &mut *v {
 assert_eq!(v, [Box::new(Some(2))]);
 ```
 
+Additionally, when `deref_patterns` is enabled, string literal patterns may be written where `str`
+is expected. Likewise, byte string literal patterns may be written where `[u8]` or `[u8; _]` is
+expected. This lets them be used in `deref!(_)` patterns:
+
+```rust
+# #![feature(deref_patterns)]
+# #![allow(incomplete_features)]
+match ("test".to_string(), b"test".to_vec()) {
+    (deref!("test"), deref!(b"test")) => {}
+    _ => panic!(),
+}
+
+// Matching on slices and arrays using literals is possible elsewhere as well:
+match *"test" {
+    "test" => {}
+    _ => panic!(),
+}
+```
+
+Implicit deref pattern syntax is not yet supported for string or byte string literals.
+
 [smart pointers in the standard library]: https://doc.rust-lang.org/std/ops/trait.DerefPure.html#implementors