Struct std::mem::Snapshot

Overview

Methods

fn shared(self) -> u64

The number of shared references to the value.

Examples

use std::mem::snapshot;

let v = [1, 2, 3];

let s = snapshot(v)?;
assert_eq!(s.shared(), 0);

// An iterators takes a shared reference to the collection being iterated over.
let it = v.iter();

let s = snapshot(v)?;
assert_eq!(s.shared(), 1);
drop(it);

let s = snapshot(v)?;
assert_eq!(s.shared(), 0);

Test if the snapshot indicates that the value is exclusively held.

Examples

use std::mem::snapshot;

let v = [1, 2, 3];

let s = snapshot(v)?;
assert_eq!(s.shared(), 0);
assert!(!s.is_exclusive());
assert!(s.is_readable());
assert!(s.is_writable());

// Assign to a separate variable since the compiler will notice that `v` is moved.
let u = v;

// Move the value into a closure, causing the original reference to become exclusively held.
let closure = move || {
  v
};

let s = snapshot(u)?;
assert!(s.is_exclusive());
assert!(!s.is_readable());
assert!(!s.is_writable());

Test if the snapshot indicates that the value is readable.

Examples

use std::mem::snapshot;

let v = [1, 2, 3];

let s = snapshot(v)?;
assert_eq!(s.shared(), 0);
assert!(!s.is_exclusive());
assert!(s.is_readable());
assert!(s.is_writable());

// Assign to a separate variable since the compiler will notice that `v` is moved.
let u = v;

// Move the value into a closure, causing the original reference to become exclusively held.
let closure = move || {
  v
};

let s = snapshot(u)?;
assert!(s.is_exclusive());
assert!(!s.is_readable());
assert!(!s.is_writable());

Test if the snapshot indicates that the value is writable.

Examples

use std::mem::snapshot;

let v = [1, 2, 3];

let s = snapshot(v)?;
assert_eq!(s.shared(), 0);
assert!(!s.is_exclusive());
assert!(s.is_readable());
assert!(s.is_writable());

// Assign to a separate variable since the compiler will notice that `v` is moved.
let u = v;

// Move the value into a closure, causing the original reference to become exclusively held.
let closure = move || {
  v
};

let s = snapshot(u)?;
assert!(s.is_exclusive());
assert!(!s.is_readable());
assert!(!s.is_writable());

Protocols

protocol DISPLAY_FMT
format!("{}", value)

Allows the value to be display printed.

protocol DEBUG_FMT
format!("{:?}", value)

Allows the value to be debug printed.