Skip to content

Commit a9777b3

Browse files
authored
Rollup merge of #65046 - sinkuu:cell_reorder, r=shepmaster
Make `Cell::new` method come first in documentation Methods to create a thing usually comes first in `std` documentation, and `Cell` has been an exception. Also, `T: Copy` specialized methods should not be on top of the page. (This had led me to miss that most of its methods are not bounded by `Copy`...)
2 parents 4737095 + 3754691 commit a9777b3

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

src/libcore/cell.rs

+46-46
Original file line numberDiff line numberDiff line change
@@ -229,52 +229,6 @@ pub struct Cell<T: ?Sized> {
229229
value: UnsafeCell<T>,
230230
}
231231

232-
impl<T:Copy> Cell<T> {
233-
/// Returns a copy of the contained value.
234-
///
235-
/// # Examples
236-
///
237-
/// ```
238-
/// use std::cell::Cell;
239-
///
240-
/// let c = Cell::new(5);
241-
///
242-
/// let five = c.get();
243-
/// ```
244-
#[inline]
245-
#[stable(feature = "rust1", since = "1.0.0")]
246-
pub fn get(&self) -> T {
247-
unsafe{ *self.value.get() }
248-
}
249-
250-
/// Updates the contained value using a function and returns the new value.
251-
///
252-
/// # Examples
253-
///
254-
/// ```
255-
/// #![feature(cell_update)]
256-
///
257-
/// use std::cell::Cell;
258-
///
259-
/// let c = Cell::new(5);
260-
/// let new = c.update(|x| x + 1);
261-
///
262-
/// assert_eq!(new, 6);
263-
/// assert_eq!(c.get(), 6);
264-
/// ```
265-
#[inline]
266-
#[unstable(feature = "cell_update", issue = "50186")]
267-
pub fn update<F>(&self, f: F) -> T
268-
where
269-
F: FnOnce(T) -> T,
270-
{
271-
let old = self.get();
272-
let new = f(old);
273-
self.set(new);
274-
new
275-
}
276-
}
277-
278232
#[stable(feature = "rust1", since = "1.0.0")]
279233
unsafe impl<T: ?Sized> Send for Cell<T> where T: Send {}
280234

@@ -448,6 +402,52 @@ impl<T> Cell<T> {
448402
}
449403
}
450404

405+
impl<T:Copy> Cell<T> {
406+
/// Returns a copy of the contained value.
407+
///
408+
/// # Examples
409+
///
410+
/// ```
411+
/// use std::cell::Cell;
412+
///
413+
/// let c = Cell::new(5);
414+
///
415+
/// let five = c.get();
416+
/// ```
417+
#[inline]
418+
#[stable(feature = "rust1", since = "1.0.0")]
419+
pub fn get(&self) -> T {
420+
unsafe{ *self.value.get() }
421+
}
422+
423+
/// Updates the contained value using a function and returns the new value.
424+
///
425+
/// # Examples
426+
///
427+
/// ```
428+
/// #![feature(cell_update)]
429+
///
430+
/// use std::cell::Cell;
431+
///
432+
/// let c = Cell::new(5);
433+
/// let new = c.update(|x| x + 1);
434+
///
435+
/// assert_eq!(new, 6);
436+
/// assert_eq!(c.get(), 6);
437+
/// ```
438+
#[inline]
439+
#[unstable(feature = "cell_update", issue = "50186")]
440+
pub fn update<F>(&self, f: F) -> T
441+
where
442+
F: FnOnce(T) -> T,
443+
{
444+
let old = self.get();
445+
let new = f(old);
446+
self.set(new);
447+
new
448+
}
449+
}
450+
451451
impl<T: ?Sized> Cell<T> {
452452
/// Returns a raw pointer to the underlying data in this cell.
453453
///

0 commit comments

Comments
 (0)