Skip to content

Commit

Permalink
Change name LateStatic::is_assigned to LateStatic::has_value
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard-W committed Feb 5, 2019
1 parent 84f01ff commit 7c82456
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ impl<T> LateStatic<T> {

/// Invalidate the late static by removing its inner value.
pub unsafe fn clear(instance: &LateStatic<T>) {
if !Self::is_assigned(instance) {
if !Self::has_value(instance) {
panic!("Tried to clear a late static without a value");
}
let option: &mut Option<T> = &mut *instance.val.get();
*option = None;
}

/// Whether a value is assigned to this LateStatic.
pub unsafe fn is_assigned(instance: &LateStatic<T>) -> bool {
pub unsafe fn has_value(instance: &LateStatic<T>) -> bool {
let option: &Option<T> = &*instance.val.get();
option.is_some()
}
Expand Down Expand Up @@ -103,9 +103,9 @@ mod tests {
#[test]
fn assign_once() {
unsafe {
assert!(!LateStatic::is_assigned(&ASSIGN_ONCE_TEST));
assert!(!LateStatic::has_value(&ASSIGN_ONCE_TEST));
LateStatic::assign(&ASSIGN_ONCE_TEST, 42);
assert!(LateStatic::is_assigned(&ASSIGN_ONCE_TEST));
assert!(LateStatic::has_value(&ASSIGN_ONCE_TEST));
}
}

Expand Down Expand Up @@ -160,7 +160,7 @@ mod tests {
LateStatic::assign(&CLEAR_TEST, Foo { value: 42 });
assert_eq!(CLEAR_TEST.value, 42);
LateStatic::clear(&CLEAR_TEST);
assert!(!LateStatic::is_assigned(&CLEAR_TEST));
assert!(!LateStatic::has_value(&CLEAR_TEST));
}
}

Expand Down

0 comments on commit 7c82456

Please sign in to comment.