File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree 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> {
308308 self . manager ( ) . state ( ) . set ( state) ;
309309 }
310310
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.
312312 fn state < T > ( & self ) -> State < ' _ , T >
313313 where
314314 T : Send + Sync + ' static ,
315315 {
316316 self . manager ( ) . inner . state . get ( )
317317 }
318318
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+
319327 /// Adds a plugin to the runtime.
320328 fn plugin < P : plugin:: Plugin < R > + ' static > ( & self , plugin : P ) {
321329 self
Original file line number Diff line number Diff line change @@ -60,4 +60,9 @@ impl StateManager {
6060 pub fn get < T : Send + Sync + ' static > ( & self ) -> State < ' _ , T > {
6161 State ( self . 0 . get ( ) )
6262 }
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+ }
6368}
You can’t perform that action at this time.
0 commit comments