Skip to main content

try_to_clone

Macro try_to_clone 

Source
macro_rules! try_to_clone {
    (&$value:expr) => { ... };
    ($value:expr) => { ... };
}
Expand description

Tries to clone a value.

Accepts either value or &value.

Conversion order:

  1. Types implementing Copy are copied.
  2. Types implementing Clone are cloned.
  3. All other types return None.

ยงExamples

let value = String::from("hello");
assert_eq!(phlow::try_to_clone!(value.clone()), Some(String::from("hello")));
assert_eq!(phlow::try_to_clone!(&value), Some(String::from("hello")));