Skip to content

Commit cbbb5d9

Browse files
authored
Merge pull request fzyzcjy#1603 from fzyzcjy/feat/11680
Fix compile error when the user crate does not have anyhow as direct dependency
2 parents 7a79a79 + 8ce16d9 commit cbbb5d9

File tree

8 files changed

+136
-126
lines changed

8 files changed

+136
-126
lines changed

frb_codegen/src/library/codegen/generator/wire/rust/spec_generator/misc/wire_func.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ fn generate_code_call_inner_func_result(func: &IrFunc, inner_func_args: Vec<Stri
166166

167167
if matches!(&func.output, IrType::RustAutoOpaque(_)) {
168168
if func.fallible() {
169-
ans = format!("Result::<_,anyhow::Error>::Ok(flutter_rust_bridge::for_generated::rust_auto_opaque_encode({ans}?))");
169+
ans = format!("Result::<_,flutter_rust_bridge::for_generated::anyhow::Error>::Ok(flutter_rust_bridge::for_generated::rust_auto_opaque_encode({ans}?))");
170170
} else {
171171
ans = format!("flutter_rust_bridge::for_generated::rust_auto_opaque_encode({ans})");
172172
}
@@ -175,7 +175,7 @@ fn generate_code_call_inner_func_result(func: &IrFunc, inner_func_args: Vec<Stri
175175
if !func.fallible() {
176176
let error_type = if (func.inputs.iter()).any(|x| matches!(x.ty, IrType::RustAutoOpaque(_)))
177177
{
178-
"anyhow::Error"
178+
"flutter_rust_bridge::for_generated::anyhow::Error"
179179
} else {
180180
"()"
181181
};
@@ -243,7 +243,7 @@ fn generate_code_closure(
243243
) -> String {
244244
let codec = (func.codec_mode_pack.rust2dart.to_string()).to_case(Case::Snake);
245245
let maybe_result = if matches!(&func.output, IrType::RustAutoOpaque(_)) && func.fallible() {
246-
"-> Result::<_,anyhow::Error>".to_string()
246+
"-> Result::<_,flutter_rust_bridge::for_generated::anyhow::Error>".to_string()
247247
} else {
248248
"".to_string()
249249
};

frb_codegen/src/library/codegen/ir/ty/delegate.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ impl IrTypeTrait for IrTypeDelegate {
130130
IrTypeDelegate::Uuid => "uuid::Uuid".to_owned(),
131131
// IrTypeDelegate::Uuids => "Vec<uuid::Uuid>".to_owned(),
132132
IrTypeDelegate::Backtrace => "backtrace::Backtrace".to_owned(),
133-
IrTypeDelegate::AnyhowException => "anyhow::Error".to_owned(),
133+
IrTypeDelegate::AnyhowException => {
134+
"flutter_rust_bridge::for_generated::anyhow::Error".to_owned()
135+
}
134136
IrTypeDelegate::Map(ir) => format!(
135137
"std::collections::HashMap<{}, {}>",
136138
ir.key.rust_api_type(),

frb_example/gallery/rust/src/frb_generated.io.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ use flutter_rust_bridge::{Handler, IntoIntoDart};
1111

1212
// Section: dart2rust
1313

14-
impl CstDecode<anyhow::Error> for *mut wire_cst_list_prim_u_8_strict {
15-
fn cst_decode(self) -> anyhow::Error {
14+
impl CstDecode<flutter_rust_bridge::for_generated::anyhow::Error>
15+
for *mut wire_cst_list_prim_u_8_strict
16+
{
17+
fn cst_decode(self) -> flutter_rust_bridge::for_generated::anyhow::Error {
1618
unimplemented!()
1719
}
1820
}

frb_example/gallery/rust/src/frb_generated.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ fn wire_DataFrame_get_column_names_impl(
104104
let api_that = that.cst_decode();
105105
transform_result_dco((move || {
106106
let api_that = api_that.rust_auto_opaque_decode_ref()?;
107-
Result::<_, anyhow::Error>::Ok(crate::api::polars::DataFrame::get_column_names(
108-
&api_that,
109-
))
107+
Result::<_, flutter_rust_bridge::for_generated::anyhow::Error>::Ok(
108+
crate::api::polars::DataFrame::get_column_names(&api_that),
109+
)
110110
})())
111111
},
112112
)
@@ -124,7 +124,7 @@ fn wire_DataFrame_lazy_impl(
124124
let api_that = that.cst_decode();
125125
transform_result_dco((move || {
126126
let api_that = api_that.rust_auto_opaque_decode_owned()?;
127-
Result::<_, anyhow::Error>::Ok(
127+
Result::<_, flutter_rust_bridge::for_generated::anyhow::Error>::Ok(
128128
flutter_rust_bridge::for_generated::rust_auto_opaque_encode(
129129
crate::api::polars::DataFrame::lazy(api_that),
130130
),
@@ -149,7 +149,7 @@ fn wire_Expr_gt_impl(
149149
transform_result_dco((move || {
150150
let api_that = api_that.rust_auto_opaque_decode_owned()?;
151151
let api_other = api_other.rust_auto_opaque_decode_owned()?;
152-
Result::<_, anyhow::Error>::Ok(
152+
Result::<_, flutter_rust_bridge::for_generated::anyhow::Error>::Ok(
153153
flutter_rust_bridge::for_generated::rust_auto_opaque_encode(
154154
crate::api::polars::Expr::gt(api_that, api_other),
155155
),
@@ -171,7 +171,7 @@ fn wire_Expr_sum_impl(
171171
let api_that = that.cst_decode();
172172
transform_result_dco((move || {
173173
let api_that = api_that.rust_auto_opaque_decode_owned()?;
174-
Result::<_, anyhow::Error>::Ok(
174+
Result::<_, flutter_rust_bridge::for_generated::anyhow::Error>::Ok(
175175
flutter_rust_bridge::for_generated::rust_auto_opaque_encode(
176176
crate::api::polars::Expr::sum(api_that),
177177
),
@@ -195,7 +195,7 @@ fn wire_LazyFrame_collect_impl(
195195
move |context| {
196196
transform_result_dco((move || {
197197
let api_that = api_that.rust_auto_opaque_decode_owned()?;
198-
Result::<_, anyhow::Error>::Ok(
198+
Result::<_, flutter_rust_bridge::for_generated::anyhow::Error>::Ok(
199199
flutter_rust_bridge::for_generated::rust_auto_opaque_encode(
200200
crate::api::polars::LazyFrame::collect(api_that),
201201
),
@@ -221,7 +221,7 @@ fn wire_LazyFrame_filter_impl(
221221
transform_result_dco((move || {
222222
let api_that = api_that.rust_auto_opaque_decode_owned()?;
223223
let api_predicate = api_predicate.rust_auto_opaque_decode_owned()?;
224-
Result::<_, anyhow::Error>::Ok(
224+
Result::<_, flutter_rust_bridge::for_generated::anyhow::Error>::Ok(
225225
flutter_rust_bridge::for_generated::rust_auto_opaque_encode(
226226
crate::api::polars::LazyFrame::filter(api_that, api_predicate),
227227
),
@@ -246,7 +246,7 @@ fn wire_LazyFrame_group_by_impl(
246246
transform_result_dco((move || {
247247
let api_that = api_that.rust_auto_opaque_decode_owned()?;
248248
let api_expr = api_expr.rust_auto_opaque_decode_owned()?;
249-
Result::<_, anyhow::Error>::Ok(
249+
Result::<_, flutter_rust_bridge::for_generated::anyhow::Error>::Ok(
250250
flutter_rust_bridge::for_generated::rust_auto_opaque_encode(
251251
crate::api::polars::LazyFrame::group_by(api_that, api_expr),
252252
),
@@ -271,7 +271,7 @@ fn wire_LazyGroupBy_agg_impl(
271271
transform_result_dco((move || {
272272
let api_that = api_that.rust_auto_opaque_decode_owned()?;
273273
let api_expr = api_expr.rust_auto_opaque_decode_owned()?;
274-
Result::<_, anyhow::Error>::Ok(
274+
Result::<_, flutter_rust_bridge::for_generated::anyhow::Error>::Ok(
275275
flutter_rust_bridge::for_generated::rust_auto_opaque_encode(
276276
crate::api::polars::LazyGroupBy::agg(api_that, api_expr),
277277
),
@@ -361,7 +361,7 @@ impl CstDecode<usize> for usize {
361361
self
362362
}
363363
}
364-
impl SseDecode for anyhow::Error {
364+
impl SseDecode for flutter_rust_bridge::for_generated::anyhow::Error {
365365
fn sse_decode(deserializer: &mut flutter_rust_bridge::for_generated::SseDeserializer) -> Self {
366366
unimplemented!("not yet supported in serialized mode, feel free to create an issue");
367367
}
@@ -514,7 +514,7 @@ impl flutter_rust_bridge::IntoIntoDart<crate::api::mandelbrot::Size>
514514
}
515515
}
516516

517-
impl SseEncode for anyhow::Error {
517+
impl SseEncode for flutter_rust_bridge::for_generated::anyhow::Error {
518518
fn sse_encode(self, serializer: &mut flutter_rust_bridge::for_generated::SseSerializer) {
519519
<String>::sse_encode(format!("{:?}", self), serializer);
520520
}

frb_example/gallery/rust/src/frb_generated.web.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ where
2121
(!self.is_null() && !self.is_undefined()).then(|| self.cst_decode())
2222
}
2323
}
24-
impl CstDecode<anyhow::Error> for String {
25-
fn cst_decode(self) -> anyhow::Error {
24+
impl CstDecode<flutter_rust_bridge::for_generated::anyhow::Error> for String {
25+
fn cst_decode(self) -> flutter_rust_bridge::for_generated::anyhow::Error {
2626
unimplemented!()
2727
}
2828
}
@@ -83,8 +83,10 @@ impl CstDecode<crate::api::mandelbrot::Size>
8383
}
8484
}
8585
}
86-
impl CstDecode<anyhow::Error> for flutter_rust_bridge::for_generated::wasm_bindgen::JsValue {
87-
fn cst_decode(self) -> anyhow::Error {
86+
impl CstDecode<flutter_rust_bridge::for_generated::anyhow::Error>
87+
for flutter_rust_bridge::for_generated::wasm_bindgen::JsValue
88+
{
89+
fn cst_decode(self) -> flutter_rust_bridge::for_generated::anyhow::Error {
8890
unimplemented!()
8991
}
9092
}

frb_example/pure_dart/rust/src/frb_generated.io.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ use flutter_rust_bridge::{Handler, IntoIntoDart};
2121

2222
// Section: dart2rust
2323

24-
impl CstDecode<anyhow::Error> for *mut wire_cst_list_prim_u_8_strict {
25-
fn cst_decode(self) -> anyhow::Error {
24+
impl CstDecode<flutter_rust_bridge::for_generated::anyhow::Error>
25+
for *mut wire_cst_list_prim_u_8_strict
26+
{
27+
fn cst_decode(self) -> flutter_rust_bridge::for_generated::anyhow::Error {
2628
unimplemented!()
2729
}
2830
}

0 commit comments

Comments
 (0)