pub struct ThreadSafeOptionType<T> { /* private fields */ }
Expand description
Generic thread safe Option
Implementations§
Source§impl<T> ThreadSafeOptionType<T>
impl<T> ThreadSafeOptionType<T>
Sourcepub fn new(option_to_wrap: Option<T>) -> Self
pub fn new(option_to_wrap: Option<T>) -> Self
Creates a new ThreadSafeOptionType for a specific type
§Example
Basic usage:
use fbp::fbp_threadsafe_wrapper::*;
let safe_bool: ThreadSafeOptionType<bool> = ThreadSafeOptionType::new(None);
Sourcepub fn create(op_arc: Arc<Mutex<Option<T>>>) -> Self
pub fn create(op_arc: Arc<Mutex<Option<T>>>) -> Self
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);
Sourcepub fn get_arc(&self) -> Arc<Mutex<Option<T>>>
pub fn get_arc(&self) -> Arc<Mutex<Option<T>>>
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();
Sourcepub fn set_arc(&mut self, new_arc: Arc<Mutex<Option<T>>>)
pub fn set_arc(&mut self, new_arc: Arc<Mutex<Option<T>>>)
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);
Sourcepub fn get_option(&self) -> MutexGuard<'_, Option<T>>
pub fn get_option(&self) -> MutexGuard<'_, Option<T>>
Change the underlying option in a MutexGuard
NOTE: MutexGuard<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");
}
Sourcepub fn set_option(&mut self, new_option: Option<T>)
pub fn set_option(&mut self, new_option: Option<T>)
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);
Sourcepub fn is_none(&self) -> bool
pub fn is_none(&self) -> bool
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());
Trait Implementations§
Source§impl<T> Clone for ThreadSafeOptionType<T>
impl<T> Clone for ThreadSafeOptionType<T>
Source§impl<T: Debug> Debug for ThreadSafeOptionType<T>
impl<T: Debug> Debug for ThreadSafeOptionType<T>
Auto Trait Implementations§
impl<T> Freeze for ThreadSafeOptionType<T>
impl<T> RefUnwindSafe for ThreadSafeOptionType<T>
impl<T> Send for ThreadSafeOptionType<T>where
T: Send,
impl<T> Sync for ThreadSafeOptionType<T>where
T: Send,
impl<T> Unpin for ThreadSafeOptionType<T>
impl<T> UnwindSafe for ThreadSafeOptionType<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more