@@ -14,6 +14,7 @@ use crate::element::ExcludeKind;
14
14
use crate :: entity:: { ControlFlowExt , ToEntity } ;
15
15
use crate :: field:: FieldDesc ;
16
16
use crate :: func:: { FuncCppBody , FuncDesc , FuncKind , ReturnKind } ;
17
+ use crate :: settings:: PropertyReadWrite ;
17
18
use crate :: type_ref:: { Constness , CppNameStyle , StrEnc , StrType , TypeRef , TypeRefDesc , TypeRefTypeHint } ;
18
19
use crate :: writer:: rust_native:: element:: RustElement ;
19
20
use crate :: {
@@ -438,71 +439,80 @@ impl<'tu, 'ge> Class<'tu, 'ge> {
438
439
let return_kind = ReturnKind :: infallible ( fld_type_kind. return_as_naked ( fld_type_ref. type_hint ( ) ) ) ;
439
440
let fld_const = fld. constness ( ) ;
440
441
let passed_by_ref = fld_type_kind. can_return_as_direct_reference ( ) ;
441
- let rust_custom_leafname = gen_env. settings . property_rename . get ( fld_refname. as_ref ( ) ) . copied ( ) ;
442
+ let prop_tweak = gen_env. settings . property_tweaks . get ( fld_refname. as_ref ( ) ) ;
443
+ let rust_custom_leafname = prop_tweak. and_then ( |tweak| tweak. rename ) ;
444
+ let read_write = prop_tweak
445
+ . and_then ( |tweak| tweak. read_write )
446
+ . unwrap_or ( PropertyReadWrite :: ReadWrite ) ;
442
447
let fld_declname = fld_refname. localname ( ) ;
443
- let ( mut read_const_yield, mut read_mut_yield) = if fld_const. is_mut ( ) && passed_by_ref {
444
- let read_const_func = if constness_filter. map_or ( true , |c| c. is_const ( ) ) {
445
- Some ( Func :: new_desc (
446
- FuncDesc :: new (
447
- FuncKind :: FieldAccessor ( self . clone ( ) , fld. clone ( ) ) ,
448
- Constness :: Const ,
449
- return_kind,
450
- fld_declname,
451
- Rc :: clone ( & rust_module) ,
452
- [ ] ,
453
- fld_type_ref. as_ref ( ) . clone ( ) . with_inherent_constness ( Constness :: Const ) ,
454
- )
455
- . def_loc ( def_loc. clone ( ) )
456
- . doc_comment ( Rc :: clone ( & doc_comment) )
457
- . cpp_body ( FuncCppBody :: ManualCall ( "{{name}}" . into ( ) ) )
458
- . maybe_rust_custom_leafname ( rust_custom_leafname) ,
459
- ) )
448
+ let ( mut read_const_yield, mut read_mut_yield) = if read_write. is_read ( ) {
449
+ if fld_const. is_mut ( ) && passed_by_ref {
450
+ let read_const_func = if constness_filter. map_or ( true , |c| c. is_const ( ) ) {
451
+ Some ( Func :: new_desc (
452
+ FuncDesc :: new (
453
+ FuncKind :: FieldAccessor ( self . clone ( ) , fld. clone ( ) ) ,
454
+ Constness :: Const ,
455
+ return_kind,
456
+ fld_declname,
457
+ Rc :: clone ( & rust_module) ,
458
+ [ ] ,
459
+ fld_type_ref. as_ref ( ) . clone ( ) . with_inherent_constness ( Constness :: Const ) ,
460
+ )
461
+ . def_loc ( def_loc. clone ( ) )
462
+ . doc_comment ( Rc :: clone ( & doc_comment) )
463
+ . cpp_body ( FuncCppBody :: ManualCall ( "{{name}}" . into ( ) ) )
464
+ . maybe_rust_custom_leafname ( rust_custom_leafname) ,
465
+ ) )
466
+ } else {
467
+ None
468
+ } ;
469
+ let read_mut_func = if constness_filter. map_or ( true , |c| c. is_mut ( ) ) {
470
+ Some ( Func :: new_desc (
471
+ FuncDesc :: new (
472
+ FuncKind :: FieldAccessor ( self . clone ( ) , fld. clone ( ) ) ,
473
+ Constness :: Mut ,
474
+ return_kind,
475
+ format ! ( "{fld_declname}Mut" ) ,
476
+ Rc :: clone ( & rust_module) ,
477
+ [ ] ,
478
+ fld_type_ref. as_ref ( ) . clone ( ) . with_inherent_constness ( Constness :: Mut ) ,
479
+ )
480
+ . def_loc ( def_loc. clone ( ) )
481
+ . doc_comment ( Rc :: clone ( & doc_comment) )
482
+ . cpp_body ( FuncCppBody :: ManualCall ( "{{name}}" . into ( ) ) )
483
+ . maybe_rust_custom_leafname ( rust_custom_leafname. map ( |name| format ! ( "{name}_mut" ) ) ) ,
484
+ ) )
485
+ } else {
486
+ None
487
+ } ;
488
+ ( read_const_func, read_mut_func)
460
489
} else {
461
- None
462
- } ;
463
- let read_mut_func = if constness_filter. map_or ( true , |c| c. is_mut ( ) ) {
464
- Some ( Func :: new_desc (
465
- FuncDesc :: new (
466
- FuncKind :: FieldAccessor ( self . clone ( ) , fld. clone ( ) ) ,
467
- Constness :: Mut ,
468
- return_kind,
469
- format ! ( "{fld_declname}Mut" ) ,
470
- Rc :: clone ( & rust_module) ,
471
- [ ] ,
472
- fld_type_ref. as_ref ( ) . clone ( ) . with_inherent_constness ( Constness :: Mut ) ,
473
- )
474
- . def_loc ( def_loc. clone ( ) )
475
- . doc_comment ( Rc :: clone ( & doc_comment) )
476
- . cpp_body ( FuncCppBody :: ManualCall ( "{{name}}" . into ( ) ) )
477
- . maybe_rust_custom_leafname ( rust_custom_leafname. map ( |name| format ! ( "{name}_mut" ) ) ) ,
478
- ) )
479
- } else {
480
- None
481
- } ;
482
- ( read_const_func, read_mut_func)
490
+ let single_read_func = if constness_filter. map_or ( true , |c| c == fld_const) {
491
+ Some ( Func :: new_desc (
492
+ FuncDesc :: new (
493
+ FuncKind :: FieldAccessor ( self . clone ( ) , fld. clone ( ) ) ,
494
+ fld_const,
495
+ return_kind,
496
+ fld_declname,
497
+ Rc :: clone ( & rust_module) ,
498
+ [ ] ,
499
+ fld_type_ref. as_ref ( ) . clone ( ) ,
500
+ )
501
+ . def_loc ( def_loc. clone ( ) )
502
+ . doc_comment ( Rc :: clone ( & doc_comment) )
503
+ . cpp_body ( FuncCppBody :: ManualCall ( "{{name}}" . into ( ) ) )
504
+ . maybe_rust_custom_leafname ( rust_custom_leafname) ,
505
+ ) )
506
+ } else {
507
+ None
508
+ } ;
509
+ ( single_read_func, None )
510
+ }
483
511
} else {
484
- let single_read_func = if constness_filter. map_or ( true , |c| c == fld_const) {
485
- Some ( Func :: new_desc (
486
- FuncDesc :: new (
487
- FuncKind :: FieldAccessor ( self . clone ( ) , fld. clone ( ) ) ,
488
- fld_const,
489
- return_kind,
490
- fld_declname,
491
- Rc :: clone ( & rust_module) ,
492
- [ ] ,
493
- fld_type_ref. as_ref ( ) . clone ( ) ,
494
- )
495
- . def_loc ( def_loc. clone ( ) )
496
- . doc_comment ( Rc :: clone ( & doc_comment) )
497
- . cpp_body ( FuncCppBody :: ManualCall ( "{{name}}" . into ( ) ) )
498
- . maybe_rust_custom_leafname ( rust_custom_leafname) ,
499
- ) )
500
- } else {
501
- None
502
- } ;
503
- ( single_read_func, None )
512
+ ( None , None )
504
513
} ;
505
- let mut write_yield = if constness_filter. map_or ( true , |c| c. is_mut ( ) )
514
+ let mut write_yield = if read_write. is_write ( )
515
+ && constness_filter. map_or ( true , |c| c. is_mut ( ) )
506
516
&& !fld_type_ref. constness ( ) . is_const ( )
507
517
&& !fld_type_kind. as_fixed_array ( ) . is_some ( )
508
518
{
0 commit comments