diff --git a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/method.rs b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/method.rs index e0e4bf1a41..1253aae163 100644 --- a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/method.rs +++ b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/method.rs @@ -1,18 +1,23 @@ use crate::codegen::generator::api_dart; +use crate::codegen::generator::api_dart::spec_generator::class::proxy_variant; use crate::codegen::generator::api_dart::spec_generator::function::{ compute_params_str, ApiDartGeneratedFunction, ApiDartGeneratedFunctionParam, }; use crate::codegen::generator::api_dart::spec_generator::misc::generate_dart_comments; use crate::codegen::ir::mir::func::{ - MirFunc, MirFuncAccessorMode, MirFuncArgMode, MirFuncDefaultConstructorMode, MirFuncOwnerInfo, - MirFuncOwnerInfoMethod, MirFuncOwnerInfoMethodMode, + MirFunc, MirFuncAccessorMode, MirFuncArgMode, MirFuncDefaultConstructorMode, MirFuncImplMode, + MirFuncImplModeDartOnly, MirFuncOwnerInfo, MirFuncOwnerInfoMethod, MirFuncOwnerInfoMethodMode, }; +use crate::codegen::ir::mir::ty::delegate::MirTypeDelegate; +use crate::codegen::ir::mir::ty::MirType; use crate::if_then_some; use crate::library::codegen::generator::api_dart::spec_generator::base::*; use crate::utils::basic_code::dart_header_code::DartHeaderCode; use crate::utils::namespace::NamespacedName; use convert_case::{Case, Casing}; use itertools::Itertools; +use lazy_static::lazy_static; +use regex::Regex; #[derive(Debug, Clone)] pub(crate) struct GenerateApiMethodConfig { @@ -53,16 +58,16 @@ struct GeneratedApiMethod { } pub(crate) fn generate_api_methods( - generalized_class_name: &NamespacedName, + owner_ty: &MirType, context: ApiDartGeneratorContext, config: &GenerateApiMethodConfig, dart_class_name: &str, ) -> GeneratedApiMethods { - let methods = - get_methods_of_enum_or_struct(generalized_class_name, &context.mir_pack.funcs_all) - .iter() - .filter_map(|func| generate_api_method(func, context, config, dart_class_name)) - .collect_vec(); + let query_class_name = compute_class_name_for_querying_methods(owner_ty); + let methods = get_methods_of_ty(&query_class_name, &context.mir_pack.funcs_all) + .iter() + .filter_map(|func| generate_api_method(func, context, config, dart_class_name)) + .collect_vec(); GeneratedApiMethods { num_methods: methods.len(), code: methods.iter().map(|x| x.code.clone()).join("\n"), @@ -70,6 +75,30 @@ pub(crate) fn generate_api_methods( } } +fn compute_class_name_for_querying_methods(ty: &MirType) -> NamespacedName { + match ty { + MirType::EnumRef(ty) => ty.ident.0.clone(), + MirType::StructRef(ty) => ty.ident.0.clone(), + MirType::TraitDef(ty) => ty.name.clone(), + MirType::Delegate(MirTypeDelegate::ProxyVariant(ty)) => { + compute_class_name_for_querying_methods(&*ty.inner) + } + MirType::RustAutoOpaqueImplicit(ty) => { + compute_class_name_for_querying_methods(&MirType::RustOpaque(ty.inner.clone())) + } + MirType::RustOpaque(ty) => { + lazy_static! { + static ref FILTER: Regex = + Regex::new(r"^flutter_rust_bridge::for_generated::RustAutoOpaqueInner<(.*)>$") + .unwrap(); + } + let name = FILTER.replace_all(&ty.inner.0, "$1").to_string(); + NamespacedName::new(ty.namespace.clone(), name) + } + _ => panic!("compute_query_class_name see unknown ty={ty:?}"), + } +} + // TODO move pub(crate) fn dart_constructor_postfix( name: &NamespacedName, @@ -83,17 +112,12 @@ pub(crate) fn dart_constructor_postfix( } fn has_default_dart_constructor(name: &NamespacedName, all_funcs: &[MirFunc]) -> bool { - get_methods_of_enum_or_struct(name, all_funcs) - .iter() - .any(|m| { - m.default_constructor_mode() == Some(MirFuncDefaultConstructorMode::DartConstructor) - }) + get_methods_of_ty(name, all_funcs).iter().any(|m| { + m.default_constructor_mode() == Some(MirFuncDefaultConstructorMode::DartConstructor) + }) } -fn get_methods_of_enum_or_struct<'a>( - name: &NamespacedName, - all_funcs: &'a [MirFunc], -) -> Vec<&'a MirFunc> { +fn get_methods_of_ty<'a>(name: &NamespacedName, all_funcs: &'a [MirFunc]) -> Vec<&'a MirFunc> { (all_funcs.iter()) .filter(|f| matches!(&f.owner, MirFuncOwnerInfo::Method(m) if m.owner_ty_name().as_ref() == Some(name))) .collect_vec() @@ -232,20 +256,30 @@ fn generate_implementation( method_info: &MirFuncOwnerInfoMethod, params: &[ApiDartGeneratedFunctionParam], ) -> String { - let dart_entrypoint_class_name = &context.config.dart_entrypoint_class_name; - let dart_api_instance = format!("{dart_entrypoint_class_name}.instance.api"); + match &func.impl_mode { + MirFuncImplMode::Normal => { + let dart_entrypoint_class_name = &context.config.dart_entrypoint_class_name; + let dart_api_instance = format!("{dart_entrypoint_class_name}.instance.api"); - let func_name = func.name_dart_wire(); + let func_name = func.name_dart_wire(); - let arg_names = params - .iter() - .map(|x| format!("{name}: {name}", name = x.name_str)) - .join(", "); + let arg_names = params + .iter() + .map(|x| format!("{name}: {name}", name = x.name_str)) + .join(", "); - if method_info.mode == MirFuncOwnerInfoMethodMode::Static { - format!("{dart_api_instance}.{func_name}({arg_names})") - } else { - let extra_arg_name = func.inputs[0].inner.name.dart_style(); - format!("{dart_api_instance}.{func_name}({extra_arg_name}: this, {arg_names})") + if method_info.mode == MirFuncOwnerInfoMethodMode::Static { + format!("{dart_api_instance}.{func_name}({arg_names})") + } else { + let extra_arg_name = func.inputs[0].inner.name.dart_style(); + format!("{dart_api_instance}.{func_name}({extra_arg_name}: this, {arg_names})") + } + } + MirFuncImplMode::NoImpl => "should_not_reach_here".to_owned(), + MirFuncImplMode::DartOnly(inner) => match inner { + MirFuncImplModeDartOnly::CreateProxyVariant(inner) => { + proxy_variant::compute_func_implementation(inner, context, func.mode) + } + }, } } diff --git a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/mod.rs b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/mod.rs index 257ae3d000..c2e9878931 100644 --- a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/mod.rs +++ b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/mod.rs @@ -5,6 +5,7 @@ use serde::Serialize; pub(crate) mod field; pub(crate) mod method; pub(super) mod misc; +pub(crate) mod proxy_variant; pub(crate) mod ty; #[derive(Debug, Serialize)] diff --git a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/proxy_variant.rs b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/proxy_variant.rs new file mode 100644 index 0000000000..e01d144522 --- /dev/null +++ b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/proxy_variant.rs @@ -0,0 +1,31 @@ +use crate::codegen::generator::api_dart::spec_generator::base::{ + ApiDartGenerator, ApiDartGeneratorContext, +}; +use crate::codegen::ir::mir::func::MirFuncMode; +use crate::codegen::ir::mir::ty::delegate::MirTypeDelegateProxyVariant; +use crate::library::codegen::generator::api_dart::spec_generator::info::ApiDartGeneratorInfoTrait; + +pub(crate) fn compute_func_implementation( + ir: &MirTypeDelegateProxyVariant, + context: ApiDartGeneratorContext, + func_mode: MirFuncMode, +) -> String { + let mut ans = format!("{}(this)", compute_dart_extra_type(ir, context)); + if func_mode == MirFuncMode::Normal { + ans = format!("Future.value({ans})"); + } + ans +} + +pub(crate) fn compute_dart_extra_type( + ir: &MirTypeDelegateProxyVariant, + context: ApiDartGeneratorContext, +) -> String { + let inner_dart_api_type = ApiDartGenerator::new(ir.inner.clone(), context).dart_api_type(); + let upstream_dart_api_type = + ApiDartGenerator::new(ir.upstream.clone(), context).dart_api_type(); + format!( + "{}ProxyVariant{}", + inner_dart_api_type, upstream_dart_api_type + ) +} diff --git a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/ty/delegate.rs b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/ty/delegate.rs index 57b95c804c..a9535ef3ad 100644 --- a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/ty/delegate.rs +++ b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/ty/delegate.rs @@ -1,11 +1,19 @@ +use crate::codegen::generator::api_dart::spec_generator::class::method::{ + generate_api_methods, GenerateApiMethodConfig, GenerateApiMethodMode, +}; use crate::codegen::generator::api_dart::spec_generator::class::ty::ApiDartGeneratorClassTrait; -use crate::codegen::generator::api_dart::spec_generator::class::ApiDartGeneratedClass; +use crate::codegen::generator::api_dart::spec_generator::class::{ + proxy_variant, ApiDartGeneratedClass, +}; use crate::codegen::ir::mir::ty::delegate::{ MirTypeDelegate, MirTypeDelegateArray, MirTypeDelegateArrayMode, MirTypeDelegatePrimitiveEnum, + MirTypeDelegateProxyVariant, }; +use crate::codegen::ir::mir::ty::MirType; use crate::library::codegen::generator::api_dart::spec_generator::base::*; use crate::library::codegen::generator::api_dart::spec_generator::info::ApiDartGeneratorInfoTrait; use crate::utils::basic_code::dart_header_code::DartHeaderCode; +use crate::utils::namespace::NamespacedName; impl<'a> ApiDartGeneratorClassTrait for DelegateApiDartGenerator<'a> { fn generate_class(&self) -> Option { @@ -17,6 +25,13 @@ impl<'a> ApiDartGeneratorClassTrait for DelegateApiDartGenerator<'a> { _ => None, } } + + fn generate_extra_impl_code(&self) -> Option { + match &self.mir { + MirTypeDelegate::ProxyVariant(mir) => Some(generate_proxy_variant(mir, self.context)), + _ => None, + } + } } fn generate_array( @@ -66,3 +81,34 @@ fn generate_array( needs_freezed: false, }) } + +fn generate_proxy_variant( + mir: &MirTypeDelegateProxyVariant, + context: ApiDartGeneratorContext, +) -> String { + let class_name = proxy_variant::compute_dart_extra_type(mir, context); + + let implements_name = ApiDartGenerator::new(mir.inner.clone(), context).dart_api_type(); + let upstream_name = ApiDartGenerator::new(mir.upstream.clone(), context).dart_api_type(); + + let methods = generate_api_methods( + &MirType::Delegate(MirTypeDelegate::ProxyVariant(mir.clone())), + context, + &GenerateApiMethodConfig { + mode_static: GenerateApiMethodMode::Nothing, + mode_non_static: GenerateApiMethodMode::DeclAndImpl, + }, + &class_name, + ); + let methods_str = methods.code; + + format!( + "class {class_name} with SimpleDisposable implements {implements_name} {{ + final {upstream_name} _upstream; + + {class_name}(this._upstream); + + {methods_str} + }}" + ) +} diff --git a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/ty/enumeration.rs b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/ty/enumeration.rs index db0ab5f061..b88ae4fedc 100644 --- a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/ty/enumeration.rs +++ b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/ty/enumeration.rs @@ -5,6 +5,7 @@ use crate::codegen::generator::api_dart::spec_generator::class::misc::generate_c use crate::codegen::generator::api_dart::spec_generator::class::ty::ApiDartGeneratorClassTrait; use crate::codegen::generator::api_dart::spec_generator::class::ApiDartGeneratedClass; use crate::codegen::ir::mir::ty::enumeration::MirEnumMode; +use crate::codegen::ir::mir::ty::MirType; use crate::library::codegen::generator::api_dart::spec_generator::base::*; impl<'a> ApiDartGeneratorClassTrait for EnumRefApiDartGenerator<'a> { @@ -12,7 +13,7 @@ impl<'a> ApiDartGeneratorClassTrait for EnumRefApiDartGenerator<'a> { let src = self.mir.get(self.context.mir_pack); let methods = generate_api_methods( - &src.name, + &MirType::EnumRef(self.mir.clone()), self.context, &GenerateApiMethodConfig::COMBINED, &src.name.name, diff --git a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/ty/rust_opaque.rs b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/ty/rust_opaque.rs index 6377a65a43..5a9e47c374 100644 --- a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/ty/rust_opaque.rs +++ b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/ty/rust_opaque.rs @@ -105,10 +105,9 @@ impl RustOpaqueApiDartGenerator<'_> { dart_class_name_postfix: &str, ) -> Info { let dart_api_type = ApiDartGenerator::new(self.mir.clone(), self.context).dart_api_type(); - let type_query_name = compute_query_name(&self.mir); let methods = generate_api_methods( - &NamespacedName::new(self.mir.namespace.clone(), type_query_name.clone()), + &MirType::RustOpaque(self.mir.clone()), self.context, config, &format!("{dart_api_type}{dart_class_name_postfix}"), @@ -126,15 +125,6 @@ struct Info { methods: GeneratedApiMethods, } -fn compute_query_name(mir: &MirTypeRustOpaque) -> String { - lazy_static! { - static ref FILTER: Regex = - Regex::new(r"^flutter_rust_bridge::for_generated::RustAutoOpaqueInner<(.*)>$").unwrap(); - } - - FILTER.replace_all(&mir.inner.0, "$1").to_string() -} - fn generate_implements( all_trait_impls: &[MirTraitImpl], self_type: &MirTypeRustOpaque, diff --git a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/ty/structure.rs b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/ty/structure.rs index 8598c829d3..b997fcf29d 100644 --- a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/ty/structure.rs +++ b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/ty/structure.rs @@ -7,6 +7,7 @@ use crate::codegen::generator::api_dart::spec_generator::class::ApiDartGenerated use crate::codegen::generator::api_dart::spec_generator::misc::{ generate_dart_comments, generate_dart_metadata, }; +use crate::codegen::ir::mir::ty::MirType; use crate::library::codegen::generator::api_dart::spec_generator::base::*; impl<'a> ApiDartGeneratorClassTrait for StructRefApiDartGenerator<'a> { @@ -20,7 +21,7 @@ impl<'a> ApiDartGeneratorClassTrait for StructRefApiDartGenerator<'a> { let class_name = &self.mir.ident.0.name; let methods = generate_api_methods( - &src.name, + &MirType::StructRef(self.mir.clone()), self.context, &GenerateApiMethodConfig::COMBINED, class_name, diff --git a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/ty/trait_def.rs b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/ty/trait_def.rs index b018d800b5..368092005e 100644 --- a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/ty/trait_def.rs +++ b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/class/ty/trait_def.rs @@ -3,13 +3,14 @@ use crate::codegen::generator::api_dart::spec_generator::class::method::{ }; use crate::codegen::generator::api_dart::spec_generator::class::ty::ApiDartGeneratorClassTrait; use crate::codegen::generator::api_dart::spec_generator::class::ApiDartGeneratedClass; +use crate::codegen::ir::mir::ty::MirType; use crate::library::codegen::generator::api_dart::spec_generator::base::*; impl<'a> ApiDartGeneratorClassTrait for TraitDefApiDartGenerator<'a> { fn generate_class(&self) -> Option { let dart_api_type = &self.mir.name.name; let methods = generate_api_methods( - &self.mir.name, + &MirType::TraitDef(self.mir.clone()), self.context, &GenerateApiMethodConfig { mode_static: GenerateApiMethodMode::Nothing, diff --git a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/info.rs b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/info.rs index e6cad0e418..f3506f41c6 100644 --- a/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/info.rs +++ b/frb_codegen/src/library/codegen/generator/api_dart/spec_generator/info.rs @@ -89,6 +89,12 @@ impl<'a> ApiDartGeneratorInfoTrait for DelegateApiDartGenerator<'a> { MirTypeDelegate::RustAutoOpaqueExplicit(mir) => { ApiDartGenerator::new(mir.inner.clone(), self.context).dart_api_type() } // MirTypeDelegate::DynTrait(mir) => mir.trait_def_name.name.clone(), + MirTypeDelegate::ProxyVariant(mir) => { + ApiDartGenerator::new(mir.inner.clone(), self.context).dart_api_type() + } + MirTypeDelegate::ProxyEnum(mir) => { + ApiDartGenerator::new(mir.original.clone(), self.context).dart_api_type() + } } } diff --git a/frb_codegen/src/library/codegen/generator/codec/sse/ty/delegate.rs b/frb_codegen/src/library/codegen/generator/codec/sse/ty/delegate.rs index 2047c26f3c..cb70e6daaa 100644 --- a/frb_codegen/src/library/codegen/generator/codec/sse/ty/delegate.rs +++ b/frb_codegen/src/library/codegen/generator/codec/sse/ty/delegate.rs @@ -1,9 +1,10 @@ use crate::codegen::generator::api_dart::spec_generator::base::ApiDartGenerator; +use crate::codegen::generator::api_dart::spec_generator::class::proxy_variant; use crate::codegen::generator::codec::sse::lang::*; use crate::codegen::generator::codec::sse::ty::*; use crate::codegen::ir::mir::ty::delegate::{ - MirTypeDelegatePrimitiveEnum, MirTypeDelegateSet, MirTypeDelegateStreamSink, - MirTypeDelegateTime, + MirTypeDelegatePrimitiveEnum, MirTypeDelegateProxyEnum, MirTypeDelegateSet, + MirTypeDelegateStreamSink, MirTypeDelegateTime, }; use crate::library::codegen::generator::api_dart::spec_generator::info::ApiDartGeneratorInfoTrait; use convert_case::{Case, Casing}; @@ -17,7 +18,7 @@ impl<'a> CodecSseTyTrait for DelegateCodecSseTy<'a> { MirTypeDelegate::String => "utf8.encoder.convert(self)".to_owned(), MirTypeDelegate::Char => "self".to_owned(), MirTypeDelegate::PrimitiveEnum(_) => "self.index".to_owned(), - MirTypeDelegate::Backtrace => { + MirTypeDelegate::Backtrace | MirTypeDelegate::ProxyVariant(_) => { return Some(format!("{};", lang.throw_unreachable(""))); } MirTypeDelegate::AnyhowException => "self.message".to_owned(), @@ -43,7 +44,9 @@ impl<'a> CodecSseTyTrait for DelegateCodecSseTy<'a> { } MirTypeDelegate::BigPrimitive(_) => "self.toString()".to_owned(), MirTypeDelegate::RustAutoOpaqueExplicit(_ir) => "self".to_owned(), - // MirTypeDelegate::DynTrait(_ir) => lang.throw_unimplemented(""), // TODO + MirTypeDelegate::ProxyEnum(mir) => { + generate_proxy_enum_dart_encode(mir, self.context.as_api_dart_context()) + } // MirTypeDelegate::DynTrait(_ir) => lang.throw_unimplemented(""), }, Lang::RustLang(_) => match &self.mir { MirTypeDelegate::Array(_) => { @@ -82,7 +85,8 @@ impl<'a> CodecSseTyTrait for DelegateCodecSseTy<'a> { } }, MirTypeDelegate::Uuid => "self.as_bytes().to_vec()".to_owned(), - MirTypeDelegate::StreamSink(_) /*| MirTypeDelegate::DynTrait(_)*/ => { + MirTypeDelegate::StreamSink(_) + /*| MirTypeDelegate::DynTrait(_)*/ => { return Some(lang.throw_unimplemented("")) } MirTypeDelegate::BigPrimitive(_) => "self.to_string()".to_owned(), @@ -90,6 +94,9 @@ impl<'a> CodecSseTyTrait for DelegateCodecSseTy<'a> { "flutter_rust_bridge::for_generated::rust_auto_opaque_explicit_encode(self)" .to_owned() } + MirTypeDelegate::ProxyVariant(_) + | MirTypeDelegate::ProxyEnum(_) + => return None, }, }; Some(simple_delegate_encode( @@ -141,7 +148,9 @@ impl<'a> CodecSseTyTrait for DelegateCodecSseTy<'a> { } }, MirTypeDelegate::Uuid => "UuidValue.fromByteList(inner)".to_owned(), - MirTypeDelegate::StreamSink(_) => { + MirTypeDelegate::StreamSink(_) + | MirTypeDelegate::ProxyVariant(_) + | MirTypeDelegate::ProxyEnum(_) => { return Some(format!("{};", lang.throw_unreachable(""))); } MirTypeDelegate::BigPrimitive(_) => "BigInt.parse(inner)".to_owned(), @@ -188,7 +197,8 @@ impl<'a> CodecSseTyTrait for DelegateCodecSseTy<'a> { MirTypeDelegate::RustAutoOpaqueExplicit(_ir) => { "flutter_rust_bridge::for_generated::rust_auto_opaque_explicit_decode(inner)" .to_owned() - } // MirTypeDelegate::DynTrait(_ir) => lang.throw_unimplemented(""), // TODO + } // MirTypeDelegate::DynTrait(_ir) => lang.throw_unimplemented(""), + MirTypeDelegate::ProxyVariant(_) | MirTypeDelegate::ProxyEnum(_) => return None, }, }; @@ -274,3 +284,31 @@ pub(crate) fn generate_stream_sink_setup_and_serialize( format!("{var_name}.setupAndSerialize(codec: {codec_code})") } + +fn generate_proxy_enum_dart_encode( + mir: &MirTypeDelegateProxyEnum, + context: ApiDartGeneratorContext, +) -> String { + let enum_name = mir.proxy_enum_name(); + + let variants = (mir.variants.iter().enumerate()) + .map(|(index, variant)| { + let variant_dart_extra_type = proxy_variant::compute_dart_extra_type(variant, context); + format!( + "if (self is {variant_dart_extra_type}) {{ + return {enum_name}.variant{index}(self._upstream); + }} + " + ) + }) + .join(""); + + format!( + " + (() {{ + {variants} + throw Exception('not reachable'); + }})() + " + ) +} diff --git a/frb_codegen/src/library/codegen/generator/wire/dart/spec_generator/codec/cst/encoder/ty/delegate.rs b/frb_codegen/src/library/codegen/generator/wire/dart/spec_generator/codec/cst/encoder/ty/delegate.rs index ecebb729fa..2b4035041c 100644 --- a/frb_codegen/src/library/codegen/generator/wire/dart/spec_generator/codec/cst/encoder/ty/delegate.rs +++ b/frb_codegen/src/library/codegen/generator/wire/dart/spec_generator/codec/cst/encoder/ty/delegate.rs @@ -139,6 +139,8 @@ impl<'a> WireDartCodecCstGeneratorEncoderTrait for DelegateWireDartCodecCstGener "return cst_encode_{}(raw);", self.mir.get_delegate().safe_ident(), ))), + MirTypeDelegate::ProxyVariant(_) | MirTypeDelegate::ProxyEnum(_) => + Acc::distribute(Some("throw UnimplementedError('Not implemented in this codec, please use the other one');".to_string())) } } diff --git a/frb_codegen/src/library/codegen/generator/wire/dart/spec_generator/codec/dco/decoder/ty/delegate.rs b/frb_codegen/src/library/codegen/generator/wire/dart/spec_generator/codec/dco/decoder/ty/delegate.rs index 33f7d39da4..cca4847a36 100644 --- a/frb_codegen/src/library/codegen/generator/wire/dart/spec_generator/codec/dco/decoder/ty/delegate.rs +++ b/frb_codegen/src/library/codegen/generator/wire/dart/spec_generator/codec/dco/decoder/ty/delegate.rs @@ -85,7 +85,9 @@ impl<'a> WireDartCodecDcoGeneratorDecoderTrait for DelegateWireDartCodecDcoGener MirTypeDelegate::BigPrimitive(_) => { "return BigInt.parse(raw);".to_owned() } - MirTypeDelegate::RustAutoOpaqueExplicit(mir) => format!(r"return dco_decode_{}(raw);", mir.inner.safe_ident()) + MirTypeDelegate::RustAutoOpaqueExplicit(mir) => format!(r"return dco_decode_{}(raw);", mir.inner.safe_ident()), + MirTypeDelegate::ProxyVariant(_) | MirTypeDelegate::ProxyEnum(_) => + "throw UnimplementedError('Not implemented in this codec, please use the other one');".into(), } } } diff --git a/frb_codegen/src/library/codegen/generator/wire/rust/spec_generator/codec/cst/decoder/ty/delegate.rs b/frb_codegen/src/library/codegen/generator/wire/rust/spec_generator/codec/cst/decoder/ty/delegate.rs index fcb9b202cf..5034de7732 100644 --- a/frb_codegen/src/library/codegen/generator/wire/rust/spec_generator/codec/cst/decoder/ty/delegate.rs +++ b/frb_codegen/src/library/codegen/generator/wire/rust/spec_generator/codec/cst/decoder/ty/delegate.rs @@ -103,6 +103,8 @@ impl<'a> WireRustCodecCstGeneratorDecoderTrait for DelegateWireRustCodecCstGener io: Some("flutter_rust_bridge::for_generated::rust_auto_opaque_explicit_decode(self.cst_decode())".into()), ..Default::default() }, + MirTypeDelegate::ProxyVariant(_) | MirTypeDelegate::ProxyEnum(_) => + Acc::distribute(Some(r#"unimplemented!("Not implemented in this codec, please use the other one")"#.to_string())) } } @@ -141,6 +143,8 @@ impl<'a> WireRustCodecCstGeneratorDecoderTrait for DelegateWireRustCodecCstGener MirTypeDelegate::BigPrimitive(_) => "CstDecode::::cst_decode(self).parse().unwrap()".into(), MirTypeDelegate::RustAutoOpaqueExplicit(_) => "flutter_rust_bridge::for_generated::rust_auto_opaque_explicit_decode(self.cst_decode())".into(), + MirTypeDelegate::ProxyVariant(_) | MirTypeDelegate::ProxyEnum(_) => + r#"unimplemented!("Not implemented in this codec, please use the other one")"#.into(), }) } diff --git a/frb_codegen/src/library/codegen/ir/early_generator/mod.rs b/frb_codegen/src/library/codegen/ir/early_generator/mod.rs new file mode 100644 index 0000000000..91b3e783b7 --- /dev/null +++ b/frb_codegen/src/library/codegen/ir/early_generator/mod.rs @@ -0,0 +1,2 @@ +pub(crate) mod pack; +pub(crate) mod proxied_type; diff --git a/frb_codegen/src/library/codegen/ir/early_generator/pack.rs b/frb_codegen/src/library/codegen/ir/early_generator/pack.rs new file mode 100644 index 0000000000..1ba490f4e3 --- /dev/null +++ b/frb_codegen/src/library/codegen/ir/early_generator/pack.rs @@ -0,0 +1,9 @@ +use crate::codegen::ir::early_generator::proxied_type::IrEarlyGeneratorProxiedType; +use crate::codegen::ir::hir::flat::pack::HirFlatPack; +use crate::codegen::ir::mir::ty::MirType; + +#[derive(Debug, Clone, Default, serde::Serialize)] +pub(crate) struct IrEarlyGeneratorPack { + pub hir_flat_pack: HirFlatPack, + pub proxied_types: Vec, +} diff --git a/frb_codegen/src/library/codegen/ir/early_generator/proxied_type.rs b/frb_codegen/src/library/codegen/ir/early_generator/proxied_type.rs new file mode 100644 index 0000000000..dce8af656e --- /dev/null +++ b/frb_codegen/src/library/codegen/ir/early_generator/proxied_type.rs @@ -0,0 +1,10 @@ +use crate::codegen::ir::mir::ty::delegate::MirTypeDelegateProxyVariant; +use crate::codegen::ir::mir::ty::MirType; +use crate::utils::namespace::Namespace; + +#[derive(Debug, Clone, serde::Serialize, PartialEq, Eq, Hash)] +pub(crate) struct IrEarlyGeneratorProxiedType { + pub proxy_enum_namespace: Namespace, + pub original_ty: MirType, + pub variants: Vec, +} diff --git a/frb_codegen/src/library/codegen/ir/mir/func.rs b/frb_codegen/src/library/codegen/ir/mir/func.rs index a8ff0364b3..b656a093c8 100644 --- a/frb_codegen/src/library/codegen/ir/mir/func.rs +++ b/frb_codegen/src/library/codegen/ir/mir/func.rs @@ -1,7 +1,9 @@ use crate::codegen::generator::codec::structs::CodecModePack; use crate::codegen::ir::mir::comment::MirComment; use crate::codegen::ir::mir::field::MirField; -use crate::codegen::ir::mir::ty::delegate::{MirTypeDelegate, MirTypeDelegatePrimitiveEnum}; +use crate::codegen::ir::mir::ty::delegate::{ + MirTypeDelegate, MirTypeDelegatePrimitiveEnum, MirTypeDelegateProxyVariant, +}; use crate::codegen::ir::mir::ty::primitive::MirTypePrimitive; use crate::codegen::ir::mir::ty::trait_def::MirTypeTraitDef; use crate::codegen::ir::mir::ty::{MirContext, MirType, MirTypeTrait}; @@ -27,7 +29,7 @@ pub struct MirFunc { pub comments: Vec, pub codec_mode_pack: CodecModePack, pub rust_call_code: Option, - pub has_impl: bool, + pub impl_mode: MirFuncImplMode, // Currently, we use serde only for tests. Since lineno can be unstable, we skip this field for comparison #[serde(skip_serializing)] pub src_lineno_pseudo: usize, @@ -55,6 +57,16 @@ pub enum MirFuncArgMode { Named, } +pub enum MirFuncImplMode { + Normal, + NoImpl, + DartOnly(MirFuncImplModeDartOnly), +} + +pub enum MirFuncImplModeDartOnly { + CreateProxyVariant(MirTypeDelegateProxyVariant), +} + pub enum MirFuncOwnerInfo { Function, Method(MirFuncOwnerInfoMethod), diff --git a/frb_codegen/src/library/codegen/ir/mir/pack.rs b/frb_codegen/src/library/codegen/ir/mir/pack.rs index c0aae38f6f..7acd8f38dd 100644 --- a/frb_codegen/src/library/codegen/ir/mir/pack.rs +++ b/frb_codegen/src/library/codegen/ir/mir/pack.rs @@ -1,5 +1,5 @@ use crate::codegen::generator::codec::structs::CodecMode; -use crate::codegen::ir::mir::func::MirFunc; +use crate::codegen::ir::mir::func::{MirFunc, MirFuncImplMode}; use crate::codegen::ir::mir::skip::MirSkip; use crate::codegen::ir::mir::trait_impl::MirTraitImpl; use crate::codegen::ir::mir::ty::enumeration::{MirEnum, MirEnumIdent}; @@ -30,7 +30,7 @@ pub struct MirPack { impl MirPack { pub(crate) fn funcs_with_impl(&self) -> Vec { (self.funcs_all.iter()) - .filter(|f| f.has_impl) + .filter(|f| f.impl_mode == MirFuncImplMode::Normal) .cloned() .collect() } diff --git a/frb_codegen/src/library/codegen/ir/mir/ty/delegate.rs b/frb_codegen/src/library/codegen/ir/mir/ty/delegate.rs index 97dea185a8..9cdf7c7ded 100644 --- a/frb_codegen/src/library/codegen/ir/mir/ty/delegate.rs +++ b/frb_codegen/src/library/codegen/ir/mir/ty/delegate.rs @@ -1,5 +1,5 @@ use crate::codegen::generator::codec::structs::CodecMode; -use crate::codegen::ir::mir::ty::enumeration::MirTypeEnumRef; +use crate::codegen::ir::mir::ty::enumeration::{MirEnumIdent, MirTypeEnumRef}; use crate::codegen::ir::mir::ty::general_list::{mir_list, MirTypeGeneralList}; use crate::codegen::ir::mir::ty::primitive::MirTypePrimitive; use crate::codegen::ir::mir::ty::primitive_list::MirTypePrimitiveList; @@ -7,7 +7,7 @@ use crate::codegen::ir::mir::ty::record::MirTypeRecord; use crate::codegen::ir::mir::ty::rust_auto_opaque_implicit::MirRustAutoOpaqueRaw; use crate::codegen::ir::mir::ty::rust_opaque::MirTypeRustOpaque; use crate::codegen::ir::mir::ty::{MirContext, MirType, MirTypeTrait}; -use crate::utils::namespace::Namespace; +use crate::utils::namespace::{Namespace, NamespacedName}; crate::mir! { /// types that delegate to another type @@ -29,6 +29,8 @@ pub enum MirTypeDelegate { StreamSink(MirTypeDelegateStreamSink), BigPrimitive(MirTypeDelegateBigPrimitive), RustAutoOpaqueExplicit(MirTypeDelegateRustAutoOpaqueExplicit), + ProxyVariant(MirTypeDelegateProxyVariant), + ProxyEnum(MirTypeDelegateProxyEnum), // DynTrait(MirTypeDelegateDynTrait), } @@ -83,6 +85,17 @@ pub struct MirTypeDelegateRustAutoOpaqueExplicit { pub raw: MirRustAutoOpaqueRaw, } +pub struct MirTypeDelegateProxyVariant { + pub inner: Box, + pub upstream: Box, +} + +pub struct MirTypeDelegateProxyEnum { + pub original: Box, + pub delegate_namespace: Namespace, + pub variants: Vec, +} + // pub struct MirTypeDelegateDynTrait { // pub trait_def_name: NamespacedName, // } @@ -131,6 +144,10 @@ impl MirTypeTrait for MirTypeDelegate { MirTypeDelegate::RustAutoOpaqueExplicit(mir) => { format!("AutoExplicit_{}", mir.inner.safe_ident()) } // MirTypeDelegate::DynTrait(mir) => mir.safe_ident(), + MirTypeDelegate::ProxyVariant(mir) => { + format!("ProxyVariant_{}", mir.inner.safe_ident()) + } + MirTypeDelegate::ProxyEnum(mir) => format!("ProxyEnum_{}", mir.get_delegate().safe_ident()), } } @@ -193,6 +210,8 @@ impl MirTypeTrait for MirTypeDelegate { MirTypeDelegate::RustAutoOpaqueExplicit(mir) => { format!("RustAutoOpaque{}<{}>", mir.inner.codec, mir.raw.string) } // MirTypeDelegate::DynTrait(mir) => format!("dyn <{}>", mir.trait_def_name.name), + MirTypeDelegate::ProxyVariant(mir) => mir.inner.rust_api_type(), + MirTypeDelegate::ProxyEnum(mir) => mir.original.rust_api_type(), } } @@ -208,6 +227,7 @@ impl MirTypeTrait for MirTypeDelegate { match self { MirTypeDelegate::PrimitiveEnum(inner) => inner.mir.self_namespace(), MirTypeDelegate::Array(inner) => Some(inner.namespace.clone()), + MirTypeDelegate::ProxyVariant(inner) => inner.inner.self_namespace(), _ => None, } } @@ -261,6 +281,8 @@ impl MirTypeDelegate { MirTypeDelegate::BigPrimitive(_) => MirType::Delegate(MirTypeDelegate::String), MirTypeDelegate::RustAutoOpaqueExplicit(mir) => MirType::RustOpaque(mir.inner.clone()), // MirTypeDelegate::DynTrait(mir) => mir.inner(), + MirTypeDelegate::ProxyVariant(mir) => *mir.inner.clone(), + MirTypeDelegate::ProxyEnum(mir) => mir.get_delegate(), } } } @@ -302,6 +324,23 @@ impl MirTypeDelegateArray { } } +impl MirTypeDelegateProxyEnum { + pub(crate) fn get_delegate(&self) -> MirType { + MirType::EnumRef(MirTypeEnumRef { + ident: MirEnumIdent(NamespacedName::new(self.delegate_namespace.clone(), self.proxy_enum_name())), + is_exception: false, + }) + } + + pub(crate) fn proxy_enum_name(&self) -> String { + Self::proxy_enum_name_raw(&self.original) + } + + pub(crate) fn proxy_enum_name_raw(original_ty: &MirType) -> String { + format!("{}ProxyEnum", original_ty.safe_ident()) + } +} + // impl MirTypeDelegateDynTrait { // pub fn inner(&self) -> MirType { // MirType::EnumRef(self.inner_raw()) diff --git a/frb_codegen/src/library/codegen/ir/mod.rs b/frb_codegen/src/library/codegen/ir/mod.rs index a48f72a5a9..bcd900f4b6 100644 --- a/frb_codegen/src/library/codegen/ir/mod.rs +++ b/frb_codegen/src/library/codegen/ir/mod.rs @@ -1,2 +1,3 @@ +pub(crate) mod early_generator; pub(crate) mod hir; pub(crate) mod mir; diff --git a/frb_codegen/src/library/codegen/parser/early_generator/mod.rs b/frb_codegen/src/library/codegen/parser/early_generator/mod.rs index a3b7ac131f..fe236b05a3 100644 --- a/frb_codegen/src/library/codegen/parser/early_generator/mod.rs +++ b/frb_codegen/src/library/codegen/parser/early_generator/mod.rs @@ -1,27 +1,43 @@ -pub(crate) mod trait_impl_enum; +mod proxy_enum; +mod trait_impl_enum; use crate::codegen::dumper::Dumper; +use crate::codegen::ir::early_generator::pack::IrEarlyGeneratorPack; use crate::codegen::ir::hir::flat::pack::HirFlatPack; use crate::codegen::parser::hir::flat::extra_code_injector::inject_extra_code; -use crate::codegen::parser::hir::internal_config::ParserHirInternalConfig; use crate::codegen::parser::mir; use crate::codegen::parser::mir::internal_config::ParserMirInternalConfig; pub(crate) fn execute( - mut pack: HirFlatPack, + hir_flat_pack: HirFlatPack, config_mir: &ParserMirInternalConfig, dumper: &Dumper, -) -> anyhow::Result { - let dumper_tentative_mir = dumper.with_add_name_prefix("tentative_mir/"); +) -> anyhow::Result { + let mut pack = IrEarlyGeneratorPack { + hir_flat_pack, + ..Default::default() + }; + + let dumper_tentative_mir = dumper.with_add_name_prefix("1_tentative_mir/"); let tentative_mir_pack = mir::parse(config_mir, &pack, &dumper_tentative_mir)?; - let extra_code = trait_impl_enum::generate(&pack, &tentative_mir_pack)?; + trait_impl_enum::generate(&mut pack, &tentative_mir_pack, config_mir)?; + dumper.dump("2_trait_impl_enum.json", &pack)?; - inject_extra_code( - &mut pack, - &extra_code, - &(config_mir.rust_input_namespace_pack).rust_output_path_namespace, - )?; + proxy_enum::generate(&mut pack, &tentative_mir_pack, config_mir)?; + dumper.dump("3_proxy_enum.json", &pack)?; Ok(pack) } + +fn inject_extra_code_to_rust_output( + pack: &mut HirFlatPack, + extra_code: &str, + config_mir: &ParserMirInternalConfig, +) -> anyhow::Result<()> { + inject_extra_code( + pack, + extra_code, + &(config_mir.rust_input_namespace_pack).rust_output_path_namespace, + ) +} diff --git a/frb_codegen/src/library/codegen/parser/early_generator/proxy_enum.rs b/frb_codegen/src/library/codegen/parser/early_generator/proxy_enum.rs new file mode 100644 index 0000000000..d8326d43bc --- /dev/null +++ b/frb_codegen/src/library/codegen/parser/early_generator/proxy_enum.rs @@ -0,0 +1,86 @@ +use crate::codegen::ir::early_generator::pack::IrEarlyGeneratorPack; +use crate::codegen::ir::early_generator::proxied_type::IrEarlyGeneratorProxiedType; +use crate::codegen::ir::hir::flat::pack::HirFlatPack; +use crate::codegen::ir::mir::pack::MirPack; +use crate::codegen::ir::mir::ty::delegate::{ + MirTypeDelegate, MirTypeDelegateProxyEnum, MirTypeDelegateProxyVariant, +}; +use crate::codegen::ir::mir::ty::MirType; +use crate::codegen::parser::early_generator::inject_extra_code_to_rust_output; +use crate::codegen::parser::mir::internal_config::ParserMirInternalConfig; +use crate::codegen::parser::mir::parser::function::real::FUNC_PREFIX_FRB_INTERNAL_NO_IMPL; +use crate::if_then_some; +use crate::library::codegen::ir::mir::ty::MirTypeTrait; +use itertools::Itertools; +use std::collections::HashMap; + +pub(crate) fn generate( + pack: &mut IrEarlyGeneratorPack, + tentative_mir_pack: &MirPack, + config_mir: &ParserMirInternalConfig, +) -> anyhow::Result<()> { + let distinct_types = tentative_mir_pack.distinct_types(None); + let proxy_variants = (distinct_types.iter()) + .filter_map(|ty| if_then_some!(let MirType::Delegate(MirTypeDelegate::ProxyVariant(inner)) = ty, inner.clone())) + .collect_vec(); + + let proxy_variants_of_enum = + (proxy_variants.iter()).into_group_map_by(|ty| ty.upstream.safe_ident()); + + let proxied_types = compute_proxied_types(&proxy_variants_of_enum, config_mir); + + let extra_code = proxy_variants_of_enum + .into_values() + .map(|proxy_variants| generate_proxy_enum(&proxy_variants)) + .join(""); + + inject_extra_code_to_rust_output(&mut pack.hir_flat_pack, &extra_code, config_mir)?; + (pack.proxied_types).extend(proxied_types); + + Ok(()) +} + +fn compute_proxied_types( + proxy_variants_of_enum: &HashMap>, + config_mir: &ParserMirInternalConfig, +) -> Vec { + (proxy_variants_of_enum.values()) + .map(|variants| { + let proxy_enum_namespace = config_mir + .rust_input_namespace_pack + .rust_output_path_namespace + .clone(); + + IrEarlyGeneratorProxiedType { + proxy_enum_namespace, + original_ty: (*variants[0].inner).to_owned(), + variants: variants.iter().map(|&x| x.to_owned()).collect_vec(), + } + }) + .collect_vec() +} + +fn generate_proxy_enum(proxy_variants: &[&MirTypeDelegateProxyVariant]) -> String { + let proxy_enum_ty = *proxy_variants[0].inner.clone(); + + let enum_name = MirTypeDelegateProxyEnum::proxy_enum_name_raw(&proxy_enum_ty); + + let variants = (proxy_variants.iter().enumerate()) + .map(|(index, variant)| { + format!( + "Variant{index}(RustAutoOpaque<{}>),\n", + &variant.upstream.rust_api_type() + ) + }) + .join(""); + + format!( + " + enum {enum_name} {{ + {variants} + }} + + pub fn {FUNC_PREFIX_FRB_INTERNAL_NO_IMPL}_dummy_function_{enum_name}(a: {enum_name}) {{ }} + " + ) +} diff --git a/frb_codegen/src/library/codegen/parser/early_generator/trait_impl_enum.rs b/frb_codegen/src/library/codegen/parser/early_generator/trait_impl_enum.rs index 41848178a2..c1e63d8468 100644 --- a/frb_codegen/src/library/codegen/parser/early_generator/trait_impl_enum.rs +++ b/frb_codegen/src/library/codegen/parser/early_generator/trait_impl_enum.rs @@ -3,20 +3,22 @@ use crate::codegen::ir::hir::flat::traits::HirFlatTrait; use crate::codegen::ir::mir::pack::MirPack; use crate::codegen::ir::mir::trait_impl::MirTraitImpl; use crate::codegen::ir::mir::ty::MirType; -use crate::codegen::parser::hir::flat::extra_code_injector::inject_extra_code; -use crate::codegen::parser::hir::internal_config::ParserHirInternalConfig; +use crate::codegen::parser::early_generator::inject_extra_code_to_rust_output; +use crate::codegen::parser::mir::internal_config::ParserMirInternalConfig; use crate::codegen::parser::mir::parser::attribute::FrbAttributes; use crate::codegen::parser::mir::parser::function::real::FUNC_PREFIX_FRB_INTERNAL_NO_IMPL; use crate::library::codegen::ir::mir::ty::MirTypeTrait; use convert_case::{Case, Casing}; use itertools::Itertools; use strum_macros::Display; +use crate::codegen::ir::early_generator::pack::IrEarlyGeneratorPack; pub(crate) fn generate( - pack: &HirFlatPack, + pack: &mut IrEarlyGeneratorPack, tentative_mir_pack: &MirPack, -) -> anyhow::Result { - Ok((pack.traits.iter()) + config_mir: &ParserMirInternalConfig, +) -> anyhow::Result<()> { + let extra_code = (pack.hir_flat_pack.traits.iter()) .filter(|x| { FrbAttributes::parse(&x.attrs) .unwrap() @@ -26,7 +28,11 @@ pub(crate) fn generate( .map(|x| generate_trait_impl_enum(x, &tentative_mir_pack.trait_impls)) .collect::>>()? .into_iter() - .join("")) + .join(""); + + inject_extra_code_to_rust_output(&mut pack.hir_flat_pack, &extra_code, config_mir)?; + + Ok(()) } fn generate_trait_impl_enum( diff --git a/frb_codegen/src/library/codegen/parser/hir/flat/mod.rs b/frb_codegen/src/library/codegen/parser/hir/flat/mod.rs index 2da7e81465..0d2334c8f1 100644 --- a/frb_codegen/src/library/codegen/parser/hir/flat/mod.rs +++ b/frb_codegen/src/library/codegen/parser/hir/flat/mod.rs @@ -14,28 +14,28 @@ pub(crate) fn parse( dumper: &Dumper, ) -> anyhow::Result { let pack = parser::pack::parse_pack(config, hir_naive_flat)?; - dumper.dump("1_parse_pack", &pack)?; + dumper.dump("1_parse_pack.json", &pack)?; let pack = transformer::filter_transformer::transform(pack, config)?; - dumper.dump("2_filter_transformer", &pack)?; + dumper.dump("2_filter_transformer.json", &pack)?; let pack = transformer::remove_not_defined_trait_transformer::transform(pack)?; - dumper.dump("3_remove_not_defined_trait_transformer", &pack)?; + dumper.dump("3_remove_not_defined_trait_transformer.json", &pack)?; let pack = transformer::copy_trait_def_to_impl_transformer::transform(pack)?; - dumper.dump("4_copy_trait_def_to_impl_transformer", &pack)?; + dumper.dump("4_copy_trait_def_to_impl_transformer.json", &pack)?; let pack = transformer::function_frb_override_transformer::transform(pack)?; - dumper.dump("5_function_frb_override_transformer", &pack)?; + dumper.dump("5_function_frb_override_transformer.json", &pack)?; let pack = transformer::merge_duplicate_transformer::transform(pack)?; - dumper.dump("6_merge_duplicate_transformer", &pack)?; + dumper.dump("6_merge_duplicate_transformer.json", &pack)?; let pack = transformer::resolve_type_alias_transformer::transform(pack)?; - dumper.dump("7_resolve_type_alias_transformer", &pack)?; + dumper.dump("7_resolve_type_alias_transformer.json", &pack)?; let pack = transformer::sort_transformer::transform(pack)?; - dumper.dump("8_sort_transformer", &pack)?; + dumper.dump("8_sort_transformer.json", &pack)?; Ok(pack) } diff --git a/frb_codegen/src/library/codegen/parser/hir/naive_flat/mod.rs b/frb_codegen/src/library/codegen/parser/hir/naive_flat/mod.rs index 37ea14f0d6..d546e2a9da 100644 --- a/frb_codegen/src/library/codegen/parser/hir/naive_flat/mod.rs +++ b/frb_codegen/src/library/codegen/parser/hir/naive_flat/mod.rs @@ -12,13 +12,13 @@ pub(crate) fn parse( dumper: &Dumper, ) -> anyhow::Result { let pack = parser::parse(hir_tree)?; - dumper.dump("1_parse_pack", &pack)?; + dumper.dump("1_parse_pack.json", &pack)?; let pack = transformer::move_third_party_override_transformer::transform(pack)?; - dumper.dump("2_move_third_party_override_transformer", &pack)?; + dumper.dump("2_move_third_party_override_transformer.json", &pack)?; let pack = transformer::filter_transformer::transform(pack, config)?; - dumper.dump("3_filter_transformer", &pack)?; + dumper.dump("3_filter_transformer.json", &pack)?; Ok(pack) } diff --git a/frb_codegen/src/library/codegen/parser/mir/mod.rs b/frb_codegen/src/library/codegen/parser/mir/mod.rs index a388188c0e..a829eb9016 100644 --- a/frb_codegen/src/library/codegen/parser/mir/mod.rs +++ b/frb_codegen/src/library/codegen/parser/mir/mod.rs @@ -1,4 +1,5 @@ use crate::codegen::dumper::Dumper; +use crate::codegen::ir::early_generator::pack::IrEarlyGeneratorPack; use crate::codegen::ir::hir::flat::pack::HirFlatPack; use crate::codegen::ir::mir::pack::MirPack; use crate::codegen::parser::mir::internal_config::ParserMirInternalConfig; @@ -10,14 +11,14 @@ pub(crate) mod transformer; pub(crate) fn parse( config: &ParserMirInternalConfig, - hir_flat: &HirFlatPack, + ir_pack: &IrEarlyGeneratorPack, dumper: &Dumper, ) -> anyhow::Result { - let pack = parser::parse(config, hir_flat)?; - dumper.dump("1_parse_pack", &pack)?; + let pack = parser::parse(config, ir_pack)?; + dumper.dump("1_parse_pack.json", &pack)?; let pack = transformer::filter_trait_impl_transformer::transform(pack)?; - dumper.dump("2_filter_trait_impl_transformer", &pack)?; + dumper.dump("2_filter_trait_impl_transformer.json", &pack)?; // let pack = transformer::dyn_trait_inner_transformer::transform(pack)?; // dump(dumper, "3_dyn_trait_inner_transformer", &pack)?; diff --git a/frb_codegen/src/library/codegen/parser/mir/parser/attribute.rs b/frb_codegen/src/library/codegen/parser/mir/parser/attribute.rs index 7a1c3dd135..d33eb21c1d 100644 --- a/frb_codegen/src/library/codegen/parser/mir/parser/attribute.rs +++ b/frb_codegen/src/library/codegen/parser/mir/parser/attribute.rs @@ -107,6 +107,10 @@ impl FrbAttributes { self.any_eq(&FrbAttribute::Positional) } + pub(crate) fn proxy(&self) -> bool { + self.any_eq(&FrbAttribute::Proxy) + } + pub(crate) fn external(&self) -> bool { self.any_eq(&FrbAttribute::External) } @@ -194,6 +198,7 @@ mod frb_keyword { syn::custom_keyword!(non_hash); syn::custom_keyword!(non_eq); syn::custom_keyword!(positional); + syn::custom_keyword!(proxy); syn::custom_keyword!(external); syn::custom_keyword!(generate_implementor_enum); syn::custom_keyword!(rust_opaque_codec_moi); @@ -233,6 +238,7 @@ enum FrbAttribute { NonHash, NonEq, Positional, + Proxy, External, GenerateImplEnum, RustOpaqueCodecMoi, @@ -271,6 +277,7 @@ impl Parse for FrbAttribute { .or_else(|| parse_keyword::(input, &lookahead, non_hash, NonHash)) .or_else(|| parse_keyword::(input, &lookahead, non_eq, NonEq)) .or_else(|| parse_keyword::(input, &lookahead, positional, Positional)) + .or_else(|| parse_keyword::(input, &lookahead, proxy, Proxy)) .or_else(|| parse_keyword::(input, &lookahead, external, External)) .or_else(|| { parse_keyword::( @@ -670,6 +677,11 @@ mod tests { simple_keyword_tester("positional", FrbAttribute::Positional); } + #[test] + fn test_proxy() { + simple_keyword_tester("positional", FrbAttribute::Proxy); + } + #[test] fn test_external() { simple_keyword_tester("external", FrbAttribute::External); diff --git a/frb_codegen/src/library/codegen/parser/mir/parser/function/auto_accessor/field.rs b/frb_codegen/src/library/codegen/parser/mir/parser/function/auto_accessor/field.rs index 751a01be84..16586a6a7f 100644 --- a/frb_codegen/src/library/codegen/parser/mir/parser/function/auto_accessor/field.rs +++ b/frb_codegen/src/library/codegen/parser/mir/parser/function/auto_accessor/field.rs @@ -1,7 +1,8 @@ use crate::codegen::ir::mir::field::MirField; use crate::codegen::ir::mir::func::{ - MirFunc, MirFuncAccessorMode, MirFuncArgMode, MirFuncInput, MirFuncMode, MirFuncOutput, - MirFuncOwnerInfo, MirFuncOwnerInfoMethod, MirFuncOwnerInfoMethodMode, OwnershipMode, + MirFunc, MirFuncAccessorMode, MirFuncArgMode, MirFuncImplMode, MirFuncInput, MirFuncMode, + MirFuncOutput, MirFuncOwnerInfo, MirFuncOwnerInfoMethod, MirFuncOwnerInfoMethodMode, + OwnershipMode, }; use crate::codegen::ir::mir::ident::MirIdent; use crate::codegen::ir::mir::ty::primitive::MirTypePrimitive; @@ -86,7 +87,7 @@ pub(super) fn parse_auto_accessor_of_field( &config.force_codec_mode_pack, ), rust_call_code: Some(rust_call_code), - has_impl: true, + impl_mode: MirFuncImplMode::Normal, src_lineno_pseudo: compute_src_lineno_pseudo(struct_name, field), }; diff --git a/frb_codegen/src/library/codegen/parser/mir/parser/function/real/argument.rs b/frb_codegen/src/library/codegen/parser/mir/parser/function/real/argument.rs index c97bf71e97..bed040b50c 100644 --- a/frb_codegen/src/library/codegen/parser/mir/parser/function/real/argument.rs +++ b/frb_codegen/src/library/codegen/parser/mir/parser/function/real/argument.rs @@ -3,6 +3,7 @@ use crate::codegen::ir::mir::func::{MirFuncInput, MirFuncOwnerInfo}; use crate::codegen::ir::mir::func::{MirFuncOwnerInfoMethod, OwnershipMode}; use crate::codegen::ir::mir::ident::MirIdent; use crate::codegen::ir::mir::ty::boxed::MirTypeBoxed; +use crate::codegen::ir::mir::ty::delegate::{MirTypeDelegate, MirTypeDelegateProxyEnum}; use crate::codegen::ir::mir::ty::MirType; use crate::codegen::ir::mir::ty::MirType::Boxed; use crate::codegen::parser::mir::parser::attribute::FrbAttributes; @@ -51,6 +52,8 @@ impl<'a, 'b> FunctionParser<'a, 'b> { ownership_mode_split, )?; + let ty = parse_maybe_proxy_enum(ty, self.type_parser)?; + if ty.should_ignore(self.type_parser) { return Ok(FunctionPartialInfo { ignore_func: true, @@ -60,7 +63,9 @@ impl<'a, 'b> FunctionParser<'a, 'b> { let attrs = parse_attrs_from_fn_arg(sig_input); let attributes = FrbAttributes::parse(attrs)?; + let ty = auto_add_boxed(ty); + Ok(FunctionPartialInfo { inputs: vec![MirFuncInput { inner: MirField { @@ -161,3 +166,17 @@ fn parse_attrs_from_fn_arg(fn_arg: &FnArg) -> &[Attribute] { FnArg::Receiver(inner) => &inner.attrs, } } + +fn parse_maybe_proxy_enum(ty: MirType, type_parser: &TypeParser) -> anyhow::Result { + if let Some(proxied_type) = (type_parser.proxied_types.iter()).find(|x| x.original_ty == ty) { + return Ok(MirType::Delegate(MirTypeDelegate::ProxyEnum( + MirTypeDelegateProxyEnum { + original: Box::new(ty), + delegate_namespace: proxied_type.proxy_enum_namespace.clone(), + variants: proxied_type.variants.clone(), + }, + ))); + } + + Ok(ty) +} diff --git a/frb_codegen/src/library/codegen/parser/mir/parser/function/real/mod.rs b/frb_codegen/src/library/codegen/parser/mir/parser/function/real/mod.rs index cb3eb4f226..228e27785c 100644 --- a/frb_codegen/src/library/codegen/parser/mir/parser/function/real/mod.rs +++ b/frb_codegen/src/library/codegen/parser/mir/parser/function/real/mod.rs @@ -2,8 +2,8 @@ use crate::codegen::generator::codec::structs::{CodecMode, CodecModePack}; use crate::codegen::ir::hir::flat::function::HirFlatFunction; use crate::codegen::ir::hir::flat::function::HirFlatFunctionOwner; use crate::codegen::ir::mir::func::{ - MirFunc, MirFuncArgMode, MirFuncInput, MirFuncMode, MirFuncOutput, MirFuncOwnerInfo, - MirFuncOwnerInfoMethod, MirFuncOwnerInfoMethodMode, + MirFunc, MirFuncArgMode, MirFuncImplMode, MirFuncImplModeDartOnly, MirFuncInput, MirFuncMode, + MirFuncOutput, MirFuncOwnerInfo, MirFuncOwnerInfoMethod, MirFuncOwnerInfoMethodMode, }; use crate::codegen::ir::mir::skip::MirSkipReason::IgnoredFunctionGeneric; use crate::codegen::ir::mir::skip::{MirSkip, MirSkipReason}; @@ -149,7 +149,8 @@ impl<'a, 'b> FunctionParser<'a, 'b> { info = info.merge(self.parse_fn_arg(sig_input, &owner, &context, is_owner_trait_def)?)?; } - info = info.merge(self.parse_fn_output(func.item_fn.sig(), &context)?)?; + info = + info.merge(self.parse_fn_output(func.item_fn.sig(), &owner, &context, &attributes)?)?; info = self.transform_fn_info(info); let codec_mode_pack = compute_codec_mode_pack(&attributes, force_codec_mode_pack); @@ -157,8 +158,12 @@ impl<'a, 'b> FunctionParser<'a, 'b> { let stream_dart_await = attributes.stream_dart_await() && !attributes.sync(); let namespace_refined = refine_namespace(&owner).unwrap_or(func.namespace.clone()); - let has_impl = - !is_owner_trait_def && !func_name.starts_with(FUNC_PREFIX_FRB_INTERNAL_NO_IMPL); + let output = MirFuncOutput { + normal: info.ok_output.unwrap_or(Primitive(MirTypePrimitive::Unit)), + error: info.error_output, + }; + + let impl_mode = compute_impl_mode(is_owner_trait_def, &func_name, &attributes, &output); if info.ignore_func { return Ok(create_output_skip(func, IgnoredMisc)); @@ -169,10 +174,7 @@ impl<'a, 'b> FunctionParser<'a, 'b> { dart_name, id: None, // to be filled later inputs: info.inputs, - output: MirFuncOutput { - normal: info.ok_output.unwrap_or(Primitive(MirTypePrimitive::Unit)), - error: info.error_output, - }, + output, owner, mode, stream_dart_await, @@ -187,7 +189,7 @@ impl<'a, 'b> FunctionParser<'a, 'b> { comments: parse_comments(func.item_fn.attrs()), codec_mode_pack, rust_call_code: None, - has_impl, + impl_mode, src_lineno_pseudo: src_lineno, })) } @@ -397,3 +399,24 @@ pub(crate) fn is_struct_or_enum_or_opaque_from_them(ty: &MirType) -> bool { } pub(crate) const FUNC_PREFIX_FRB_INTERNAL_NO_IMPL: &str = "frb_internal_no_impl"; + +fn compute_impl_mode( + is_owner_trait_def: bool, + func_name: &String, + attributes: &FrbAttributes, + output: &MirFuncOutput, +) -> MirFuncImplMode { + if is_owner_trait_def || func_name.starts_with(FUNC_PREFIX_FRB_INTERNAL_NO_IMPL) { + return MirFuncImplMode::NoImpl; + } + + if attributes.proxy() { + if let MirType::Delegate(MirTypeDelegate::ProxyVariant(inner)) = &output.normal { + return MirFuncImplMode::DartOnly(MirFuncImplModeDartOnly::CreateProxyVariant( + inner.clone(), + )); + } + } + + MirFuncImplMode::Normal +} diff --git a/frb_codegen/src/library/codegen/parser/mir/parser/function/real/output.rs b/frb_codegen/src/library/codegen/parser/mir/parser/function/real/output.rs index d1dd0111aa..3775c2fe2d 100644 --- a/frb_codegen/src/library/codegen/parser/mir/parser/function/real/output.rs +++ b/frb_codegen/src/library/codegen/parser/mir/parser/function/real/output.rs @@ -1,21 +1,26 @@ -use crate::codegen::ir::mir::func::OwnershipMode; +use crate::codegen::ir::mir::func::{MirFuncOwnerInfo, OwnershipMode}; +use crate::codegen::ir::mir::ty::delegate::{MirTypeDelegate, MirTypeDelegateProxyVariant}; use crate::codegen::ir::mir::ty::primitive::MirTypePrimitive; use crate::codegen::ir::mir::ty::rust_auto_opaque_implicit::MirTypeRustAutoOpaqueImplicit; use crate::codegen::ir::mir::ty::MirType; +use crate::codegen::parser::mir::parser::attribute::FrbAttributes; use crate::codegen::parser::mir::parser::function::real::{FunctionParser, FunctionPartialInfo}; use crate::codegen::parser::mir::parser::ty::result::parse_type_maybe_result; use crate::codegen::parser::mir::parser::ty::TypeParserParsingContext; +use anyhow::bail; use syn::*; impl<'a, 'b> FunctionParser<'a, 'b> { pub(super) fn parse_fn_output( &mut self, sig: &Signature, + owner: &MirFuncOwnerInfo, context: &TypeParserParsingContext, + attributes: &FrbAttributes, ) -> anyhow::Result { Ok(match &sig.output { ReturnType::Type(_, ty) => remove_reference_type(remove_primitive_unit( - self.parse_fn_output_type(ty, context)?, + self.parse_fn_output_type(ty, owner, context, attributes)?, )), ReturnType::Default => Default::default(), }) @@ -25,9 +30,12 @@ impl<'a, 'b> FunctionParser<'a, 'b> { fn parse_fn_output_type( &mut self, ty: &Type, + owner: &MirFuncOwnerInfo, context: &TypeParserParsingContext, + attributes: &FrbAttributes, ) -> anyhow::Result { let mir = self.type_parser.parse_type(ty, context)?; + let mir = parse_maybe_proxy_return_type(mir, owner, attributes)?; let info = parse_type_maybe_result(&mir, self.type_parser, context)?; Ok(FunctionPartialInfo { ok_output: Some(info.ok_output), @@ -64,3 +72,33 @@ fn remove_reference_type(info: FunctionPartialInfo) -> FunctionPartialInfo { } info } + +fn parse_maybe_proxy_return_type( + mir: MirType, + owner: &MirFuncOwnerInfo, + attributes: &FrbAttributes, +) -> anyhow::Result { + if attributes.proxy() { + parse_proxy_return_type(mir, owner) + } else { + Ok(mir) + } +} + +fn parse_proxy_return_type(mir: MirType, owner: &MirFuncOwnerInfo) -> anyhow::Result { + if let MirType::RustAutoOpaqueImplicit(mir_inner) = &mir { + if mir_inner.ownership_mode == OwnershipMode::Ref + || mir_inner.ownership_mode == OwnershipMode::RefMut + { + if let MirFuncOwnerInfo::Method(method) = owner { + return Ok(MirType::Delegate(MirTypeDelegate::ProxyVariant( + MirTypeDelegateProxyVariant { + inner: Box::new(mir), + upstream: Box::new(method.owner_ty.clone()), + }, + ))); + } + } + } + bail!("This return type is not currently compatible with `#[frb(proxy)]` yet") +} diff --git a/frb_codegen/src/library/codegen/parser/mir/parser/mod.rs b/frb_codegen/src/library/codegen/parser/mir/parser/mod.rs index ad9e707b4e..3f17a04748 100644 --- a/frb_codegen/src/library/codegen/parser/mir/parser/mod.rs +++ b/frb_codegen/src/library/codegen/parser/mir/parser/mod.rs @@ -4,6 +4,7 @@ pub(crate) mod misc; pub(crate) mod trait_impl; pub(crate) mod ty; +use crate::codegen::ir::early_generator::pack::IrEarlyGeneratorPack; use crate::codegen::ir::hir::flat::pack::HirFlatPack; use crate::codegen::ir::mir::pack::MirPack; use crate::codegen::parser::mir::internal_config::ParserMirInternalConfig; @@ -13,12 +14,13 @@ use crate::codegen::parser::mir::sanity_checker::unused_checker::get_unused_type pub(crate) fn parse( config: &ParserMirInternalConfig, - hir_flat: &HirFlatPack, + ir_pack: &IrEarlyGeneratorPack, ) -> anyhow::Result { + let hir_flat = &ir_pack.hir_flat_pack; let structs_map = hir_flat.structs_map(); let enums_map = hir_flat.enums_map(); - let mut type_parser = TypeParser::new_from_hir_flat_pack(hir_flat); + let mut type_parser = TypeParser::new_from_pack(ir_pack); let trait_impls = trait_impl::parse( &hir_flat.trait_impls, diff --git a/frb_codegen/src/library/codegen/parser/mir/parser/ty/mod.rs b/frb_codegen/src/library/codegen/parser/mir/parser/ty/mod.rs index 83435a1f4f..ff968c8d5a 100644 --- a/frb_codegen/src/library/codegen/parser/mir/parser/ty/mod.rs +++ b/frb_codegen/src/library/codegen/parser/mir/parser/ty/mod.rs @@ -1,4 +1,5 @@ use crate::codegen::generator::codec::structs::CodecMode; +use crate::codegen::ir::early_generator::pack::IrEarlyGeneratorPack; use crate::codegen::ir::hir::flat::pack::HirFlatPack; use crate::codegen::ir::hir::flat::struct_or_enum::HirFlatEnum; use crate::codegen::ir::hir::flat::struct_or_enum::HirFlatStruct; @@ -19,6 +20,7 @@ use crate::codegen::parser::mir::parser::ty::rust_opaque::RustOpaqueParserInfo; use crate::utils::namespace::Namespace; use std::collections::HashMap; use syn::Type; +use crate::codegen::ir::early_generator::proxied_type::IrEarlyGeneratorProxiedType; pub(crate) mod array; pub(crate) mod concrete; @@ -49,6 +51,7 @@ pub(crate) struct TypeParser<'a> { src_enums: HashMap, pub(super) src_traits: HashMap, src_types: HashMap, + pub(super) proxied_types: Vec, dart_code_of_type: HashMap, struct_parser_info: EnumOrStructParserInfo, enum_parser_info: EnumOrStructParserInfo, @@ -58,12 +61,13 @@ pub(crate) struct TypeParser<'a> { } impl<'a> TypeParser<'a> { - pub(crate) fn new_from_hir_flat_pack(hir_flat: &'a HirFlatPack) -> Self { + pub(crate) fn new_from_pack(ir_pack: &'a IrEarlyGeneratorPack) -> Self { Self::new( - hir_flat.structs_map(), - hir_flat.enums_map(), - hir_flat.traits_map(), - hir_flat.types_map(), + ir_pack.hir_flat_pack.structs_map(), + ir_pack.hir_flat_pack.enums_map(), + ir_pack.hir_flat_pack.traits_map(), + ir_pack.hir_flat_pack.types_map(), + ir_pack.proxied_types.clone(), ) } @@ -72,12 +76,14 @@ impl<'a> TypeParser<'a> { src_enums: HashMap, src_traits: HashMap, src_types: HashMap, + proxied_types: Vec, ) -> Self { TypeParser { src_structs, src_enums, src_traits, src_types, + proxied_types, dart_code_of_type: HashMap::new(), struct_parser_info: EnumOrStructParserInfo::new(), enum_parser_info: EnumOrStructParserInfo::new(), diff --git a/frb_codegen/src/library/codegen/parser/mir/parser/ty/ty.rs b/frb_codegen/src/library/codegen/parser/mir/parser/ty/ty.rs index 60357d2fcf..ff0ae44f2a 100644 --- a/frb_codegen/src/library/codegen/parser/mir/parser/ty/ty.rs +++ b/frb_codegen/src/library/codegen/parser/mir/parser/ty/ty.rs @@ -1,3 +1,4 @@ +use crate::codegen::ir::mir::ty::delegate::{MirTypeDelegate, MirTypeDelegateProxyEnum}; use crate::codegen::ir::mir::ty::MirType; use crate::codegen::parser::mir::parser::ty::misc::convert_ident_str; use crate::codegen::parser::mir::parser::ty::TypeParserWithContext; @@ -7,8 +8,11 @@ use syn::Type; impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { pub(crate) fn parse_type(&mut self, ty: &Type) -> anyhow::Result { let resolve_ty = self.resolve_alias(ty); + self.parse_type_inner(&resolve_ty) + } - Ok(match resolve_ty.clone() { + fn parse_type_inner(&mut self, ty: &Type) -> anyhow::Result { + Ok(match ty.clone() { Type::Path(x) => self.parse_type_path(&x)?, Type::Array(x) => self.parse_type_array(&x)?, Type::Slice(x) => self.parse_type_slice(&x)?, @@ -17,7 +21,7 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> { Type::ImplTrait(x) => self .parse_type_impl_trait_dart_fn(&x) .context("when trying to parse DartFn")?, - _ => self.parse_type_rust_auto_opaque_implicit(None, &resolve_ty, None, None)?, + _ => self.parse_type_rust_auto_opaque_implicit(None, &ty, None, None)?, }) } diff --git a/frb_codegen/src/library/codegen/parser/mod.rs b/frb_codegen/src/library/codegen/parser/mod.rs index b8696ca780..8e8bbd1085 100644 --- a/frb_codegen/src/library/codegen/parser/mod.rs +++ b/frb_codegen/src/library/codegen/parser/mod.rs @@ -41,12 +41,12 @@ fn parse_inner( let hir_tree = hir::tree::parse(&config.hir, hir_raw, &dumper_hir_tree)?; let hir_naive_flat = hir::naive_flat::parse(&config.hir, hir_tree, &dumper_hir_naive_flat)?; let hir_flat = hir::flat::parse(&config.hir, hir_naive_flat, &dumper_hir_flat)?; - let hir_flat = early_generator::execute(hir_flat, &config.mir, &dumper_early_generator)?; on_hir_flat(&hir_flat)?; + let ir_early_generator = early_generator::execute(hir_flat, &config.mir, &dumper_early_generator)?; drop(pb); let pb = progress_bar_pack.parse_mir.start(); - let mir_pack = mir::parse(&config.mir, &hir_flat, &dumper_mir)?; + let mir_pack = mir::parse(&config.mir, &ir_early_generator, &dumper_mir)?; drop(pb); Ok(mir_pack) diff --git a/frb_dart/lib/flutter_rust_bridge_for_generated_common.dart b/frb_dart/lib/flutter_rust_bridge_for_generated_common.dart index bf8eec4e4b..a335de7425 100644 --- a/frb_dart/lib/flutter_rust_bridge_for_generated_common.dart +++ b/frb_dart/lib/flutter_rust_bridge_for_generated_common.dart @@ -25,6 +25,7 @@ export 'src/main_components/wire.dart'; export 'src/manual_impl/_common.dart'; export 'src/misc/box.dart'; export 'src/misc/rust_opaque.dart'; +export 'src/misc/simple_disposable.dart'; export 'src/rust_arc/_common.dart'; export 'src/stream/stream_sink.dart'; export 'src/task.dart'; diff --git a/frb_dart/lib/src/misc/simple_disposable.dart b/frb_dart/lib/src/misc/simple_disposable.dart new file mode 100644 index 0000000000..10d5eb7bc5 --- /dev/null +++ b/frb_dart/lib/src/misc/simple_disposable.dart @@ -0,0 +1,11 @@ +/// {@macro flutter_rust_bridge.only_for_generated_code} +mixin SimpleDisposable { + /// {@macro flutter_rust_bridge.only_for_generated_code} + void dispose() { + _isDisposed = true; + } + + /// {@macro flutter_rust_bridge.only_for_generated_code} + bool get isDisposed => _isDisposed; + bool _isDisposed = false; +} diff --git a/frb_example/dart_minimal/lib/src/rust/api/minimal.dart b/frb_example/dart_minimal/lib/src/rust/api/minimal.dart index 3e1fb0dcd2..799a44b231 100644 --- a/frb_example/dart_minimal/lib/src/rust/api/minimal.dart +++ b/frb_example/dart_minimal/lib/src/rust/api/minimal.dart @@ -6,5 +6,12 @@ import '../frb_generated.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; -Future minimalAdder({required int a, required int b}) => - RustLib.instance.api.crateApiMinimalMinimalAdder(a: a, b: b); +// Rust type: RustOpaqueMoi> +abstract class MyAudioParam implements RustOpaqueInterface { + Future myMethod(); +} + +// Rust type: RustOpaqueMoi> +abstract class MyNode implements RustOpaqueInterface { + Future paramOne(); +} diff --git a/frb_example/dart_minimal/lib/src/rust/frb_generated.dart b/frb_example/dart_minimal/lib/src/rust/frb_generated.dart index 785cd5eea1..293d977599 100644 --- a/frb_example/dart_minimal/lib/src/rust/frb_generated.dart +++ b/frb_example/dart_minimal/lib/src/rust/frb_generated.dart @@ -2,6 +2,10 @@ // Generated by `flutter_rust_bridge`@ 2.0.0-dev.37. // ignore_for_file: unused_import, unused_element, unnecessary_import, duplicate_ignore, invalid_use_of_internal_member, annotate_overrides, non_constant_identifier_names, curly_braces_in_flow_control_structures, prefer_const_literals_to_create_immutables, unused_field +// This file is automatically generated, so please do not edit it. +// Generated by `flutter_rust_bridge`@ 2.0.0-dev.37. + +// ignore_for_file: invalid_use_of_internal_member, unused_import, unnecessary_import import 'api/minimal.dart'; import 'dart:async'; @@ -9,6 +13,8 @@ import 'dart:convert'; import 'frb_generated.dart'; import 'frb_generated.io.dart' if (dart.library.html) 'frb_generated.web.dart'; import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart'; +import 'package:freezed_annotation/freezed_annotation.dart' hide protected; +part 'frb_generated.freezed.dart'; /// Main entrypoint of the Rust API class RustLib extends BaseEntrypoint { @@ -45,9 +51,7 @@ class RustLib extends BaseEntrypoint { RustLibWire.fromExternalLibrary; @override - Future executeRustInitializers() async { - await api.crateApiMinimalInitApp(); - } + Future executeRustInitializers() async {} @override ExternalLibraryLoaderConfig get defaultExternalLibraryLoaderConfig => @@ -57,7 +61,7 @@ class RustLib extends BaseEntrypoint { String get codegenVersion => '2.0.0-dev.37'; @override - int get rustContentHash => -2119384465; + int get rustContentHash => 382423683; static const kDefaultExternalLibraryLoaderConfig = ExternalLibraryLoaderConfig( @@ -68,9 +72,22 @@ class RustLib extends BaseEntrypoint { } abstract class RustLibApi extends BaseApi { - Future crateApiMinimalInitApp(); + Future crateApiMinimalMyAudioParamMyMethod( + {required MyAudioParam that}); + + RustArcIncrementStrongCountFnType + get rust_arc_increment_strong_count_MyAudioParam; + + RustArcDecrementStrongCountFnType + get rust_arc_decrement_strong_count_MyAudioParam; + + CrossPlatformFinalizerArg get rust_arc_decrement_strong_count_MyAudioParamPtr; + + RustArcIncrementStrongCountFnType get rust_arc_increment_strong_count_MyNode; - Future crateApiMinimalMinimalAdder({required int a, required int b}); + RustArcDecrementStrongCountFnType get rust_arc_decrement_strong_count_MyNode; + + CrossPlatformFinalizerArg get rust_arc_decrement_strong_count_MyNodePtr; } class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { @@ -82,56 +99,162 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { }); @override - Future crateApiMinimalInitApp() { + Future crateApiMinimalMyAudioParamMyMethod( + {required MyAudioParam that}) { return handler.executeNormal(NormalTask( callFfi: (port_) { final serializer = SseSerializer(generalizedFrbRustBinding); + sse_encode_ProxyEnum_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + that, serializer); pdeCallFfi(generalizedFrbRustBinding, serializer, funcId: 1, port: port_); }, codec: SseCodec( - decodeSuccessData: sse_decode_unit, + decodeSuccessData: sse_decode_String, decodeErrorData: null, ), - constMeta: kCrateApiMinimalInitAppConstMeta, - argValues: [], + constMeta: kCrateApiMinimalMyAudioParamMyMethodConstMeta, + argValues: [that], apiImpl: this, )); } - TaskConstMeta get kCrateApiMinimalInitAppConstMeta => const TaskConstMeta( - debugName: "init_app", - argNames: [], + TaskConstMeta get kCrateApiMinimalMyAudioParamMyMethodConstMeta => + const TaskConstMeta( + debugName: "MyAudioParam_my_method", + argNames: ["that"], ); - @override - Future crateApiMinimalMinimalAdder({required int a, required int b}) { - return handler.executeNormal(NormalTask( - callFfi: (port_) { - final serializer = SseSerializer(generalizedFrbRustBinding); - sse_encode_i_32(a, serializer); - sse_encode_i_32(b, serializer); - pdeCallFfi(generalizedFrbRustBinding, serializer, - funcId: 2, port: port_); - }, - codec: SseCodec( - decodeSuccessData: sse_decode_i_32, - decodeErrorData: null, - ), - constMeta: kCrateApiMinimalMinimalAdderConstMeta, - argValues: [a, b], - apiImpl: this, - )); + RustArcIncrementStrongCountFnType + get rust_arc_increment_strong_count_MyAudioParam => wire + .rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam; + + RustArcDecrementStrongCountFnType + get rust_arc_decrement_strong_count_MyAudioParam => wire + .rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam; + + RustArcIncrementStrongCountFnType + get rust_arc_increment_strong_count_MyNode => wire + .rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode; + + RustArcDecrementStrongCountFnType + get rust_arc_decrement_strong_count_MyNode => wire + .rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode; + + @protected + MyNode + dco_decode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return dco_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + raw); } - TaskConstMeta get kCrateApiMinimalMinimalAdderConstMeta => - const TaskConstMeta( - debugName: "minimal_adder", - argNames: ["a", "b"], - ); + @protected + MyAudioParam + dco_decode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return MyAudioParamImpl.frbInternalDcoDecode(raw as List); + } + + @protected + MyNode + dco_decode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return MyNodeImpl.frbInternalDcoDecode(raw as List); + } + + @protected + MyAudioParam + dco_decode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return MyAudioParamImpl.frbInternalDcoDecode(raw as List); + } + + @protected + MyNode + dco_decode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return MyNodeImpl.frbInternalDcoDecode(raw as List); + } + + @protected + MyAudioParam + dco_decode_ProxyEnum_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + throw UnimplementedError( + 'Not implemented in this codec, please use the other one'); + } + + @protected + MyAudioParam + dco_decode_ProxyVariant_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + throw UnimplementedError( + 'Not implemented in this codec, please use the other one'); + } + + @protected + MyAudioParam + dco_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return MyAudioParamImpl.frbInternalDcoDecode(raw as List); + } + + @protected + MyNode + dco_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return MyNodeImpl.frbInternalDcoDecode(raw as List); + } + + @protected + String dco_decode_String(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return raw as String; + } @protected - int dco_decode_i_32(dynamic raw) { + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum + dco_decode_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + switch (raw[0]) { + case 0: + return Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0( + dco_decode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + raw[1]), + ); + default: + throw Exception("unreachable"); + } + } + + @protected + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum + dco_decode_box_autoadd_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return dco_decode_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + raw); + } + + @protected + Uint8List dco_decode_list_prim_u_8_strict(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return raw as Uint8List; + } + + @protected + int dco_decode_u_8(dynamic raw) { // Codec=Dco (DartCObject based), see doc to use other codecs return raw as int; } @@ -143,9 +266,138 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { } @protected - int sse_decode_i_32(SseDeserializer deserializer) { + BigInt dco_decode_usize(dynamic raw) { + // Codec=Dco (DartCObject based), see doc to use other codecs + return dcoDecodeU64(raw); + } + + @protected + MyNode + sse_decode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs - return deserializer.buffer.getInt32(); + var inner = + sse_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + deserializer); + return inner; + } + + @protected + MyAudioParam + sse_decode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + return MyAudioParamImpl.frbInternalSseDecode( + sse_decode_usize(deserializer), sse_decode_i_32(deserializer)); + } + + @protected + MyNode + sse_decode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + return MyNodeImpl.frbInternalSseDecode( + sse_decode_usize(deserializer), sse_decode_i_32(deserializer)); + } + + @protected + MyAudioParam + sse_decode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + return MyAudioParamImpl.frbInternalSseDecode( + sse_decode_usize(deserializer), sse_decode_i_32(deserializer)); + } + + @protected + MyNode + sse_decode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + return MyNodeImpl.frbInternalSseDecode( + sse_decode_usize(deserializer), sse_decode_i_32(deserializer)); + } + + @protected + MyAudioParam + sse_decode_ProxyEnum_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + throw UnimplementedError('Unreachable ()'); + } + + @protected + MyAudioParam + sse_decode_ProxyVariant_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + throw UnimplementedError('Unreachable ()'); + } + + @protected + MyAudioParam + sse_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + return MyAudioParamImpl.frbInternalSseDecode( + sse_decode_usize(deserializer), sse_decode_i_32(deserializer)); + } + + @protected + MyNode + sse_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + return MyNodeImpl.frbInternalSseDecode( + sse_decode_usize(deserializer), sse_decode_i_32(deserializer)); + } + + @protected + String sse_decode_String(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var inner = sse_decode_list_prim_u_8_strict(deserializer); + return utf8.decoder.convert(inner); + } + + @protected + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum + sse_decode_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + + var tag_ = sse_decode_i_32(deserializer); + switch (tag_) { + case 0: + var var_field0 = + sse_decode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + deserializer); + return Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0( + var_field0); + default: + throw UnimplementedError(''); + } + } + + @protected + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum + sse_decode_box_autoadd_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + return (sse_decode_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + deserializer)); + } + + @protected + Uint8List sse_decode_list_prim_u_8_strict(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + var len_ = sse_decode_i_32(deserializer); + return deserializer.buffer.getUint8List(len_); + } + + @protected + int sse_decode_u_8(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + return deserializer.buffer.getUint8(); } @protected @@ -153,6 +405,18 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { // Codec=Sse (Serialization based), see doc to use other codecs } + @protected + BigInt sse_decode_usize(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + return deserializer.buffer.getBigUint64(); + } + + @protected + int sse_decode_i_32(SseDeserializer deserializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + return deserializer.buffer.getInt32(); + } + @protected bool sse_decode_bool(SseDeserializer deserializer) { // Codec=Sse (Serialization based), see doc to use other codecs @@ -160,9 +424,141 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { } @protected - void sse_encode_i_32(int self, SseSerializer serializer) { + void + sse_encode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + MyNode self, SseSerializer serializer) { // Codec=Sse (Serialization based), see doc to use other codecs - serializer.buffer.putInt32(self); + sse_encode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + self, serializer); + } + + @protected + void + sse_encode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + MyAudioParam self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_usize( + (self as MyAudioParamImpl).frbInternalSseEncode(move: true), + serializer); + } + + @protected + void + sse_encode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + MyNode self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_usize( + (self as MyNodeImpl).frbInternalSseEncode(move: true), serializer); + } + + @protected + void + sse_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + MyAudioParam self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_usize( + (self as MyAudioParamImpl).frbInternalSseEncode(move: false), + serializer); + } + + @protected + void + sse_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + MyNode self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_usize( + (self as MyNodeImpl).frbInternalSseEncode(move: false), serializer); + } + + @protected + void + sse_encode_ProxyEnum_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + MyAudioParam self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + (() { + if (self is MyAudioParamProxyVariantMyNode) { + return Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum + .variant0(self._upstream); + } + + throw Exception('not reachable'); + })(), serializer); + } + + @protected + void + sse_encode_ProxyVariant_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + MyAudioParam self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + throw UnimplementedError('Unreachable ()'); + } + + @protected + void + sse_encode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + MyAudioParam self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_usize( + (self as MyAudioParamImpl).frbInternalSseEncode(move: null), + serializer); + } + + @protected + void + sse_encode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + MyNode self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_usize( + (self as MyNodeImpl).frbInternalSseEncode(move: null), serializer); + } + + @protected + void sse_encode_String(String self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_list_prim_u_8_strict(utf8.encoder.convert(self), serializer); + } + + @protected + void sse_encode_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum + self, + SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + switch (self) { + case Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0( + field0: final field0 + ): + sse_encode_i_32(0, serializer); + sse_encode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + field0, serializer); + default: + throw UnimplementedError(''); + } + } + + @protected + void sse_encode_box_autoadd_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum + self, + SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + self, serializer); + } + + @protected + void sse_encode_list_prim_u_8_strict( + Uint8List self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + sse_encode_i_32(self.length, serializer); + serializer.buffer.putUint8List(self); + } + + @protected + void sse_encode_u_8(int self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + serializer.buffer.putUint8(self); } @protected @@ -170,9 +566,93 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi { // Codec=Sse (Serialization based), see doc to use other codecs } + @protected + void sse_encode_usize(BigInt self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + serializer.buffer.putBigUint64(self); + } + + @protected + void sse_encode_i_32(int self, SseSerializer serializer) { + // Codec=Sse (Serialization based), see doc to use other codecs + serializer.buffer.putInt32(self); + } + @protected void sse_encode_bool(bool self, SseSerializer serializer) { // Codec=Sse (Serialization based), see doc to use other codecs serializer.buffer.putUint8(self ? 1 : 0); } } + +@freezed +sealed class Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum + with + _$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum { + const Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum._(); + + const factory Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum.variant0( + MyNode field0, + ) = Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0; +} + +@sealed +class MyAudioParamImpl extends RustOpaque implements MyAudioParam { + // Not to be used by end users + MyAudioParamImpl.frbInternalDcoDecode(List wire) + : super.frbInternalDcoDecode(wire, _kStaticData); + + // Not to be used by end users + MyAudioParamImpl.frbInternalSseDecode(BigInt ptr, int externalSizeOnNative) + : super.frbInternalSseDecode(ptr, externalSizeOnNative, _kStaticData); + + static final _kStaticData = RustArcStaticData( + rustArcIncrementStrongCount: + RustLib.instance.api.rust_arc_increment_strong_count_MyAudioParam, + rustArcDecrementStrongCount: + RustLib.instance.api.rust_arc_decrement_strong_count_MyAudioParam, + rustArcDecrementStrongCountPtr: + RustLib.instance.api.rust_arc_decrement_strong_count_MyAudioParamPtr, + ); + + Future myMethod() => + RustLib.instance.api.crateApiMinimalMyAudioParamMyMethod( + that: this, + ); +} + +@sealed +class MyNodeImpl extends RustOpaque implements MyNode { + // Not to be used by end users + MyNodeImpl.frbInternalDcoDecode(List wire) + : super.frbInternalDcoDecode(wire, _kStaticData); + + // Not to be used by end users + MyNodeImpl.frbInternalSseDecode(BigInt ptr, int externalSizeOnNative) + : super.frbInternalSseDecode(ptr, externalSizeOnNative, _kStaticData); + + static final _kStaticData = RustArcStaticData( + rustArcIncrementStrongCount: + RustLib.instance.api.rust_arc_increment_strong_count_MyNode, + rustArcDecrementStrongCount: + RustLib.instance.api.rust_arc_decrement_strong_count_MyNode, + rustArcDecrementStrongCountPtr: + RustLib.instance.api.rust_arc_decrement_strong_count_MyNodePtr, + ); + + Future paramOne() => + Future.value(MyAudioParamProxyVariantMyNode(this)); +} + +class MyAudioParamProxyVariantMyNode + with SimpleDisposable + implements MyAudioParam { + final MyNode _upstream; + + MyAudioParamProxyVariantMyNode(this._upstream); + + Future myMethod() => + RustLib.instance.api.crateApiMinimalMyAudioParamMyMethod( + that: this, + ); +} diff --git a/frb_example/dart_minimal/lib/src/rust/frb_generated.freezed.dart b/frb_example/dart_minimal/lib/src/rust/frb_generated.freezed.dart new file mode 100644 index 0000000000..db94d0db9d --- /dev/null +++ b/frb_example/dart_minimal/lib/src/rust/frb_generated.freezed.dart @@ -0,0 +1,282 @@ +// coverage:ignore-file +// GENERATED CODE - DO NOT MODIFY BY HAND +// ignore_for_file: type=lint +// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark + +part of 'frb_generated.dart'; + +// ************************************************************************** +// FreezedGenerator +// ************************************************************************** + +T _$identity(T value) => value; + +final _privateConstructorUsedError = UnsupportedError( + 'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#custom-getters-and-methods'); + +/// @nodoc +mixin _$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum { + MyNode get field0 => throw _privateConstructorUsedError; + @optionalTypeArgs + TResult when({ + required TResult Function(MyNode field0) variant0, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(MyNode field0)? variant0, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(MyNode field0)? variant0, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult map({ + required TResult Function( + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0 + value) + variant0, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function( + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0 + value)? + variant0, + }) => + throw _privateConstructorUsedError; + @optionalTypeArgs + TResult maybeMap({ + TResult Function( + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0 + value)? + variant0, + required TResult orElse(), + }) => + throw _privateConstructorUsedError; + + @JsonKey(ignore: true) + $Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnumCopyWith< + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum> + get copyWith => throw _privateConstructorUsedError; +} + +/// @nodoc +abstract class $Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnumCopyWith< + $Res> { + factory $Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnumCopyWith( + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum + value, + $Res Function( + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum) + then) = _$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnumCopyWithImpl< + $Res, + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum>; + @useResult + $Res call({MyNode field0}); +} + +/// @nodoc +class _$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnumCopyWithImpl< + $Res, + $Val extends Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum> + implements + $Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnumCopyWith< + $Res> { + _$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnumCopyWithImpl( + this._value, this._then); + + // ignore: unused_field + final $Val _value; + // ignore: unused_field + final $Res Function($Val) _then; + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? field0 = null, + }) { + return _then(_value.copyWith( + field0: null == field0 + ? _value.field0 + : field0 // ignore: cast_nullable_to_non_nullable + as MyNode, + ) as $Val); + } +} + +/// @nodoc +abstract class _$$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0ImplCopyWith< + $Res> + implements + $Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnumCopyWith< + $Res> { + factory _$$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0ImplCopyWith( + _$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0Impl + value, + $Res Function( + _$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0Impl) + then) = + __$$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0ImplCopyWithImpl< + $Res>; + @override + @useResult + $Res call({MyNode field0}); +} + +/// @nodoc +class __$$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0ImplCopyWithImpl< + $Res> + extends _$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnumCopyWithImpl< + $Res, + _$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0Impl> + implements + _$$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0ImplCopyWith< + $Res> { + __$$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0ImplCopyWithImpl( + _$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0Impl + _value, + $Res Function( + _$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0Impl) + _then) + : super(_value, _then); + + @pragma('vm:prefer-inline') + @override + $Res call({ + Object? field0 = null, + }) { + return _then( + _$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0Impl( + null == field0 + ? _value.field0 + : field0 // ignore: cast_nullable_to_non_nullable + as MyNode, + )); + } +} + +/// @nodoc + +class _$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0Impl + extends Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0 { + const _$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0Impl( + this.field0) + : super._(); + + @override + final MyNode field0; + + @override + String toString() { + return 'Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum.variant0(field0: $field0)'; + } + + @override + bool operator ==(Object other) { + return identical(this, other) || + (other.runtimeType == runtimeType && + other + is _$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0Impl && + (identical(other.field0, field0) || other.field0 == field0)); + } + + @override + int get hashCode => Object.hash(runtimeType, field0); + + @JsonKey(ignore: true) + @override + @pragma('vm:prefer-inline') + _$$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0ImplCopyWith< + _$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0Impl> + get copyWith => + __$$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0ImplCopyWithImpl< + _$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0Impl>( + this, _$identity); + + @override + @optionalTypeArgs + TResult when({ + required TResult Function(MyNode field0) variant0, + }) { + return variant0(field0); + } + + @override + @optionalTypeArgs + TResult? whenOrNull({ + TResult? Function(MyNode field0)? variant0, + }) { + return variant0?.call(field0); + } + + @override + @optionalTypeArgs + TResult maybeWhen({ + TResult Function(MyNode field0)? variant0, + required TResult orElse(), + }) { + if (variant0 != null) { + return variant0(field0); + } + return orElse(); + } + + @override + @optionalTypeArgs + TResult map({ + required TResult Function( + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0 + value) + variant0, + }) { + return variant0(this); + } + + @override + @optionalTypeArgs + TResult? mapOrNull({ + TResult? Function( + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0 + value)? + variant0, + }) { + return variant0?.call(this); + } + + @override + @optionalTypeArgs + TResult maybeMap({ + TResult Function( + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0 + value)? + variant0, + required TResult orElse(), + }) { + if (variant0 != null) { + return variant0(this); + } + return orElse(); + } +} + +abstract class Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0 + extends Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum { + const factory Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0( + final MyNode field0) = + _$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0Impl; + const Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0._() + : super._(); + + @override + MyNode get field0; + @override + @JsonKey(ignore: true) + _$$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0ImplCopyWith< + _$Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum_Variant0Impl> + get copyWith => throw _privateConstructorUsedError; +} diff --git a/frb_example/dart_minimal/lib/src/rust/frb_generated.io.dart b/frb_example/dart_minimal/lib/src/rust/frb_generated.io.dart index 514bf14e56..0d6699a0cc 100644 --- a/frb_example/dart_minimal/lib/src/rust/frb_generated.io.dart +++ b/frb_example/dart_minimal/lib/src/rust/frb_generated.io.dart @@ -18,27 +18,235 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { required super.portManager, }); + CrossPlatformFinalizerArg + get rust_arc_decrement_strong_count_MyAudioParamPtr => wire + ._rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamPtr; + + CrossPlatformFinalizerArg get rust_arc_decrement_strong_count_MyNodePtr => wire + ._rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNodePtr; + + @protected + MyNode + dco_decode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + dynamic raw); + + @protected + MyAudioParam + dco_decode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + dynamic raw); + + @protected + MyNode + dco_decode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + dynamic raw); + + @protected + MyAudioParam + dco_decode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + dynamic raw); + + @protected + MyNode + dco_decode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + dynamic raw); + + @protected + MyAudioParam + dco_decode_ProxyEnum_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + dynamic raw); + + @protected + MyAudioParam + dco_decode_ProxyVariant_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + dynamic raw); + + @protected + MyAudioParam + dco_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + dynamic raw); + + @protected + MyNode + dco_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + dynamic raw); + + @protected + String dco_decode_String(dynamic raw); + + @protected + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum + dco_decode_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + dynamic raw); + + @protected + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum + dco_decode_box_autoadd_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + dynamic raw); + @protected - int dco_decode_i_32(dynamic raw); + Uint8List dco_decode_list_prim_u_8_strict(dynamic raw); + + @protected + int dco_decode_u_8(dynamic raw); @protected void dco_decode_unit(dynamic raw); @protected - int sse_decode_i_32(SseDeserializer deserializer); + BigInt dco_decode_usize(dynamic raw); + + @protected + MyNode + sse_decode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + SseDeserializer deserializer); + + @protected + MyAudioParam + sse_decode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + SseDeserializer deserializer); + + @protected + MyNode + sse_decode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + SseDeserializer deserializer); + + @protected + MyAudioParam + sse_decode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + SseDeserializer deserializer); + + @protected + MyNode + sse_decode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + SseDeserializer deserializer); + + @protected + MyAudioParam + sse_decode_ProxyEnum_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + SseDeserializer deserializer); + + @protected + MyAudioParam + sse_decode_ProxyVariant_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + SseDeserializer deserializer); + + @protected + MyAudioParam + sse_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + SseDeserializer deserializer); + + @protected + MyNode + sse_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + SseDeserializer deserializer); + + @protected + String sse_decode_String(SseDeserializer deserializer); + + @protected + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum + sse_decode_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + SseDeserializer deserializer); + + @protected + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum + sse_decode_box_autoadd_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + SseDeserializer deserializer); + + @protected + Uint8List sse_decode_list_prim_u_8_strict(SseDeserializer deserializer); + + @protected + int sse_decode_u_8(SseDeserializer deserializer); @protected void sse_decode_unit(SseDeserializer deserializer); + @protected + BigInt sse_decode_usize(SseDeserializer deserializer); + + @protected + int sse_decode_i_32(SseDeserializer deserializer); + @protected bool sse_decode_bool(SseDeserializer deserializer); @protected - void sse_encode_i_32(int self, SseSerializer serializer); + void + sse_encode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + MyNode self, SseSerializer serializer); + + @protected + void + sse_encode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + MyAudioParam self, SseSerializer serializer); + + @protected + void + sse_encode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + MyNode self, SseSerializer serializer); + + @protected + void + sse_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + MyAudioParam self, SseSerializer serializer); + + @protected + void + sse_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + MyNode self, SseSerializer serializer); + + @protected + void + sse_encode_ProxyEnum_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + MyAudioParam self, SseSerializer serializer); + + @protected + void + sse_encode_ProxyVariant_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + MyAudioParam self, SseSerializer serializer); + + @protected + void + sse_encode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + MyAudioParam self, SseSerializer serializer); + + @protected + void + sse_encode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + MyNode self, SseSerializer serializer); + + @protected + void sse_encode_String(String self, SseSerializer serializer); + + @protected + void sse_encode_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum + self, + SseSerializer serializer); + + @protected + void sse_encode_box_autoadd_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum + self, + SseSerializer serializer); + + @protected + void sse_encode_list_prim_u_8_strict( + Uint8List self, SseSerializer serializer); + + @protected + void sse_encode_u_8(int self, SseSerializer serializer); @protected void sse_encode_unit(void self, SseSerializer serializer); + @protected + void sse_encode_usize(BigInt self, SseSerializer serializer); + + @protected + void sse_encode_i_32(int self, SseSerializer serializer); + @protected void sse_encode_bool(bool self, SseSerializer serializer); } @@ -56,4 +264,68 @@ class RustLibWire implements BaseWire { /// The symbols are looked up in [dynamicLibrary]. RustLibWire(ffi.DynamicLibrary dynamicLibrary) : _lookup = dynamicLibrary.lookup; + + void + rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + ffi.Pointer ptr, + ) { + return _rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + ptr, + ); + } + + late final _rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamPtr = + _lookup)>>( + 'frbgen_frb_example_dart_minimal_rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam'); + late final _rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam = + _rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamPtr + .asFunction)>(); + + void + rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + ffi.Pointer ptr, + ) { + return _rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + ptr, + ); + } + + late final _rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamPtr = + _lookup)>>( + 'frbgen_frb_example_dart_minimal_rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam'); + late final _rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam = + _rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamPtr + .asFunction)>(); + + void + rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + ffi.Pointer ptr, + ) { + return _rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + ptr, + ); + } + + late final _rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNodePtr = + _lookup)>>( + 'frbgen_frb_example_dart_minimal_rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode'); + late final _rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode = + _rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNodePtr + .asFunction)>(); + + void + rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + ffi.Pointer ptr, + ) { + return _rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + ptr, + ); + } + + late final _rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNodePtr = + _lookup)>>( + 'frbgen_frb_example_dart_minimal_rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode'); + late final _rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode = + _rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNodePtr + .asFunction)>(); } diff --git a/frb_example/dart_minimal/lib/src/rust/frb_generated.web.dart b/frb_example/dart_minimal/lib/src/rust/frb_generated.web.dart index d1f8695480..867ca5856e 100644 --- a/frb_example/dart_minimal/lib/src/rust/frb_generated.web.dart +++ b/frb_example/dart_minimal/lib/src/rust/frb_generated.web.dart @@ -20,27 +20,235 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { required super.portManager, }); + CrossPlatformFinalizerArg + get rust_arc_decrement_strong_count_MyAudioParamPtr => wire + .rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam; + + CrossPlatformFinalizerArg get rust_arc_decrement_strong_count_MyNodePtr => wire + .rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode; + + @protected + MyNode + dco_decode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + dynamic raw); + + @protected + MyAudioParam + dco_decode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + dynamic raw); + + @protected + MyNode + dco_decode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + dynamic raw); + + @protected + MyAudioParam + dco_decode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + dynamic raw); + + @protected + MyNode + dco_decode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + dynamic raw); + + @protected + MyAudioParam + dco_decode_ProxyEnum_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + dynamic raw); + + @protected + MyAudioParam + dco_decode_ProxyVariant_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + dynamic raw); + + @protected + MyAudioParam + dco_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + dynamic raw); + + @protected + MyNode + dco_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + dynamic raw); + + @protected + String dco_decode_String(dynamic raw); + + @protected + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum + dco_decode_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + dynamic raw); + + @protected + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum + dco_decode_box_autoadd_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + dynamic raw); + @protected - int dco_decode_i_32(dynamic raw); + Uint8List dco_decode_list_prim_u_8_strict(dynamic raw); + + @protected + int dco_decode_u_8(dynamic raw); @protected void dco_decode_unit(dynamic raw); @protected - int sse_decode_i_32(SseDeserializer deserializer); + BigInt dco_decode_usize(dynamic raw); + + @protected + MyNode + sse_decode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + SseDeserializer deserializer); + + @protected + MyAudioParam + sse_decode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + SseDeserializer deserializer); + + @protected + MyNode + sse_decode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + SseDeserializer deserializer); + + @protected + MyAudioParam + sse_decode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + SseDeserializer deserializer); + + @protected + MyNode + sse_decode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + SseDeserializer deserializer); + + @protected + MyAudioParam + sse_decode_ProxyEnum_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + SseDeserializer deserializer); + + @protected + MyAudioParam + sse_decode_ProxyVariant_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + SseDeserializer deserializer); + + @protected + MyAudioParam + sse_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + SseDeserializer deserializer); + + @protected + MyNode + sse_decode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + SseDeserializer deserializer); + + @protected + String sse_decode_String(SseDeserializer deserializer); + + @protected + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum + sse_decode_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + SseDeserializer deserializer); + + @protected + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum + sse_decode_box_autoadd_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + SseDeserializer deserializer); + + @protected + Uint8List sse_decode_list_prim_u_8_strict(SseDeserializer deserializer); + + @protected + int sse_decode_u_8(SseDeserializer deserializer); @protected void sse_decode_unit(SseDeserializer deserializer); + @protected + BigInt sse_decode_usize(SseDeserializer deserializer); + + @protected + int sse_decode_i_32(SseDeserializer deserializer); + @protected bool sse_decode_bool(SseDeserializer deserializer); @protected - void sse_encode_i_32(int self, SseSerializer serializer); + void + sse_encode_AutoExplicit_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + MyNode self, SseSerializer serializer); + + @protected + void + sse_encode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + MyAudioParam self, SseSerializer serializer); + + @protected + void + sse_encode_Auto_Owned_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + MyNode self, SseSerializer serializer); + + @protected + void + sse_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + MyAudioParam self, SseSerializer serializer); + + @protected + void + sse_encode_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + MyNode self, SseSerializer serializer); + + @protected + void + sse_encode_ProxyEnum_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + MyAudioParam self, SseSerializer serializer); + + @protected + void + sse_encode_ProxyVariant_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + MyAudioParam self, SseSerializer serializer); + + @protected + void + sse_encode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + MyAudioParam self, SseSerializer serializer); + + @protected + void + sse_encode_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + MyNode self, SseSerializer serializer); + + @protected + void sse_encode_String(String self, SseSerializer serializer); + + @protected + void sse_encode_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum + self, + SseSerializer serializer); + + @protected + void sse_encode_box_autoadd_auto_ref_rust_opaque_flutter_rust_bridgefor_generated_rust_auto_opaque_inner_my_audio_param_proxy_enum( + Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum + self, + SseSerializer serializer); + + @protected + void sse_encode_list_prim_u_8_strict( + Uint8List self, SseSerializer serializer); + + @protected + void sse_encode_u_8(int self, SseSerializer serializer); @protected void sse_encode_unit(void self, SseSerializer serializer); + @protected + void sse_encode_usize(BigInt self, SseSerializer serializer); + + @protected + void sse_encode_i_32(int self, SseSerializer serializer); + @protected void sse_encode_bool(bool self, SseSerializer serializer); } @@ -49,6 +257,30 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl { class RustLibWire implements BaseWire { RustLibWire.fromExternalLibrary(ExternalLibrary lib); + + void rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + dynamic ptr) => + wasmModule + .rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + ptr); + + void rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + dynamic ptr) => + wasmModule + .rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + ptr); + + void rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + dynamic ptr) => + wasmModule + .rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + ptr); + + void rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + dynamic ptr) => + wasmModule + .rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + ptr); } @JS('wasm_bindgen') @@ -62,4 +294,20 @@ class RustLibWasmModule implements WasmModule { @override external RustLibWasmModule bind(dynamic thisArg, String moduleName); + + external void + rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + dynamic ptr); + + external void + rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + dynamic ptr); + + external void + rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + dynamic ptr); + + external void + rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + dynamic ptr); } diff --git a/frb_example/dart_minimal/rust/src/api/minimal.rs b/frb_example/dart_minimal/rust/src/api/minimal.rs index 517e29973f..0f0492810d 100644 --- a/frb_example/dart_minimal/rust/src/api/minimal.rs +++ b/frb_example/dart_minimal/rust/src/api/minimal.rs @@ -1,10 +1,43 @@ use flutter_rust_bridge::frb; -#[frb(init)] -pub fn init_app() { - flutter_rust_bridge::setup_default_user_utils(); +// #[frb(init)] +// pub fn init_app() { +// flutter_rust_bridge::setup_default_user_utils(); +// } +// +// pub fn minimal_adder(a: i32, b: i32) -> i32 { +// a + b +// } + +#[frb(opaque)] +pub struct MyAudioParam(String); + +impl MyAudioParam { + // #[frb(sync)] + // pub fn new(value: String) -> Self { + // Self(value) + // } + + pub fn my_method(&self) -> String { + self.0.repeat(2) + } } -pub fn minimal_adder(a: i32, b: i32) -> i32 { - a + b +#[frb(opaque)] +pub struct MyNode { + param_one: MyAudioParam, +} + +impl MyNode { + // #[frb(sync)] + // pub fn new() -> Self { + // Self { + // param_one: MyAudioParam::new("a".to_owned()), + // } + // } + + #[frb(proxy)] + pub fn param_one(&self) -> &MyAudioParam { + &self.param_one + } } diff --git a/frb_example/dart_minimal/rust/src/frb_generated.io.rs b/frb_example/dart_minimal/rust/src/frb_generated.io.rs index 1cfa2a0e73..efd5d6854e 100644 --- a/frb_example/dart_minimal/rust/src/frb_generated.io.rs +++ b/frb_example/dart_minimal/rust/src/frb_generated.io.rs @@ -4,6 +4,7 @@ // Section: imports use super::*; +use crate::api::minimal::*; use flutter_rust_bridge::for_generated::byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt}; use flutter_rust_bridge::for_generated::transform_result_dco; use flutter_rust_bridge::{Handler, IntoIntoDart}; @@ -11,3 +12,31 @@ use flutter_rust_bridge::{Handler, IntoIntoDart}; // Section: boilerplate flutter_rust_bridge::frb_generated_boilerplate_io!(); + +#[no_mangle] +pub extern "C" fn frbgen_frb_example_dart_minimal_rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + ptr: *const std::ffi::c_void, +) { + MoiArc::>::increment_strong_count(ptr as _); +} + +#[no_mangle] +pub extern "C" fn frbgen_frb_example_dart_minimal_rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + ptr: *const std::ffi::c_void, +) { + MoiArc::>::decrement_strong_count(ptr as _); +} + +#[no_mangle] +pub extern "C" fn frbgen_frb_example_dart_minimal_rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + ptr: *const std::ffi::c_void, +) { + MoiArc::>::increment_strong_count(ptr as _); +} + +#[no_mangle] +pub extern "C" fn frbgen_frb_example_dart_minimal_rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + ptr: *const std::ffi::c_void, +) { + MoiArc::>::decrement_strong_count(ptr as _); +} diff --git a/frb_example/dart_minimal/rust/src/frb_generated.rs b/frb_example/dart_minimal/rust/src/frb_generated.rs index fb26d7f88c..dcec7c573a 100644 --- a/frb_example/dart_minimal/rust/src/frb_generated.rs +++ b/frb_example/dart_minimal/rust/src/frb_generated.rs @@ -21,6 +21,7 @@ // Section: imports +use crate::api::minimal::*; use flutter_rust_bridge::for_generated::byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt}; use flutter_rust_bridge::for_generated::transform_result_dco; use flutter_rust_bridge::{Handler, IntoIntoDart}; @@ -33,7 +34,7 @@ flutter_rust_bridge::frb_generated_boilerplate!( default_rust_auto_opaque = RustAutoOpaqueMoi, ); pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_VERSION: &str = "2.0.0-dev.37"; -pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = -2119384465; +pub(crate) const FLUTTER_RUST_BRIDGE_CODEGEN_CONTENT_HASH: i32 = 382423683; // Section: executor @@ -41,7 +42,7 @@ flutter_rust_bridge::frb_generated_default_handler!(); // Section: wire_funcs -fn wire__crate__api__minimal__init_app_impl( +fn wire__crate__api__minimal__MyAudioParam_my_method_impl( port_: flutter_rust_bridge::for_generated::MessagePort, ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, rust_vec_len_: i32, @@ -49,7 +50,7 @@ fn wire__crate__api__minimal__init_app_impl( ) { FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::( flutter_rust_bridge::for_generated::TaskInfo { - debug_name: "init_app", + debug_name: "MyAudioParam_my_method", port: Some(port_), mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal, }, @@ -63,57 +64,121 @@ fn wire__crate__api__minimal__init_app_impl( }; let mut deserializer = flutter_rust_bridge::for_generated::SseDeserializer::new(message); + let api_that = , + >>::sse_decode(&mut deserializer); deserializer.end(); move |context| { transform_result_sse((move || { - Result::<_, ()>::Ok({ - crate::api::minimal::init_app(); - }) + Result::<_, ()>::Ok(crate::api::minimal::MyAudioParam::my_method(api_that)) })()) } }, ) } -fn wire__crate__api__minimal__minimal_adder_impl( - port_: flutter_rust_bridge::for_generated::MessagePort, - ptr_: flutter_rust_bridge::for_generated::PlatformGeneralizedUint8ListPtr, - rust_vec_len_: i32, - data_len_: i32, + +// Section: related_funcs + +flutter_rust_bridge::frb_generated_moi_arc_impl_value!( + flutter_rust_bridge::for_generated::RustAutoOpaqueInner +); +flutter_rust_bridge::frb_generated_moi_arc_impl_value!( + flutter_rust_bridge::for_generated::RustAutoOpaqueInner +); + +// Section: extra_from_parser + +enum Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum { + Variant0(RustAutoOpaque), +} + +pub fn frb_internal_no_impl_dummy_function_Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum( + a: Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum, ) { - FLUTTER_RUST_BRIDGE_HANDLER.wrap_normal::( - flutter_rust_bridge::for_generated::TaskInfo { - debug_name: "minimal_adder", - port: Some(port_), - mode: flutter_rust_bridge::for_generated::FfiCallMode::Normal, - }, - move || { - let message = unsafe { - flutter_rust_bridge::for_generated::Dart2RustMessageSse::from_wire( - ptr_, - rust_vec_len_, - data_len_, - ) - }; - let mut deserializer = - flutter_rust_bridge::for_generated::SseDeserializer::new(message); - let api_a = ::sse_decode(&mut deserializer); - let api_b = ::sse_decode(&mut deserializer); - deserializer.end(); - move |context| { - transform_result_sse((move || { - Result::<_, ()>::Ok(crate::api::minimal::minimal_adder(api_a, api_b)) - })()) - } - }, - ) } // Section: dart2rust -impl SseDecode for i32 { +impl SseDecode for RustAutoOpaqueMoi { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { - deserializer.cursor.read_i32::().unwrap() + let mut inner = , + >>::sse_decode(deserializer); + return flutter_rust_bridge::for_generated::rust_auto_opaque_explicit_decode(inner); + } +} + +impl SseDecode for MyAudioParam { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut inner = , + >>::sse_decode(deserializer); + return flutter_rust_bridge::for_generated::rust_auto_opaque_decode_owned(inner); + } +} + +impl SseDecode for MyNode { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut inner = , + >>::sse_decode(deserializer); + return flutter_rust_bridge::for_generated::rust_auto_opaque_decode_owned(inner); + } +} + +impl SseDecode + for RustOpaqueMoi> +{ + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut inner = ::sse_decode(deserializer); + return decode_rust_opaque_moi(inner); + } +} + +impl SseDecode for RustOpaqueMoi> { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut inner = ::sse_decode(deserializer); + return decode_rust_opaque_moi(inner); + } +} + +impl SseDecode for String { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut inner = >::sse_decode(deserializer); + return String::from_utf8(inner).unwrap(); + } +} + +impl SseDecode for crate::frb_generated::Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {let mut tag_ = ::sse_decode(deserializer); + match tag_ {0 => { let mut var_field0 = >::sse_decode(deserializer); +return crate::frb_generated::Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum::Variant0(var_field0); } + _ => { unimplemented!(""); }}} + } + +impl SseDecode for Vec { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + let mut len_ = ::sse_decode(deserializer); + let mut ans_ = vec![]; + for idx_ in 0..len_ { + ans_.push(::sse_decode(deserializer)); + } + return ans_; + } +} + +impl SseDecode for u8 { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + deserializer.cursor.read_u8().unwrap() } } @@ -122,6 +187,20 @@ impl SseDecode for () { fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {} } +impl SseDecode for usize { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + deserializer.cursor.read_u64::().unwrap() as _ + } +} + +impl SseDecode for i32 { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { + deserializer.cursor.read_i32::().unwrap() + } +} + impl SseDecode for bool { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self { @@ -138,8 +217,12 @@ fn pde_ffi_dispatcher_primary_impl( ) { // Codec=Pde (Serialization + dispatch), see doc to use other codecs match func_id { - 1 => wire__crate__api__minimal__init_app_impl(port, ptr, rust_vec_len, data_len), - 2 => wire__crate__api__minimal__minimal_adder_impl(port, ptr, rust_vec_len, data_len), + 1 => wire__crate__api__minimal__MyAudioParam_my_method_impl( + port, + ptr, + rust_vec_len, + data_len, + ), _ => unreachable!(), } } @@ -158,10 +241,120 @@ fn pde_ffi_dispatcher_sync_impl( // Section: rust2dart -impl SseEncode for i32 { +// Codec=Dco (DartCObject based), see doc to use other codecs +impl flutter_rust_bridge::IntoDart for FrbWrapper { + fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi { + flutter_rust_bridge::for_generated::rust_auto_opaque_encode::<_, MoiArc<_>>(self.0) + .into_dart() + } +} +impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive for FrbWrapper {} + +impl flutter_rust_bridge::IntoIntoDart> for MyAudioParam { + fn into_into_dart(self) -> FrbWrapper { + self.into() + } +} + +// Codec=Dco (DartCObject based), see doc to use other codecs +impl flutter_rust_bridge::IntoDart for FrbWrapper { + fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi { + flutter_rust_bridge::for_generated::rust_auto_opaque_encode::<_, MoiArc<_>>(self.0) + .into_dart() + } +} +impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive for FrbWrapper {} + +impl flutter_rust_bridge::IntoIntoDart> for MyNode { + fn into_into_dart(self) -> FrbWrapper { + self.into() + } +} + +// Codec=Dco (DartCObject based), see doc to use other codecs +impl flutter_rust_bridge::IntoDart for crate::frb_generated::Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum { + fn into_dart(self) -> flutter_rust_bridge::for_generated::DartAbi { + match self {crate::frb_generated::Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum::Variant0(field0) => { [0.into_dart(), +field0.into_into_dart().into_dart()].into_dart() } + _ => { unimplemented!(""); }} + } + } +impl flutter_rust_bridge::for_generated::IntoDartExceptPrimitive for crate::frb_generated::Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum {} +impl flutter_rust_bridge::IntoIntoDart for crate::frb_generated::Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum { + fn into_into_dart(self) -> crate::frb_generated::Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum { + self + } + } + +impl SseEncode for RustAutoOpaqueMoi { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { - serializer.cursor.write_i32::(self).unwrap(); + >>::sse_encode(flutter_rust_bridge::for_generated::rust_auto_opaque_explicit_encode(self), serializer); + } +} + +impl SseEncode for MyAudioParam { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + >>::sse_encode(flutter_rust_bridge::for_generated::rust_auto_opaque_encode::<_, MoiArc<_>>(self), serializer); + } +} + +impl SseEncode for MyNode { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + >>::sse_encode(flutter_rust_bridge::for_generated::rust_auto_opaque_encode::<_, MoiArc<_>>(self), serializer); + } +} + +impl SseEncode + for RustOpaqueMoi> +{ + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + let (ptr, size) = self.sse_encode_raw(); + ::sse_encode(ptr, serializer); + ::sse_encode(size, serializer); + } +} + +impl SseEncode for RustOpaqueMoi> { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + let (ptr, size) = self.sse_encode_raw(); + ::sse_encode(ptr, serializer); + ::sse_encode(size, serializer); + } +} + +impl SseEncode for String { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + >::sse_encode(self.into_bytes(), serializer); + } +} + +impl SseEncode for crate::frb_generated::Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {match self {crate::frb_generated::Auto_Ref_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParamProxyEnum::Variant0(field0) => { ::sse_encode(0, serializer); >::sse_encode(field0, serializer); + } + _ => { unimplemented!(""); }}} + } + +impl SseEncode for Vec { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + ::sse_encode(self.len() as _, serializer); + for item in self { + ::sse_encode(item, serializer); + } + } +} + +impl SseEncode for u8 { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + serializer.cursor.write_u8(self).unwrap(); } } @@ -170,6 +363,23 @@ impl SseEncode for () { fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {} } +impl SseEncode for usize { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + serializer + .cursor + .write_u64::(self as _) + .unwrap(); + } +} + +impl SseEncode for i32 { + // Codec=Sse (Serialization based), see doc to use other codecs + fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { + serializer.cursor.write_i32::(self).unwrap(); + } +} + impl SseEncode for bool { // Codec=Sse (Serialization based), see doc to use other codecs fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) { diff --git a/frb_example/dart_minimal/rust/src/frb_generated.web.rs b/frb_example/dart_minimal/rust/src/frb_generated.web.rs index 2a167704c1..01f084508a 100644 --- a/frb_example/dart_minimal/rust/src/frb_generated.web.rs +++ b/frb_example/dart_minimal/rust/src/frb_generated.web.rs @@ -4,6 +4,7 @@ // Section: imports use super::*; +use crate::api::minimal::*; use flutter_rust_bridge::for_generated::byteorder::{NativeEndian, ReadBytesExt, WriteBytesExt}; use flutter_rust_bridge::for_generated::transform_result_dco; use flutter_rust_bridge::for_generated::wasm_bindgen; @@ -13,3 +14,31 @@ use flutter_rust_bridge::{Handler, IntoIntoDart}; // Section: boilerplate flutter_rust_bridge::frb_generated_boilerplate_web!(); + +#[wasm_bindgen] +pub fn rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + ptr: *const std::ffi::c_void, +) { + MoiArc::>::increment_strong_count(ptr as _); +} + +#[wasm_bindgen] +pub fn rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyAudioParam( + ptr: *const std::ffi::c_void, +) { + MoiArc::>::decrement_strong_count(ptr as _); +} + +#[wasm_bindgen] +pub fn rust_arc_increment_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + ptr: *const std::ffi::c_void, +) { + MoiArc::>::increment_strong_count(ptr as _); +} + +#[wasm_bindgen] +pub fn rust_arc_decrement_strong_count_RustOpaque_flutter_rust_bridgefor_generatedRustAutoOpaqueInnerMyNode( + ptr: *const std::ffi::c_void, +) { + MoiArc::>::decrement_strong_count(ptr as _); +}