@@ -104,73 +104,69 @@ impl RConnection {
104104 match message {
105105 ConnectionsBackendRequest :: ListObjects ( ListObjectsParams { path } ) => {
106106 let tables = r_task ( || -> Result < _ , anyhow:: Error > {
107- unsafe {
108- let mut call = RFunction :: from ( ".ps.connection_list_objects" ) ;
109- call. add ( RObject :: from ( self . comm . comm_id . clone ( ) ) ) ;
110- for obj in path {
111- call. param ( obj. kind . as_str ( ) , obj. name ) ;
112- }
113- // returns a data.frame with columns name and type
114- let tables = call. call ( ) ?;
115-
116- let names = RFunction :: from ( "[[" )
117- . add ( tables. clone ( ) )
118- . add ( RObject :: from ( "name" ) )
119- . call ( ) ?;
120-
121- let types = RFunction :: from ( "[[" )
122- . add ( tables)
123- . add ( RObject :: from ( "type" ) )
124- . call ( ) ?;
125-
126- let resulting = RObject :: to :: < Vec < String > > ( names) ?
127- . iter ( )
128- . zip ( RObject :: to :: < Vec < String > > ( types) ?. iter ( ) )
129- . map ( |( name, kind) | ObjectSchema {
130- name : name. clone ( ) ,
131- kind : kind. clone ( ) ,
132- has_children : None ,
133- } )
134- . collect :: < Vec < _ > > ( ) ;
135-
136- Ok ( resulting)
107+ let mut call = RFunction :: from ( ".ps.connection_list_objects" ) ;
108+ call. add ( RObject :: from ( self . comm . comm_id . clone ( ) ) ) ;
109+ for obj in path {
110+ call. param ( obj. kind . as_str ( ) , obj. name ) ;
137111 }
112+ // returns a data.frame with columns name and type
113+ let tables = call. call ( ) ?;
114+
115+ let names = RFunction :: from ( "[[" )
116+ . add ( tables. clone ( ) )
117+ . add ( RObject :: from ( "name" ) )
118+ . call ( ) ?;
119+
120+ let types = RFunction :: from ( "[[" )
121+ . add ( tables)
122+ . add ( RObject :: from ( "type" ) )
123+ . call ( ) ?;
124+
125+ let resulting = RObject :: to :: < Vec < String > > ( names) ?
126+ . iter ( )
127+ . zip ( RObject :: to :: < Vec < String > > ( types) ?. iter ( ) )
128+ . map ( |( name, kind) | ObjectSchema {
129+ name : name. clone ( ) ,
130+ kind : kind. clone ( ) ,
131+ has_children : None ,
132+ } )
133+ . collect :: < Vec < _ > > ( ) ;
134+
135+ Ok ( resulting)
138136 } ) ?;
139137
140138 Ok ( ConnectionsBackendReply :: ListObjectsReply ( tables) )
141139 } ,
142140 ConnectionsBackendRequest :: ListFields ( ListFieldsParams { path } ) => {
143141 let fields = r_task ( || -> Result < _ , anyhow:: Error > {
144- unsafe {
145- let mut call = RFunction :: from ( ".ps.connection_list_fields" ) ;
146- call. add ( RObject :: from ( self . comm . comm_id . clone ( ) ) ) ;
147- for obj in path {
148- call. param ( obj. kind . as_str ( ) , obj. name ) ;
149- }
150- let fields = call. call ( ) ?;
151-
152- // for now we only need the name column
153- let names = RFunction :: from ( "[[" )
154- . add ( fields. clone ( ) )
155- . add ( RObject :: from ( "name" ) )
156- . call ( ) ?;
157-
158- let dtypes = RFunction :: from ( "[[" )
159- . add ( fields)
160- . add ( RObject :: from ( "type" ) )
161- . call ( ) ?;
162-
163- let resulting = RObject :: to :: < Vec < String > > ( names) ?
164- . iter ( )
165- . zip ( RObject :: to :: < Vec < String > > ( dtypes) ?. iter ( ) )
166- . map ( |( name, dtype) | FieldSchema {
167- name : name. clone ( ) ,
168- dtype : dtype. clone ( ) ,
169- } )
170- . collect :: < Vec < _ > > ( ) ;
171-
172- Ok ( resulting)
142+ let mut call = RFunction :: from ( ".ps.connection_list_fields" ) ;
143+ call. add ( RObject :: from ( self . comm . comm_id . clone ( ) ) ) ;
144+ for obj in path {
145+ call. param ( obj. kind . as_str ( ) , obj. name ) ;
173146 }
147+ let fields = call. call ( ) ?;
148+
149+ // for now we only need the name column
150+ let names = RFunction :: from ( "[[" )
151+ . add ( fields. clone ( ) )
152+ . add ( RObject :: from ( "name" ) )
153+ . call ( ) ?;
154+
155+ let dtypes = RFunction :: from ( "[[" )
156+ . add ( fields)
157+ . add ( RObject :: from ( "type" ) )
158+ . call ( ) ?;
159+
160+ let resulting = RObject :: to :: < Vec < String > > ( names) ?
161+ . iter ( )
162+ . zip ( RObject :: to :: < Vec < String > > ( dtypes) ?. iter ( ) )
163+ . map ( |( name, dtype) | FieldSchema {
164+ name : name. clone ( ) ,
165+ dtype : dtype. clone ( ) ,
166+ } )
167+ . collect :: < Vec < _ > > ( ) ;
168+
169+ Ok ( resulting)
174170 } ) ?;
175171
176172 Ok ( ConnectionsBackendReply :: ListFieldsReply ( fields) )
@@ -191,38 +187,34 @@ impl RConnection {
191187 ConnectionsBackendRequest :: GetIcon ( GetIconParams { path } ) => {
192188 // Calls back into R to get the icon.
193189 let icon_path = r_task ( || -> Result < _ , anyhow:: Error > {
194- unsafe {
195- let mut call = RFunction :: from ( ".ps.connection_icon" ) ;
196- call. add ( RObject :: from ( self . comm . comm_id . clone ( ) ) ) ;
197- for obj in path {
198- call. param ( obj. kind . as_str ( ) , obj. name ) ;
199- }
200-
201- let icon = call. call ( ) ?;
202-
203- if r_is_null ( * icon) {
204- // we'd rather use the option type but couldn't find a way to autogenerate RPC optionals
205- Ok ( "" . to_string ( ) )
206- } else {
207- Ok ( RObject :: to :: < String > ( icon) ?)
208- }
190+ let mut call = RFunction :: from ( ".ps.connection_icon" ) ;
191+ call. add ( RObject :: from ( self . comm . comm_id . clone ( ) ) ) ;
192+ for obj in path {
193+ call. param ( obj. kind . as_str ( ) , obj. name ) ;
194+ }
195+
196+ let icon = call. call ( ) ?;
197+
198+ if r_is_null ( * icon) {
199+ // we'd rather use the option type but couldn't find a way to autogenerate RPC optionals
200+ Ok ( "" . to_string ( ) )
201+ } else {
202+ Ok ( RObject :: to :: < String > ( icon) ?)
209203 }
210204 } ) ?;
211205 Ok ( ConnectionsBackendReply :: GetIconReply ( icon_path) )
212206 } ,
213207 ConnectionsBackendRequest :: ContainsData ( ContainsDataParams { path } ) => {
214208 // Calls back into R to check if the object contains data.
215209 let contains_data = r_task ( || -> Result < _ , anyhow:: Error > {
216- unsafe {
217- let mut contains_data_call: RFunction =
218- RFunction :: from ( ".ps.connection_contains_data" ) ;
219- contains_data_call. add ( RObject :: from ( self . comm . comm_id . clone ( ) ) ) ;
220- for obj in path {
221- contains_data_call. param ( obj. kind . as_str ( ) , obj. name ) ;
222- }
223- let contains_data = contains_data_call. call ( ) ?;
224- Ok ( RObject :: to :: < bool > ( contains_data) ?)
210+ let mut contains_data_call: RFunction =
211+ RFunction :: from ( ".ps.connection_contains_data" ) ;
212+ contains_data_call. add ( RObject :: from ( self . comm . comm_id . clone ( ) ) ) ;
213+ for obj in path {
214+ contains_data_call. param ( obj. kind . as_str ( ) , obj. name ) ;
225215 }
216+ let contains_data = contains_data_call. call ( ) ?;
217+ Ok ( RObject :: to :: < bool > ( contains_data) ?)
226218 } ) ?;
227219 Ok ( ConnectionsBackendReply :: ContainsDataReply ( contains_data) )
228220 } ,
@@ -255,12 +247,10 @@ impl RConnection {
255247 fn disconnect ( & self ) -> std:: result:: Result < bool , anyhow:: Error > {
256248 // Execute database side disconnect method.
257249 r_task ( || -> Result < bool , anyhow:: Error > {
258- unsafe {
259- let mut call = RFunction :: from ( ".ps.connection_close" ) ;
260- call. add ( RObject :: from ( self . comm . comm_id . clone ( ) ) ) ;
261- let closed = call. call ( ) ?;
262- Ok ( RObject :: to :: < bool > ( closed) ?)
263- }
250+ let mut call = RFunction :: from ( ".ps.connection_close" ) ;
251+ call. add ( RObject :: from ( self . comm . comm_id . clone ( ) ) ) ;
252+ let closed = call. call ( ) ?;
253+ Ok ( RObject :: to :: < bool > ( closed) ?)
264254 } )
265255 }
266256
0 commit comments