-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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. | ||
|
||
| 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>`. | ||
|
||
| 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. | ||
|
||
| #[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. | ||
|
||
| #[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. | ||
|
||
| 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. | ||
|
||
| 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. | ||
|
||
| 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. | ||
|
||
| 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`. | ||
|
||
| 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. | ||
|
||
| 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. | ||
|
||
| 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. | ||
|
||
| 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. | ||
|
||
| 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."