@@ -52,7 +52,8 @@ impl KVConfig {
5252 placement=None ,
5353 limit_markers=None ,
5454 ) ) ]
55- pub fn __new__ (
55+ #[ must_use]
56+ pub const fn __new__ (
5657 bucket : String ,
5758 description : Option < String > ,
5859 max_value_size : Option < i32 > ,
@@ -100,29 +101,32 @@ impl TryFrom<KVConfig> for async_nats::jetstream::kv::Config {
100101 history : value. history . unwrap_or_default ( ) ,
101102 max_age : value
102103 . max_age
103- . map ( |val| std:: time:: Duration :: from_secs_f32 ( val ) )
104+ . map ( std:: time:: Duration :: from_secs_f32)
104105 . unwrap_or_default ( ) ,
105106 max_bytes : value. max_bytes . unwrap_or_default ( ) ,
106107 storage : value. storage . unwrap_or_default ( ) . into ( ) ,
107108 num_replicas : value. num_replicas . unwrap_or_default ( ) ,
108- republish : value. republish . map ( |r| r. into ( ) ) ,
109- mirror : value. mirror . map ( |m| m. try_into ( ) ) . transpose ( ) ?,
109+ republish : value. republish . map ( std:: convert:: Into :: into) ,
110+ mirror : value
111+ . mirror
112+ . map ( std:: convert:: TryInto :: try_into)
113+ . transpose ( ) ?,
110114 sources : value
111115 . sources
112116 . map ( |srcs| {
113117 // Collect the results of trying to convert each source, and if any conversion
114118 // fails, return the error
115119 srcs. into_iter ( )
116- . map ( |s| s . try_into ( ) )
120+ . map ( std :: convert :: TryInto :: try_into)
117121 . collect :: < Result < Vec < _ > , _ > > ( )
118122 } )
119123 // Now it's a Option<Result<_>>,
120124 // we transpose it to Result<Option<_>>
121125 . transpose ( ) ?,
122126 mirror_direct : value. mirror_direct . unwrap_or_default ( ) ,
123127 compression : value. compression . unwrap_or_default ( ) ,
124- placement : value. placement . map ( |p| p . into ( ) ) ,
125- limit_markers : value. limit_markers . map ( |val| Duration :: from_secs_f32 ( val ) ) ,
128+ placement : value. placement . map ( std :: convert :: Into :: into) ,
129+ limit_markers : value. limit_markers . map ( Duration :: from_secs_f32) ,
126130 } )
127131 }
128132}
@@ -133,6 +137,7 @@ pub struct KeyValue {
133137}
134138
135139impl KeyValue {
140+ #[ must_use]
136141 pub fn new ( store : async_nats:: jetstream:: kv:: Store ) -> Self {
137142 Self {
138143 store : Arc :: new ( RwLock :: new ( store) ) ,
@@ -145,27 +150,25 @@ impl KeyValue {
145150 pub fn get < ' py > ( & self , py : Python < ' py > , key : String ) -> NatsrpyResult < Bound < ' py , PyAny > > {
146151 let store = self . store . clone ( ) ;
147152 natsrpy_future ( py, async move {
148- let kv = store. read ( ) . await ;
149- if let Some ( data) = kv. get ( key) . await ? {
150- let pybytes = Python :: attach ( move |gil| PyBytes :: new ( gil, & data) . unbind ( ) ) ;
151- Ok ( Some ( pybytes) )
152- } else {
153- Ok ( None )
154- }
153+ Ok ( store
154+ . read ( )
155+ . await
156+ . get ( key)
157+ . await ?
158+ . map ( |data| Python :: attach ( move |gil| PyBytes :: new ( gil, & data) . unbind ( ) ) ) )
155159 } )
156160 }
157161
158162 pub fn put < ' py > (
159163 & self ,
160164 py : Python < ' py > ,
161165 key : String ,
162- value : Bound < ' py , PyBytes > ,
166+ value : & Bound < ' py , PyBytes > ,
163167 ) -> NatsrpyResult < Bound < ' py , PyAny > > {
164168 let store = self . store . clone ( ) ;
165169 let data = bytes:: Bytes :: copy_from_slice ( value. as_bytes ( ) ) ;
166170 natsrpy_future ( py, async move {
167- let kv = store. read ( ) . await ;
168- let status = kv. put ( key, data) . await ?;
171+ let status = store. read ( ) . await . put ( key, data) . await ?;
169172 Ok ( status)
170173 } )
171174 }
0 commit comments