Skip to content

Commit

Permalink
Merge pull request #2180 from fzyzcjy/feat/12466
Browse files Browse the repository at this point in the history
  • Loading branch information
fzyzcjy authored Jul 3, 2024
2 parents bfc005a + 0906a1f commit a44f789
Show file tree
Hide file tree
Showing 12 changed files with 2,025 additions and 1,956 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::codegen::parser::mir::parser::ty::TypeParserWithContext;
use crate::codegen::parser::mir::ParseMode;
use crate::if_then_some;
use crate::utils::syn_utils::ty_to_string;
use anyhow::Context;
use syn::TypeTraitObject;

impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> {
Expand Down Expand Up @@ -37,21 +38,25 @@ impl<'a, 'b, 'c> TypeParserWithContext<'a, 'b, 'c> {
if let Some(trait_name_path) = extract_trait_name_path(type_trait_object) {
let trait_name = ty_to_string(&trait_name_path.segments.last().unwrap());
if let Some(trait_ty) = parse_type_trait(&trait_name, self.inner) {
let data = match self.context.parse_mode {
ParseMode::Early => None,
ParseMode::Normal => {
let trait_def_info = (self.inner.trait_def_infos.iter())
.find(|info| info.trait_def_name == trait_ty.name)
.with_context(|| {
format!("Cannot find trait def info for {:?}", trait_ty.name)
})?;
Some(MirTypeDelegateDynTraitData {
delegate_namespace: trait_def_info.delegate_namespace.clone(),
variants: trait_def_info.variants.clone(),
})
}
};

return Ok(Some(MirType::Delegate(MirTypeDelegate::DynTrait(
MirTypeDelegateDynTrait {
trait_def_name: trait_ty.name.clone(),
data: match self.context.parse_mode {
ParseMode::Early => None,
ParseMode::Normal => {
let trait_def_info = (self.inner.trait_def_infos.iter())
.find(|info| info.trait_def_name == trait_ty.name)
.unwrap();
Some(MirTypeDelegateDynTraitData {
delegate_namespace: trait_def_info.delegate_namespace.clone(),
variants: trait_def_info.variants.clone(),
})
}
},
data,
},
))));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import 'misc_no_twin_example_b.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';

// These functions are ignored because they are not marked as `pub`: `log`
// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `clone`, `clone`, `fmt`
// These types are ignored because they are not used by any `pub` functions: `Issue2170Struct`
// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `clone`, `clone`, `fmt`, `fmt`

Future<void> sameFunctionNameInDifferentFiles() => RustLib.instance.api
.crateApiMiscNoTwinExampleASameFunctionNameInDifferentFiles();
Expand Down Expand Up @@ -117,6 +118,10 @@ abstract class StructWithSimpleSetterTwinNormal implements RustOpaqueInterface {
set simpleSetter(int value);
}

abstract class Issue2170Trait {
Future<void> method();
}

class ItemContainerSolutionTwoTwinNormal {
String name;
final List<OpaqueItemTwinNormal> items;
Expand Down
6 changes: 6 additions & 0 deletions frb_example/pure_dart/lib/src/rust/frb_generated.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103094,6 +103094,12 @@ class RustLibApiImpl extends RustLibApiImplPlatform implements RustLibApi {
return raw as String;
}

@protected
Issue2170Trait dco_decode_TraitDef_Issue2170Trait(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
throw UnimplementedError();
}

@protected
MyTraitTwinMoi dco_decode_TraitDef_MyTraitTwinMoi(dynamic raw) {
// Codec=Dco (DartCObject based), see doc to use other codecs
Expand Down
3 changes: 3 additions & 0 deletions frb_example/pure_dart/lib/src/rust/frb_generated.io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4217,6 +4217,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
String dco_decode_String(dynamic raw);

@protected
Issue2170Trait dco_decode_TraitDef_Issue2170Trait(dynamic raw);

@protected
MyTraitTwinMoi dco_decode_TraitDef_MyTraitTwinMoi(dynamic raw);

Expand Down
3 changes: 3 additions & 0 deletions frb_example/pure_dart/lib/src/rust/frb_generated.web.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4219,6 +4219,9 @@ abstract class RustLibApiImplPlatform extends BaseApiImpl<RustLibWire> {
@protected
String dco_decode_String(dynamic raw);

@protected
Issue2170Trait dco_decode_TraitDef_Issue2170Trait(dynamic raw);

@protected
MyTraitTwinMoi dco_decode_TraitDef_MyTraitTwinMoi(dynamic raw);

Expand Down
15 changes: 15 additions & 0 deletions frb_example/pure_dart/rust/src/api/misc_no_twin_example_a.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,18 @@ impl MyStructWithTryFromTwinNormal {
self.0.to_owned()
}
}

// https://github.com/fzyzcjy/flutter_rust_bridge/issues/2170
pub trait Issue2170Trait {
fn method(&self);
}

pub struct Issue2170Struct {
pub field: Box<dyn Issue2170Trait>,
}

impl std::fmt::Debug for Issue2170Struct {
fn fmt(&self, _f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
unimplemented!()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import 'misc_no_twin_example_b.dart';
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated.dart';

// These functions are ignored because they are not marked as `pub`: `log`
// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `clone`, `clone`, `fmt`
// These types are ignored because they are not used by any `pub` functions: `Issue2170Struct`
// These function are ignored because they are on traits that is not defined in current crate (put an empty `#[frb]` on it to unignore): `clone`, `clone`, `fmt`, `fmt`

Future<void> sameFunctionNameInDifferentFiles() => RustLib.instance.api
.crateApiMiscNoTwinExampleASameFunctionNameInDifferentFiles();
Expand Down Expand Up @@ -117,6 +118,10 @@ abstract class StructWithSimpleSetterTwinNormal implements RustOpaqueInterface {
set simpleSetter(int value);
}

abstract class Issue2170Trait {
Future<void> method();
}

class ItemContainerSolutionTwoTwinNormal {
String name;
final List<OpaqueItemTwinNormal> items;
Expand Down
Loading

0 comments on commit a44f789

Please sign in to comment.