-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Documentation of what Default does for each type #36396
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -249,6 +249,7 @@ impl<'a, B: ?Sized> Default for Cow<'a, B> | |
where B: ToOwned, | ||
<B as ToOwned>::Owned: Default | ||
{ | ||
/// Creates a `Cow<'a, B>` pointer. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is wrong.
or something. |
||
fn default() -> Cow<'a, B> { | ||
Owned(<B as ToOwned>::Owned::default()) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -674,6 +674,7 @@ impl<'a, T: 'a + Ord + Copy> Extend<&'a T> for BTreeSet<T> { | |
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<T: Ord> Default for BTreeSet<T> { | ||
/// Creates a new `BTreeSet<T>`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should mention it is empty. |
||
fn default() -> BTreeSet<T> { | ||
BTreeSet::new() | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,7 @@ impl<T> Drop for VecDeque<T> { | |
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<T> Default for VecDeque<T> { | ||
/// Creates a `VecDeque<T>` with a constant initial capacity. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes little sense. Should probably say the same thing as |
||
#[inline] | ||
fn default() -> VecDeque<T> { | ||
VecDeque::new() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -698,6 +698,7 @@ fn expect_failed(msg: &str) -> ! { | |
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<T> Default for Option<T> { | ||
/// Creates an instance of None. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inline code for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could just say "Returns None" |
||
#[inline] | ||
fn default() -> Option<T> { None } | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -755,11 +755,13 @@ impl<T> ops::IndexMut<ops::RangeToInclusive<usize>> for [T] { | |
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<'a, T> Default for &'a [T] { | ||
/// Creates an empty Slice. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why slice is capitalized? |
||
fn default() -> &'a [T] { &[] } | ||
} | ||
|
||
#[stable(feature = "mut_slice_default", since = "1.5.0")] | ||
impl<'a, T> Default for &'a mut [T] { | ||
/// Creates a mutable empty Slice. | ||
fn default() -> &'a mut [T] { &mut [] } | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,6 +95,7 @@ pub struct AtomicBool { | |
#[cfg(target_has_atomic = "8")] | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl Default for AtomicBool { | ||
/// Creates an `AtomicBool` initialised as false. | ||
fn default() -> Self { | ||
Self::new(false) | ||
} | ||
|
@@ -117,6 +118,7 @@ pub struct AtomicPtr<T> { | |
#[cfg(target_has_atomic = "ptr")] | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<T> Default for AtomicPtr<T> { | ||
/// Creates an `AtomicPtr<T>` with an initial mutable null pointer. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mutability is irrelevant here.
might be better and more concise. |
||
fn default() -> AtomicPtr<T> { | ||
AtomicPtr::new(::ptr::null_mut()) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ struct MyHasher { | |
} | ||
|
||
impl Default for MyHasher { | ||
/// Constructs a `MyHasher` with initial value zero. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have nothing against adding documentation to tests, but is there any reason to do this? |
||
fn default() -> MyHasher { | ||
MyHasher { hash: 0 } | ||
} | ||
|
@@ -90,6 +91,7 @@ impl Hasher for CustomHasher { | |
} | ||
|
||
impl Default for CustomHasher { | ||
/// Constructs a `CustomHasher` with initial value zero. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these (this file) are just internal, so they don't strictly need docs. |
||
fn default() -> CustomHasher { | ||
CustomHasher { output: 0 } | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -84,6 +84,7 @@ pub enum ErrorOutputType { | |
} | ||
|
||
impl Default for ErrorOutputType { | ||
/// Creates an `HumanReadble`, initialised with `ColorConfig` enum type `Auto`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto, is there any reason to document default impls deep inside the rustc (i.e. something people reading the standard library documentation will never see)? |
||
fn default() -> ErrorOutputType { | ||
ErrorOutputType::HumanReadable(ColorConfig::Auto) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1218,6 +1218,7 @@ impl<K, V, S> Default for HashMap<K, V, S> | |
where K: Eq + Hash, | ||
S: BuildHasher + Default, | ||
{ | ||
/// Creates a `HashMap<K, V, S>`, with initial `Default` hasher. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can say the HashMap is empty, too. "Creates an empty `HashMap<K, V, S>", with the default value for the hasher" |
||
fn default() -> HashMap<K, V, S> { | ||
HashMap::with_hasher(Default::default()) | ||
} | ||
|
@@ -2026,6 +2027,7 @@ impl Hasher for DefaultHasher { | |
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl Default for RandomState { | ||
/// Constructs a new `RandomState`. | ||
#[inline] | ||
fn default() -> RandomState { | ||
RandomState::new() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -665,6 +665,7 @@ impl<T, S> Default for HashSet<T, S> | |
where T: Eq + Hash, | ||
S: BuildHasher + Default, | ||
{ | ||
/// Creates a `HashSet<T, S>` with initial `Default` hasher. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as hashmap. Not really a |
||
fn default() -> HashSet<T, S> { | ||
HashSet::with_hasher(Default::default()) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -339,6 +339,7 @@ impl<'a> Default for &'a CStr { | |
|
||
#[stable(feature = "cstr_default", since = "1.10.0")] | ||
impl Default for CString { | ||
/// Creates a new `CString`, by calling the `Default` of `CStr`, and then owns it. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should say the CString is empty, don't need to tell the implementation details |
||
fn default() -> CString { | ||
let a: &CStr = Default::default(); | ||
a.to_owned() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -154,6 +154,7 @@ impl<T> P<[T]> { | |
} | ||
|
||
impl<T> Default for P<[T]> { | ||
/// Creates a new `P`, with the `Default` value for T. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually creates a new empty |
||
fn default() -> P<[T]> { | ||
P::new() | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should have the same info as new, "Constructs a new
Weak<T>
without an accompanying instance of T."