@@ -6,11 +6,11 @@ use crate::{
6
6
CBLCollection_GetIndexNames , CBLCollection_CreateArrayIndex , CBLArrayIndexConfiguration ,
7
7
CBLQueryIndex , CBLQueryIndex_Name , CBLQueryIndex_Collection , CBLCollection_GetIndex ,
8
8
} ,
9
- error:: { Result , failure} ,
10
- slice:: { from_str, from_c_str} ,
9
+ error:: { Error , Result , failure} ,
10
+ slice:: { from_str, from_c_str, Slice } ,
11
11
QueryLanguage , Array ,
12
12
collection:: Collection ,
13
- check_error, retain,
13
+ check_error, retain, CouchbaseLiteError ,
14
14
} ;
15
15
use std:: ffi:: CString ;
16
16
@@ -44,8 +44,8 @@ impl ValueIndexConfiguration {
44
44
#[ derive( Debug ) ]
45
45
pub struct ArrayIndexConfiguration {
46
46
cbl_ref : CBLArrayIndexConfiguration ,
47
- _path : CString ,
48
- _expressions : CString ,
47
+ _path : Slice < CString > ,
48
+ _expressions : Slice < CString > ,
49
49
}
50
50
51
51
impl CblRef for ArrayIndexConfiguration {
@@ -67,19 +67,24 @@ impl ArrayIndexConfiguration {
67
67
indexed. The expressions could be specified in a JSON Array or in N1QL syntax
68
68
using comma delimiter. If the array specified by the path contains scalar values,
69
69
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 ) ) ?;
73
75
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 {
75
80
cbl_ref : CBLArrayIndexConfiguration {
76
81
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 ( ) ,
79
84
} ,
80
- _path : path_c ,
81
- _expressions : expressions_c ,
82
- }
85
+ _path : path_s ,
86
+ _expressions : expressions_s ,
87
+ } )
83
88
}
84
89
}
85
90
0 commit comments