@@ -53,25 +53,25 @@ use crate::fmt;
53
53
/// # Examples
54
54
///
55
55
/// ```
56
- /// use std::cell::RefCell ;
56
+ /// use std::cell::Cell ;
57
57
/// use std::thread;
58
58
///
59
- /// thread_local!(static FOO: RefCell <u32> = RefCell ::new(1));
59
+ /// thread_local!(static FOO: Cell <u32> = Cell ::new(1));
60
60
///
61
- /// FOO.with_borrow(|v| assert_eq!(*v , 1) );
62
- /// FOO.with_borrow_mut(|v| *v = 2);
61
+ /// assert_eq!(FOO.get() , 1);
62
+ /// FOO.set( 2);
63
63
///
64
64
/// // each thread starts out with the initial value of 1
65
65
/// let t = thread::spawn(move|| {
66
- /// FOO.with_borrow(|v| assert_eq!(*v , 1) );
67
- /// FOO.with_borrow_mut(|v| *v = 3);
66
+ /// assert_eq!(FOO.get() , 1);
67
+ /// FOO.set( 3);
68
68
/// });
69
69
///
70
70
/// // wait for the thread to complete and bail out on panic
71
71
/// t.join().unwrap();
72
72
///
73
73
/// // we retain our original value of 2 despite the child thread
74
- /// FOO.with_borrow(|v| assert_eq!(*v , 2) );
74
+ /// assert_eq!(FOO.get() , 2);
75
75
/// ```
76
76
///
77
77
/// # Platform-specific behavior
@@ -141,15 +141,16 @@ impl<T: 'static> fmt::Debug for LocalKey<T> {
141
141
/// Publicity and attributes for each static are allowed. Example:
142
142
///
143
143
/// ```
144
- /// use std::cell::RefCell;
144
+ /// use std::cell::{Cell, RefCell};
145
+ ///
145
146
/// thread_local! {
146
- /// pub static FOO: RefCell <u32> = RefCell ::new(1);
147
+ /// pub static FOO: Cell <u32> = Cell ::new(1);
147
148
///
148
- /// static BAR: RefCell<f32> = RefCell::new(1.0);
149
+ /// static BAR: RefCell<Vec< f32>> = RefCell::new(vec![ 1.0, 2.0] );
149
150
/// }
150
151
///
151
- /// FOO.with_borrow(|v| assert_eq!(*v , 1) );
152
- /// BAR.with_borrow(|v| assert_eq!(*v, 1 .0));
152
+ /// assert_eq!(FOO.get() , 1);
153
+ /// BAR.with_borrow(|v| assert_eq!(v[1], 2 .0));
153
154
/// ```
154
155
///
155
156
/// Note that only shared references (`&T`) to the inner data may be obtained, so a
@@ -164,12 +165,13 @@ impl<T: 'static> fmt::Debug for LocalKey<T> {
164
165
/// track any additional state.
165
166
///
166
167
/// ```
167
- /// use std::cell::Cell;
168
+ /// use std::cell::RefCell;
169
+ ///
168
170
/// thread_local! {
169
- /// pub static FOO: Cell< u32> = const { Cell ::new(1 ) };
171
+ /// pub static FOO: RefCell<Vec< u32>> = const { RefCell ::new(Vec::new() ) };
170
172
/// }
171
173
///
172
- /// assert_eq!(FOO.get (), 1 );
174
+ /// FOO.with_borrow(|v| assert_eq!(v.len (), 0) );
173
175
/// ```
174
176
///
175
177
/// See [`LocalKey` documentation][`std::thread::LocalKey`] for more
0 commit comments