@@ -6,11 +6,11 @@ use crate::{
66 CBLCollection_GetIndexNames , CBLCollection_CreateArrayIndex , CBLArrayIndexConfiguration ,
77 CBLQueryIndex , CBLQueryIndex_Name , CBLQueryIndex_Collection , CBLCollection_GetIndex ,
88 } ,
9- error:: { Result , failure} ,
10- slice:: { from_str, from_c_str} ,
9+ error:: { Error , Result , failure} ,
10+ slice:: { from_str, from_c_str, Slice } ,
1111 QueryLanguage , Array ,
1212 collection:: Collection ,
13- check_error, retain,
13+ check_error, retain, CouchbaseLiteError ,
1414} ;
1515use std:: ffi:: CString ;
1616
@@ -44,8 +44,8 @@ impl ValueIndexConfiguration {
4444#[ derive( Debug ) ]
4545pub struct ArrayIndexConfiguration {
4646 cbl_ref : CBLArrayIndexConfiguration ,
47- _path : CString ,
48- _expressions : CString ,
47+ _path : Slice < CString > ,
48+ _expressions : Slice < CString > ,
4949}
5050
5151impl CblRef for ArrayIndexConfiguration {
@@ -67,19 +67,24 @@ impl ArrayIndexConfiguration {
6767 indexed. The expressions could be specified in a JSON Array or in N1QL syntax
6868 using comma delimiter. If the array specified by the path contains scalar values,
6969 the expressions should be left unset or set to null. */
70- pub fn new ( query_language : QueryLanguage , path : & str , expressions : & str ) -> Self {
71- let path_c = CString :: new ( path) . unwrap ( ) ;
72- let expressions_c = CString :: new ( expressions) . unwrap ( ) ;
70+ pub fn new ( query_language : QueryLanguage , path : & str , expressions : & str ) -> Result < Self > {
71+ let path_c = CString :: new ( path)
72+ . map_err ( |_| Error :: cbl_error ( CouchbaseLiteError :: InvalidParameter ) ) ?;
73+ let expressions_c = CString :: new ( expressions)
74+ . map_err ( |_| Error :: cbl_error ( CouchbaseLiteError :: InvalidParameter ) ) ?;
7375
74- Self {
76+ let path_s = from_c_str ( path_c, path. len ( ) ) ;
77+ let expressions_s = from_c_str ( expressions_c, expressions. len ( ) ) ;
78+
79+ Ok ( Self {
7580 cbl_ref : CBLArrayIndexConfiguration {
7681 expressionLanguage : query_language as u32 ,
77- path : from_c_str ( & path_c , path . len ( ) ) . get_ref ( ) ,
78- expressions : from_c_str ( & expressions_c , expressions . len ( ) ) . get_ref ( ) ,
82+ path : path_s . get_ref ( ) ,
83+ expressions : expressions_s . get_ref ( ) ,
7984 } ,
80- _path : path_c ,
81- _expressions : expressions_c ,
82- }
85+ _path : path_s ,
86+ _expressions : expressions_s ,
87+ } )
8388 }
8489}
8590
0 commit comments