Skip to content

Commit dffdade

Browse files
committed
Fix the doctest in the README.md.
See rust-lang/rust#134221 for more details.
1 parent ca8e811 commit dffdade

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

trait_cast_rs/README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ Note: No modifications on the *target* traits are necessary. Which allows you to
3939
## Example
4040

4141
```rust
42-
#![feature(
43-
ptr_metadata, //
44-
)]
42+
#![feature(ptr_metadata, min_specialization)]
4543
use trait_cast_rs::{
4644
make_trait_castable, TraitcastableAny, TraitcastableAnyInfra, TraitcastableAnyInfraExt,
4745
};
@@ -52,7 +50,7 @@ trait Print {
5250
}
5351
impl Print for Source {
5452
fn print(&self) {
55-
println!("{}", self.0)
53+
println!("{}", self.0);
5654
}
5755
}
5856

trait_cast_rs/src/test.rs

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::make_trait_castable_decl;
1+
use crate::{make_trait_castable_decl, TraitcastableAny, TraitcastableAnyInfra};
2+
use alloc::boxed::Box;
3+
use trait_cast_impl_rs::make_trait_castable;
24

35
const fn _test_empty_trait_cast_targets() {
46
struct Woof {}
@@ -7,3 +9,25 @@ const fn _test_empty_trait_cast_targets() {
79
Woof => (),
810
}
911
}
12+
13+
make_trait_castable_decl! {
14+
Source => (Print)
15+
}
16+
17+
struct Source(i32);
18+
trait Print {
19+
fn print(&self) -> i32;
20+
}
21+
impl Print for Source {
22+
fn print(&self) -> i32 {
23+
self.0
24+
}
25+
}
26+
27+
#[test]
28+
fn test_trait_castable() {
29+
let source = Box::new(Source(5));
30+
let castable: Box<dyn TraitcastableAny> = source;
31+
let x: &dyn Print = castable.downcast_ref().unwrap();
32+
x.print();
33+
}

trait_cast_rs/src/trait_cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub trait TraitcastableAnyInfraExt<Target: ?Sized + 'static>: Sized {
148148
#[cfg(feature = "min_specialization")]
149149
// Safety:
150150
// Since `traitcast_targets` returns nothing this is always safe.
151-
// `find_traitcast_target` has the default implementations
151+
// `find_traitcast_target` has the default implementations.
152152
unsafe impl<T: 'static> TraitcastableAny for T {
153153
default fn traitcast_targets(&self) -> &[TraitcastTarget] {
154154
&[]

0 commit comments

Comments
 (0)