Skip to content

Commit

Permalink
refactor: parse_receiver_ownership_mode
Browse files Browse the repository at this point in the history
  • Loading branch information
fzyzcjy committed Feb 7, 2024
1 parent dce9ee5 commit 16fb232
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions frb_codegen/src/library/codegen/parser/function_parser/argument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::codegen::ir::field::{IrField, IrFieldSettings};
use crate::codegen::ir::func::{IrFuncMode, IrFuncOwnerInfo};
use crate::codegen::ir::ident::IrIdent;
use crate::codegen::ir::ty::boxed::IrTypeBoxed;
use crate::codegen::ir::ty::rust_auto_opaque::OwnershipMode;
use crate::codegen::ir::ty::IrType;
use crate::codegen::ir::ty::IrType::Boxed;
use crate::codegen::parser::attribute_parser::FrbAttributes;
Expand Down Expand Up @@ -186,13 +187,21 @@ fn parse_name_from_pat_type(pat_type: &PatType) -> anyhow::Result<String> {
}

fn generate_ref_type_considering_reference(raw: &str, receiver: &Receiver) -> String {
match parse_receiver_ownership_mode(receiver) {
OwnershipMode::Owned => raw.to_owned(),
OwnershipMode::RefMut => format!("&mut {raw}"),
OwnershipMode::Ref => format!("&{raw}"),
}
}

fn parse_receiver_ownership_mode(receiver: &Receiver) -> OwnershipMode {
if receiver.reference.is_some() {
if receiver.mutability.is_some() {
format!("&mut {raw}")
OwnershipMode::RefMut
} else {
format!("&{raw}")
OwnershipMode::Ref
}
} else {
raw.to_owned()
OwnershipMode::Owned
}
}

0 comments on commit 16fb232

Please sign in to comment.