Struct godot::obj::NotUniqueError
pub struct NotUniqueError { /* private fields */ }
Expand description
Error stemming from the non-uniqueness of the Gd
instance.
Keeping track of the uniqueness of references can be crucial in many applications, especially if we want to ensure
that the passed Gd
reference will be possessed by only one different object instance or function in its lifetime.
Only applicable to GodotClass
objects that inherit from RefCounted
. To check the
uniqueness, call the check()
associated method.
§Example
use godot::prelude::*;
use godot::obj::NotUniqueError;
let shared = RefCounted::new_gd();
let cloned = shared.clone();
let result = NotUniqueError::check(shared);
assert!(result.is_err());
if let Err(error) = result {
assert_eq!(error.get_reference_count(), 2)
}
Implementations§
§impl NotUniqueError
impl NotUniqueError
pub fn check<T>(rc: Gd<T>) -> Result<Gd<T>, NotUniqueError>where
T: Inherits<RefCounted>,
pub fn check<T>(rc: Gd<T>) -> Result<Gd<T>, NotUniqueError>where
T: Inherits<RefCounted>,
check Gd
reference uniqueness.
Checks the Gd
of the GodotClass
that inherits from RefCounted
if it is an unique reference to the object.
§Example
use godot::prelude::*;
use godot::obj::NotUniqueError;
let unique = RefCounted::new_gd();
assert!(NotUniqueError::check(unique).is_ok());
let shared = RefCounted::new_gd();
let cloned = shared.clone();
assert!(NotUniqueError::check(shared).is_err());
assert!(NotUniqueError::check(cloned).is_err());
pub fn get_reference_count(&self) -> i32
pub fn get_reference_count(&self) -> i32
Get the detected reference count
Trait Implementations§
§impl Debug for NotUniqueError
impl Debug for NotUniqueError
§impl Display for NotUniqueError
impl Display for NotUniqueError
§impl Error for NotUniqueError
impl Error for NotUniqueError
1.30.0 · source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
The lower-level source of this error, if any. Read more
1.0.0 · source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Auto Trait Implementations§
impl Freeze for NotUniqueError
impl RefUnwindSafe for NotUniqueError
impl Send for NotUniqueError
impl Sync for NotUniqueError
impl Unpin for NotUniqueError
impl UnwindSafe for NotUniqueError
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