|
29 | 29 | //! Nil,
|
30 | 30 | //! }
|
31 | 31 | //!
|
32 |
| -//! fn main() { |
33 |
| -//! let list: List<i32> = List::Cons(1, Box::new(List::Cons(2, Box::new(List::Nil)))); |
34 |
| -//! println!("{:?}", list); |
35 |
| -//! } |
| 32 | +//! let list: List<i32> = List::Cons(1, Box::new(List::Cons(2, Box::new(List::Nil)))); |
| 33 | +//! println!("{:?}", list); |
36 | 34 | //! ```
|
37 | 35 | //!
|
38 | 36 | //! This will print `Cons(1, Cons(2, Nil))`.
|
@@ -375,14 +373,12 @@ impl<T: ?Sized> Box<T> {
|
375 | 373 | /// ```
|
376 | 374 | /// #![feature(box_into_raw_non_null)]
|
377 | 375 | ///
|
378 |
| - /// fn main() { |
379 |
| - /// let x = Box::new(5); |
380 |
| - /// let ptr = Box::into_raw_non_null(x); |
| 376 | + /// let x = Box::new(5); |
| 377 | + /// let ptr = Box::into_raw_non_null(x); |
381 | 378 | ///
|
382 |
| - /// // Clean up the memory by converting the NonNull pointer back |
383 |
| - /// // into a Box and letting the Box be dropped. |
384 |
| - /// let x = unsafe { Box::from_raw(ptr.as_ptr()) }; |
385 |
| - /// } |
| 379 | + /// // Clean up the memory by converting the NonNull pointer back |
| 380 | + /// // into a Box and letting the Box be dropped. |
| 381 | + /// let x = unsafe { Box::from_raw(ptr.as_ptr()) }; |
386 | 382 | /// ```
|
387 | 383 | #[unstable(feature = "box_into_raw_non_null", issue = "47336")]
|
388 | 384 | #[inline]
|
@@ -428,23 +424,19 @@ impl<T: ?Sized> Box<T> {
|
428 | 424 | /// Simple usage:
|
429 | 425 | ///
|
430 | 426 | /// ```
|
431 |
| - /// fn main() { |
432 |
| - /// let x = Box::new(41); |
433 |
| - /// let static_ref: &'static mut usize = Box::leak(x); |
434 |
| - /// *static_ref += 1; |
435 |
| - /// assert_eq!(*static_ref, 42); |
436 |
| - /// } |
| 427 | + /// let x = Box::new(41); |
| 428 | + /// let static_ref: &'static mut usize = Box::leak(x); |
| 429 | + /// *static_ref += 1; |
| 430 | + /// assert_eq!(*static_ref, 42); |
437 | 431 | /// ```
|
438 | 432 | ///
|
439 | 433 | /// Unsized data:
|
440 | 434 | ///
|
441 | 435 | /// ```
|
442 |
| - /// fn main() { |
443 |
| - /// let x = vec![1, 2, 3].into_boxed_slice(); |
444 |
| - /// let static_ref = Box::leak(x); |
445 |
| - /// static_ref[0] = 4; |
446 |
| - /// assert_eq!(*static_ref, [4, 2, 3]); |
447 |
| - /// } |
| 436 | + /// let x = vec![1, 2, 3].into_boxed_slice(); |
| 437 | + /// let static_ref = Box::leak(x); |
| 438 | + /// static_ref[0] = 4; |
| 439 | + /// assert_eq!(*static_ref, [4, 2, 3]); |
448 | 440 | /// ```
|
449 | 441 | #[stable(feature = "box_leak", since = "1.26.0")]
|
450 | 442 | #[inline]
|
@@ -780,11 +772,9 @@ impl Box<dyn Any> {
|
780 | 772 | /// }
|
781 | 773 | /// }
|
782 | 774 | ///
|
783 |
| - /// fn main() { |
784 |
| - /// let my_string = "Hello World".to_string(); |
785 |
| - /// print_if_string(Box::new(my_string)); |
786 |
| - /// print_if_string(Box::new(0i8)); |
787 |
| - /// } |
| 775 | + /// let my_string = "Hello World".to_string(); |
| 776 | + /// print_if_string(Box::new(my_string)); |
| 777 | + /// print_if_string(Box::new(0i8)); |
788 | 778 | /// ```
|
789 | 779 | pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<dyn Any>> {
|
790 | 780 | if self.is::<T>() {
|
@@ -814,11 +804,9 @@ impl Box<dyn Any + Send> {
|
814 | 804 | /// }
|
815 | 805 | /// }
|
816 | 806 | ///
|
817 |
| - /// fn main() { |
818 |
| - /// let my_string = "Hello World".to_string(); |
819 |
| - /// print_if_string(Box::new(my_string)); |
820 |
| - /// print_if_string(Box::new(0i8)); |
821 |
| - /// } |
| 807 | + /// let my_string = "Hello World".to_string(); |
| 808 | + /// print_if_string(Box::new(my_string)); |
| 809 | + /// print_if_string(Box::new(0i8)); |
822 | 810 | /// ```
|
823 | 811 | pub fn downcast<T: Any>(self) -> Result<Box<T>, Box<dyn Any + Send>> {
|
824 | 812 | <Box<dyn Any>>::downcast(self).map_err(|s| unsafe {
|
|
0 commit comments