# Struct std::sync::Weak [−] [src]

    pub struct Weak<T> where T: ?Sized {
        // some fields omitted
    }

A weak pointer to an `Arc`.

Weak pointers will not keep the data inside of the `Arc` alive, and can be used to break cycles between `Arc` pointers.

## Methods

### `impl<T> Weak<T> where T: ?Sized`

#### `fn upgrade(&self) -> Option<Arc<T>>`

Upgrades a weak reference to a strong reference.

Upgrades the `Weak<T>` reference to an `Arc<T>`, if possible.

Returns `None` if there were no strong references and the data was destroyed.

# Examples

fn main() { use std::sync::Arc; let five = Arc::new(5); let weak_five = Arc::downgrade(&five); let strong_five: Option<Arc<_>> = weak_five.upgrade(); }

    use std::sync::Arc;

    let five = Arc::new(5);

    let weak_five = Arc::downgrade(&five);

    let strong_five: Option<Arc<_>> = weak_five.upgrade();

### `impl<T> Weak<T>`

#### `fn new() -> Weak<T>`

Unstable (`downgraded_weak` #30425)

: recently added

Constructs a new `Weak<T>` without an accompanying instance of T.

This allocates memory for T, but does not initialize it. Calling Weak<T>::upgrade() on the return value always gives None.

# Examples

#![feature(downgraded_weak)] fn main() { use std::sync::Weak; let empty: Weak<i64> = Weak::new(); }

    #![feature(downgraded_weak)]

    use std::sync::Weak;

    let empty: Weak<i64> = Weak::new();

## Trait Implementations

### `impl<T> Send for Weak<T> where T: Send + Sync + ?Sized`

### `impl<T> Sync for Weak<T> where T: Send + Sync + ?Sized`

### `impl<T, U> CoerceUnsized<Weak<U>> for Weak<T> where U: ?Sized, T: Unsize<U> + ?Sized`

### `impl<T> Debug for Weak<T> where T: Debug + ?Sized`

#### `fn fmt(&self, f: &mut Formatter) -> Result<(), Error>`

### `impl<T> Clone for Weak<T> where T: ?Sized`

#### `fn clone(&self) -> Weak<T>`

#### `fn clone_from(&mut self, source: &Self)`

### `impl<T> Drop for Weak<T> where T: ?Sized`

#### `fn drop(&mut self)`

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize`)