We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 5fac191 commit ea48ffcCopy full SHA for ea48ffc
tests/ui/any/downcast_trait_mut.rs
@@ -0,0 +1,20 @@
1
+//@ run-pass
2
+#![feature(downcast_trait)]
3
+
4
+use std::fmt::{Error, Write};
5
6
+// Look ma, no `T: Write`
7
+fn downcast_mut_write<T: 'static>(t: &mut T, s: &str) -> Result<(), Error> {
8
+ match std::any::downcast_trait_mut::<_, dyn Write>(t) {
9
+ Some(w) => w.write_str(s),
10
+ None => Ok(())
11
+ }
12
+}
13
14
+// Test that downcasting to a mut dyn trait works as expected
15
+fn main() {
16
+ let mut buf = "Hello".to_string();
17
18
+ downcast_mut_write(&mut buf, " world!").unwrap();
19
+ assert_eq!(buf, "Hello world!");
20
0 commit comments