alexcrichton / alexcrichton/scoped-tls
Add panic-less `try_with` method
Open
- Dominant language
- Rust
- Stars
- 65
- Forks
- 10
- PR merge metrics
- No merged PRs in 30d
Description
Currently `with` method always panics if nothing was stored before. To avoid this it is required to call `is_set` before `with`.
What I'd like to see is panic-less `try_with` method:
```rust
pub fn try_with(&'static self, f: F) -> R
where
F: FnOnce(Option<&T>) -> R,
{
let val_ptr = self.inner.with(|c| c.get());
let val = when (val_ptr.is_null()) {
true => None,
false => Some(unsafe { &*(val_ptr as *const T) }),
};
f(val)
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.