File tree 3 files changed +19
-1
lines changed
3 files changed +19
-1
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " tauri " : patch
3
+ ---
4
+
5
+ Add ` try_state ` API to the ` Manager ` trait.
Original file line number Diff line number Diff line change @@ -308,14 +308,22 @@ pub trait Manager<R: Runtime>: sealed::ManagerBase<R> {
308
308
self . manager ( ) . state ( ) . set ( state) ;
309
309
}
310
310
311
- /// Gets the managed state for the type `T`.
311
+ /// Gets the managed state for the type `T`. Panics if the type is not managed.
312
312
fn state < T > ( & self ) -> State < ' _ , T >
313
313
where
314
314
T : Send + Sync + ' static ,
315
315
{
316
316
self . manager ( ) . inner . state . get ( )
317
317
}
318
318
319
+ /// Tries to get the managed state for the type `T`. Returns `None` if the type is not managed.
320
+ fn try_state < T > ( & self ) -> Option < State < ' _ , T > >
321
+ where
322
+ T : Send + Sync + ' static ,
323
+ {
324
+ self . manager ( ) . inner . state . try_get ( )
325
+ }
326
+
319
327
/// Adds a plugin to the runtime.
320
328
fn plugin < P : plugin:: Plugin < R > + ' static > ( & self , plugin : P ) {
321
329
self
Original file line number Diff line number Diff line change @@ -60,4 +60,9 @@ impl StateManager {
60
60
pub fn get < T : Send + Sync + ' static > ( & self ) -> State < ' _ , T > {
61
61
State ( self . 0 . get ( ) )
62
62
}
63
+
64
+ /// Gets the state associated with the specified type.
65
+ pub fn try_get < T : Send + Sync + ' static > ( & self ) -> Option < State < ' _ , T > > {
66
+ self . 0 . try_get ( ) . map ( State )
67
+ }
63
68
}
You can’t perform that action at this time.
0 commit comments