File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -639,4 +639,37 @@ mod test {
639
639
// value-breakage test:
640
640
assert_eq ! ( results[ 0 ] , 5029875928683246316 ) ;
641
641
}
642
+
643
+ #[ test]
644
+ fn dyn_trait_conversion ( ) {
645
+ // Illustrates the need for `+ ?Sized` bound in `impl<R: RngCore> TryRngCore for R`.
646
+
647
+ // A method in another crate taking a fallible RNG
648
+ fn third_party_api ( _rng : & mut ( impl TryRngCore + ?Sized ) ) -> bool {
649
+ true
650
+ }
651
+
652
+ // A method in our crate requiring an infallible RNG
653
+ fn my_api ( rng : & mut dyn RngCore ) -> bool {
654
+ // We want to call the method above
655
+ third_party_api ( rng)
656
+ }
657
+
658
+ // A stub RNG.
659
+ struct SomeRng ;
660
+
661
+ impl RngCore for SomeRng {
662
+ fn next_u32 ( & mut self ) -> u32 {
663
+ unimplemented ! ( )
664
+ }
665
+ fn next_u64 ( & mut self ) -> u64 {
666
+ unimplemented ! ( )
667
+ }
668
+ fn fill_bytes ( & mut self , _: & mut [ u8 ] ) {
669
+ unimplemented ! ( )
670
+ }
671
+ }
672
+
673
+ assert ! ( my_api( & mut SomeRng ) ) ;
674
+ }
642
675
}
You can’t perform that action at this time.
0 commit comments