@@ -138,12 +138,18 @@ impl Language for Kotlin {
138
138
} ,
139
139
& [ ] ,
140
140
false ,
141
+ match ty. is_redacted {
142
+ true => Visibility :: Private ,
143
+ false => Visibility :: Public ,
144
+ } ,
141
145
) ?;
142
146
143
147
writeln ! ( w) ?;
144
148
145
149
if ty. is_redacted {
146
150
writeln ! ( w, ") {{" ) ?;
151
+ writeln ! ( w, "\t fun unwrap() = value" ) ?;
152
+ writeln ! ( w) ?;
147
153
writeln ! ( w, "\t override fun toString(): String = \" ***\" " ) ?;
148
154
writeln ! ( w, "}}" ) ?;
149
155
} else {
@@ -196,10 +202,22 @@ impl Language for Kotlin {
196
202
197
203
if let Some ( ( last, elements) ) = rs. fields . split_last ( ) {
198
204
for f in elements. iter ( ) {
199
- self . write_element ( w, f, rs. generic_types . as_slice ( ) , requires_serial_name) ?;
205
+ self . write_element (
206
+ w,
207
+ f,
208
+ rs. generic_types . as_slice ( ) ,
209
+ requires_serial_name,
210
+ Visibility :: Public ,
211
+ ) ?;
200
212
writeln ! ( w, "," ) ?;
201
213
}
202
- self . write_element ( w, last, rs. generic_types . as_slice ( ) , requires_serial_name) ?;
214
+ self . write_element (
215
+ w,
216
+ last,
217
+ rs. generic_types . as_slice ( ) ,
218
+ requires_serial_name,
219
+ Visibility :: Public ,
220
+ ) ?;
203
221
writeln ! ( w) ?;
204
222
}
205
223
@@ -275,6 +293,11 @@ impl Language for Kotlin {
275
293
}
276
294
}
277
295
296
+ enum Visibility {
297
+ Public ,
298
+ Private ,
299
+ }
300
+
278
301
impl Kotlin {
279
302
fn write_enum_variants ( & mut self , w : & mut dyn Write , e : & RustEnum ) -> std:: io:: Result < ( ) > {
280
303
match e {
@@ -402,6 +425,7 @@ impl Kotlin {
402
425
f : & RustField ,
403
426
generic_types : & [ String ] ,
404
427
requires_serial_name : bool ,
428
+ visibility : Visibility ,
405
429
) -> std:: io:: Result < ( ) > {
406
430
self . write_comments ( w, 1 , & f. comments ) ?;
407
431
if requires_serial_name {
@@ -414,16 +438,28 @@ impl Kotlin {
414
438
. map_err ( |e| std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , e) ) ?,
415
439
} ;
416
440
417
- write ! (
418
- w,
419
- "\t val {}: {}{}" ,
420
- remove_dash_from_identifier( & f. id. renamed) ,
421
- ty,
422
- ( f. has_default && !f. ty. is_optional( ) )
423
- . then_some( "? = null" )
424
- . or_else( || f. ty. is_optional( ) . then_some( " = null" ) )
425
- . unwrap_or_default( )
426
- )
441
+ match visibility {
442
+ Visibility :: Public => write ! (
443
+ w,
444
+ "\t val {}: {}{}" ,
445
+ remove_dash_from_identifier( & f. id. renamed) ,
446
+ ty,
447
+ ( f. has_default && !f. ty. is_optional( ) )
448
+ . then_some( "? = null" )
449
+ . or_else( || f. ty. is_optional( ) . then_some( " = null" ) )
450
+ . unwrap_or_default( )
451
+ ) ,
452
+ Visibility :: Private => write ! (
453
+ w,
454
+ "\t private val {}: {}{}" ,
455
+ remove_dash_from_identifier( & f. id. renamed) ,
456
+ ty,
457
+ ( f. has_default && !f. ty. is_optional( ) )
458
+ . then_some( "? = null" )
459
+ . or_else( || f. ty. is_optional( ) . then_some( " = null" ) )
460
+ . unwrap_or_default( )
461
+ ) ,
462
+ }
427
463
}
428
464
429
465
fn write_comment (
0 commit comments