Skip to content

Commit

Permalink
added Default impls
Browse files Browse the repository at this point in the history
  • Loading branch information
Billy-Sheppard committed May 3, 2024
1 parent 7f2fc33 commit 81b0331
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
22 changes: 22 additions & 0 deletions library/alloc/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,28 @@ impl From<&CStr> for Rc<CStr> {
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
impl Default for Arc<CStr> {
/// Creates an empty CStr inside an Arc
#[inline]
fn default() -> Self {
let c_str: &CStr = Default::default();
Arc::from(c_str)
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
impl Default for Rc<CStr> {
/// Creates an empty CStr inside an Rc
#[inline]
fn default() -> Self {
let c_str: &CStr = Default::default();
Rc::from(c_str)
}
}

#[cfg(not(test))]
#[stable(feature = "default_box_extra", since = "1.17.0")]
impl Default for Box<CStr> {
Expand Down
21 changes: 21 additions & 0 deletions library/alloc/src/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2226,6 +2226,27 @@ impl<T: Default> Default for Rc<T> {
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
impl Default for Rc<str> {
/// Creates an empty str inside an Rc
#[inline]
fn default() -> Self {
Rc::from("")
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Default for Rc<[T]> {
/// Creates an empty [T] inside an Rc
#[inline]
fn default() -> Self {
let arr: [T; 0] = [];
Rc::from(arr)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
trait RcEqIdent<T: ?Sized + PartialEq, A: Allocator> {
fn eq(&self, other: &Rc<T, A>) -> bool;
Expand Down
21 changes: 21 additions & 0 deletions library/alloc/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3298,6 +3298,27 @@ impl<T: Default> Default for Arc<T> {
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
impl Default for Arc<str> {
/// Creates an empty str inside an Arc
#[inline]
fn default() -> Self {
Arc::from("")
}
}

#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Default for Arc<[T]> {
/// Creates an empty [T] inside an Arc
#[inline]
fn default() -> Self {
let arr: [T; 0] = [];
Arc::from(arr)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized + Hash, A: Allocator> Hash for Arc<T, A> {
fn hash<H: Hasher>(&self, state: &mut H) {
Expand Down
20 changes: 20 additions & 0 deletions library/std/src/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,26 @@ impl Default for &OsStr {
}
}

#[stable(feature = "shared_from_slice2", since = "1.24.0")]
impl Default for Arc<OsStr> {
/// Creates an empty OsStr inside an Arc
#[inline]
fn default() -> Self {
let os_str: &OsStr = Default::default();
Arc::from(os_str)
}
}

#[stable(feature = "shared_from_slice2", since = "1.24.0")]
impl Default for Rc<OsStr> {
/// Creates an empty OsStr inside an Rc
#[inline]
fn default() -> Self {
let os_str: &OsStr = Default::default();
Rc::from(os_str)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl PartialEq for OsStr {
#[inline]
Expand Down

0 comments on commit 81b0331

Please sign in to comment.