Struct fbp::fbp_threadsafe_wrapper::ThreadSafeOptionType[][src]

pub struct ThreadSafeOptionType<T> { /* fields omitted */ }
Expand description

Generic thread safe Option

Implementations

Creates a new ThreadSafeOptionType for a specific type

Example

Basic usage:

use fbp::fbp_threadsafe_wrapper::*;

let safe_bool: ThreadSafeOptionType<bool> = ThreadSafeOptionType::new(None);

Create a new ThreadSafeOptionType from an Arc<Mutex<Option>>

Example

Basic usage:

use fbp::fbp_threadsafe_wrapper::*;
use std::sync::{Arc, Mutex, MutexGuard};

let an_arc = Arc::new(Mutex::new(Some(false)));

let safe_bool_option = ThreadSafeType::create(an_arc);

Return the underlying arc used by the ThreadSafeOptionType

Example

Basic usage:

use fbp::fbp_threadsafe_wrapper::*;
use std::sync::{Arc, Mutex, MutexGuard};

let safe_bool_option = ThreadSafeOptionType::new(Some(false));
let the_arc = safe_bool_option.get_arc();

Change the underlying arc used by the ThreadSafeOptionType

Example

Basic usage:

use fbp::fbp_threadsafe_wrapper::*;
use std::sync::{Arc, Mutex, MutexGuard};

let mut safe_bool_option = ThreadSafeOptionType::new(Some(false));
let new_arc = Arc::new(Mutex::new(Some(true)));
safe_bool_option.set_arc(new_arc);

Change the underlying option in a MutexGuard

NOTE: MutexGuard<Option> will dereference to the underlying Option

Example

Basic usage:

use fbp::fbp_threadsafe_wrapper::*;
use std::sync::{Arc, Mutex, MutexGuard};
use std::ops::Deref;

let mut safe_bool_option = ThreadSafeOptionType::new(Some(false));
let the_value = safe_bool_option.get_option();
if the_value.deref().unwrap() == true {
	println!("The value is true");
} else {
	println!("The value is false");
}

Replace the underlying option in a ThreadSafeOptionType with a new option

Example

Basic usage:

use fbp::fbp_threadsafe_wrapper::*;
use std::sync::{Arc, Mutex, MutexGuard};
use std::ops::{DerefMut, Deref};

let mut safe_bool_option = ThreadSafeOptionType::new(None);
let new_option = Some(true);
safe_bool_option.set_option(new_option);

Implement is_none for a ThreadSafeOptionType so that it works like a regular option

Example

Basic usage:

use fbp::fbp_threadsafe_wrapper::*;

let mut safe_bool_option: ThreadSafeOptionType<bool>  = ThreadSafeOptionType::new(None);
assert!(safe_bool_option.is_none());

Implement is_some for a ThreadSafeOptionType so that it works like a regular option

Example

Basic usage:

use fbp::fbp_threadsafe_wrapper::*;
let mut safe_bool_option = ThreadSafeOptionType::new(Some(true));
assert!(safe_bool_option.is_some());

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.