@@ -99,6 +99,12 @@ impl From<Vec<u8>> for BlobType {
99
99
}
100
100
}
101
101
102
+ impl < const COUNT : usize > From < & [ u8 ; COUNT ] > for BlobType {
103
+ fn from ( value : & [ u8 ; COUNT ] ) -> Self {
104
+ BlobType :: Blob ( value. to_vec ( ) )
105
+ }
106
+ }
107
+
102
108
#[ derive( Clone ) ]
103
109
pub struct AnalyticsEngineDataPoint {
104
110
indexes : Array ,
@@ -137,12 +143,12 @@ impl AnalyticsEngineDataPointBuilder {
137
143
/// use worker::AnalyticsEngineDataPointBuilder;
138
144
///
139
145
/// let data = AnalyticsEngineDataPointBuilder::new()
140
- /// .indexes(vec! ["index1"].as_slice() )
146
+ /// .indexes(["index1"])
141
147
/// .build();
142
148
/// ```
143
- pub fn indexes ( mut self , indexes : & [ & str ] ) -> Self {
149
+ pub fn indexes < ' index > ( mut self , indexes : impl AsRef < [ & ' index str ] > ) -> Self {
144
150
let values = Array :: new ( ) ;
145
- for idx in indexes {
151
+ for idx in indexes. as_ref ( ) {
146
152
values. push ( & JsValue :: from_str ( idx) ) ;
147
153
}
148
154
self . indexes = values;
@@ -162,7 +168,7 @@ impl AnalyticsEngineDataPointBuilder {
162
168
/// ```
163
169
/// use worker::AnalyticsEngineDataPointBuilder;
164
170
/// let point = AnalyticsEngineDataPointBuilder::new()
165
- /// .indexes(vec! ["index1"].into() )
171
+ /// .indexes(["index1"])
166
172
/// .add_double(25) // double1
167
173
/// .add_double(0.5) // double2
168
174
/// .build();
@@ -187,16 +193,16 @@ impl AnalyticsEngineDataPointBuilder {
187
193
/// ```
188
194
/// use worker::AnalyticsEngineDataPointBuilder;
189
195
/// let point = AnalyticsEngineDataPointBuilder::new()
190
- /// .indexes(vec! ["index1"].into() )
196
+ /// .indexes(["index1"])
191
197
/// .add_double(1) // value will be replaced by the following line
192
- /// .doubles(vec! [1, 2, 3].into() ) // sets double1, double2 and double3
198
+ /// .doubles([1, 2, 3]) // sets double1, double2 and double3
193
199
/// .build();
194
200
/// println!("{:?}", point);
195
201
/// ```
196
- pub fn doubles ( mut self , doubles : & [ f64 ] ) -> Self {
202
+ pub fn doubles ( mut self , doubles : impl IntoIterator < Item = f64 > ) -> Self {
197
203
let values = Array :: new ( ) ;
198
204
for n in doubles {
199
- values. push ( & JsValue :: from_f64 ( * n) ) ;
205
+ values. push ( & JsValue :: from_f64 ( n) ) ;
200
206
}
201
207
self . doubles = values;
202
208
self
@@ -215,7 +221,7 @@ impl AnalyticsEngineDataPointBuilder {
215
221
/// ```
216
222
/// use worker::AnalyticsEngineDataPointBuilder;
217
223
/// let point = AnalyticsEngineDataPointBuilder::new()
218
- /// .indexes(vec! ["index1"].into() )
224
+ /// .indexes(["index1"])
219
225
/// .add_blob("Seattle") // blob1
220
226
/// .add_blob("USA") // blob2
221
227
/// .add_blob("pro_sensor_9000") // blob3
@@ -241,12 +247,12 @@ impl AnalyticsEngineDataPointBuilder {
241
247
/// ```
242
248
/// use worker::AnalyticsEngineDataPointBuilder;
243
249
/// let point = AnalyticsEngineDataPointBuilder::new()
244
- /// .indexes(vec! ["index1"].into() )
245
- /// .blobs(vec! ["Seattle", "USA", "pro_sensor_9000"]) // sets blob1, blob2, and blob3
250
+ /// .indexes(["index1"])
251
+ /// .blobs(["Seattle", "USA", "pro_sensor_9000"]) // sets blob1, blob2, and blob3
246
252
/// .build();
247
253
/// println!("{:?}", point);
248
254
/// ```
249
- pub fn blobs ( mut self , blobs : Vec < impl Into < BlobType > > ) -> Self {
255
+ pub fn blobs ( mut self , blobs : impl IntoIterator < Item = impl Into < BlobType > > ) -> Self {
250
256
let values = Array :: new ( ) ;
251
257
for blob in blobs {
252
258
let value = blob. into ( ) ;
0 commit comments