create a way to hoist ownership to a different scope
This commit is contained in:
1 parent
49001c59d3
commit
dce418140a
4 files changed
+53
-6
No files matched your search
@@ -268,6 +268,15 @@ pub fn consume_context<T: 'static + Clone>() -> Option<T> {
|
||||
with_current_scope(|cx| cx.consume_context::<T>()).flatten()
|
||||
}
|
||||
|
||||
/// Consume context from the current scope
|
||||
pub fn consume_context_from_scope<T: 'static + Clone>(scope_id: ScopeId) -> Option<T> {
|
||||
with_runtime(|rt| {
|
||||
rt.get_context(scope_id)
|
||||
.and_then(|cx| cx.consume_context::<T>())
|
||||
})
|
||||
.flatten()
|
||||
}
|
||||
|
||||
/// Check if the current scope has a context
|
||||
pub fn has_context<T: 'static + Clone>() -> Option<T> {
|
||||
with_current_scope(|cx| cx.has_context::<T>()).flatten()
|
||||
@@ -278,6 +287,11 @@ pub fn provide_context<T: 'static + Clone>(value: T) -> Option<T> {
|
||||
with_current_scope(|cx| cx.provide_context(value))
|
||||
}
|
||||
|
||||
/// Provide context to the the given scope
|
||||
pub fn provide_context_to_scope<T: 'static + Clone>(scope_id: ScopeId, value: T) -> Option<T> {
|
||||
with_runtime(|rt| rt.get_context(scope_id).map(|cx| cx.provide_context(value))).flatten()
|
||||
}
|
||||
|
||||
/// Provide a context to the root scope
|
||||
pub fn provide_root_context<T: 'static + Clone>(value: T) -> Option<T> {
|
||||
with_current_scope(|cx| cx.provide_root_context(value))
|
||||
|
||||
Reference in new issue
Block a user