Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Got unknown return type #888

Closed
MaxKingPor opened this issue Nov 25, 2022 · 7 comments
Closed

Got unknown return type #888

MaxKingPor opened this issue Nov 25, 2022 · 7 comments
Labels
question Further information is requested

Comments

@MaxKingPor
Copy link

image

  --> src/lib.rs:21:1
   |
21 | #[pg_extern]
   | ^^^^^^^^^^^^
   |
   = help: message: called `Result::unwrap()` on an `Err` value: Error("Got unknown return type: ImplTrait(TypeImplTrait { impl_token: Impl, bounds: [Trait(TraitBound { paren_token: None, modifier: None, lifetimes: None, path: Path { leading_colon: None, segments: [PathSegment { ident: Ident { ident: \"Iterator\", span: #0 bytes(309..317) }, arguments: AngleBracketed(AngleBracketedGenericArguments { colon2_token: None, lt_token: Lt, args: [Binding(Binding { ident: Ident { ident: \"Item\", span: #0 bytes(318..322) }, eq_token: Eq, ty: Tuple(TypeTuple { paren_token: Paren, elems: [Macro(TypeMacro { mac: Macro { path: Path { leading_colon: None, segments: [PathSegment { ident: Ident { ident: \"name\", span: #0 bytes(326..330) }, arguments: None }] }, bang_token: Bang, delimiter: Paren(Paren), tokens: TokenStream [Ident { ident: \"a\", span: #0 bytes(332..333) }, Punct { ch: ',', spacing: Alone, span: #0 bytes(333..334) }, Ident { ident: \"i32\", span: #0 bytes(335..338) }] } }), Comma, Macro(TypeMacro { mac: Macro { path: Path { leading_colon: None, segments: [PathSegment { ident: Ident { ident: \"name\", span: #0 bytes(341..345) }, arguments: None }] }, bang_token: Bang, delimiter: Paren(Paren), tokens: TokenStream [Ident { ident: \"b\", span: #0 bytes(347..348) }, Punct { ch: ',', spacing: Alone, span: #0 bytes(348..349) }, Ident { ident: \"i32\", span: #0 bytes(350..353) }] } })] }) })], gt_token: Gt }) }] } })] })")

@workingjubilee
Copy link
Member

You probably need to be using TableIterator<'a, T>.

@workingjubilee workingjubilee added the question Further information is requested label Nov 27, 2022
@workingjubilee
Copy link
Member

@MaxKingPor Does that answer your question?

#[pg_extern]
fn floop<'a>() -> TableIterator<'a, (name!(a, i32), name!(b, i32))> {
    TableIterator::new(None.into_iter())
}

容易理解吗?

@MaxKingPor
Copy link
Author

@MaxKingPor Does that answer your question?

#[pg_extern]
fn floop<'a>() -> TableIterator<'a, (name!(a, i32), name!(b, i32))> {
    TableIterator::new(None.into_iter())
}

容易理解吗?

Thank you. But Your document has not been modified
image

@workingjubilee
Copy link
Member

Ah, will fix that.

@kavirajk
Copy link

Also got similar error for following example.

#[pg_extern]
fn generate_series(start: i64, end: i64, step: default!(i64, 1)) -> impl std::iter::Iterator {
    (start..end).into_iter().step_by(step as usize).into_iter()
}
error: Got unknown return type: ImplTrait(TypeImplTrait { impl_token: Impl, bounds: [Trait(TraitBound { paren_token: None, modifier: None, lifetimes: None, path: Path { leading_colon: None, segments: [PathSegment { ident: Ident { ident: "std", span: #0 bytes(565..568) }, arguments: None }, Colon2, PathSegment { ident: Ident { ident: "iter", span: #0 bytes(570..574) }, arguments: None }, Colon2, PathSegment { ident: Ident { ident: "Iterator", span: #0 bytes(576..584) }, arguments: None }] } })] })
  --> src/lib.rs:25:1
   |
25 | #[pg_extern]
   | ^^^^^^^^^^^^
   |
   = note: this error originates in the attribute macro `pg_extern` (in Nightly builds, run with -Z macro-backtrace for more info)

Followed example from this video.
https://www.youtube.com/watch?v=RORkgaURcS0&t=555s&ab_channel=PostgresConference

So my understanding is pgx doesn't allow normal impl std::iterator::Iterator as return value any more? Instead I have to use one of the SetOfIterator or TableIterator only? But those two doesn't look like correct iterators for my use case here.

@workingjubilee

@workingjubilee
Copy link
Member

wow didn't see this.

Yes, that's correct.

@workingjubilee
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants