Skip to content

Add #[derive(FromRef)] - #1430

Merged
davidpdrsn merged 15 commits into
mainfrom
derive-from-ref
Oct 10, 2022
Merged

Add #[derive(FromRef)]#1430
davidpdrsn merged 15 commits into
mainfrom
derive-from-ref

Conversation

@davidpdrsn

@davidpdrsn davidpdrsn commented Sep 28, 2022

Copy link
Copy Markdown
Member

Given how straight forward this is I think it makes sense to support.

TODO

  • Docs
  • Tests

probably wouldn't work at all since the whole state likely needs `Clone`
@davidpdrsn
davidpdrsn marked this pull request as ready for review September 29, 2022 15:21
@davidpdrsn
davidpdrsn requested a review from jplatte September 29, 2022 15:21

@jplatte jplatte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be re-exporting this and the FromRequest[Parts] macros like we do debug_handler?

Comment thread axum-macros/src/from_ref.rs Outdated
Comment thread axum-macros/src/from_ref.rs Outdated
Comment thread axum-macros/src/from_ref.rs Outdated
@davidpdrsn

Copy link
Copy Markdown
Member Author

Yes I think so! Will add that later!

@davidpdrsn
davidpdrsn requested a review from jplatte October 9, 2022 20:58
/// This trait can be derived using `#[derive(axum_macros::FromRef)]`.
///
/// [`State`]: https://docs.rs/axum/0.6/axum/extract/struct.State.html
/// [`#[derive(axum_macros::FromRef)]`]: https://docs.rs/axum-macros/latest/axum_macros/derive.FromRef.html

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could add axum-macros as a dev-dependency so we can use an intra-doc link here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weren't there something with docsrs not building dev dependencies, and that is why we have the __private_docs feature in axum?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm yeah, that might be right.

Comment thread axum-macros/src/lib.rs
/// #[derive(FromRef)]
/// struct AppState {
/// auth_token: AuthToken,
/// database_pool: DatabasePool,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be nice to have #[from_ref(skip)] so you can avoid "weird" impls like FromRef<AppState> for String.

Doesn't have to be in this PR, of course.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I've gone back and forth on this. We can add that later if someone requests it.

@davidpdrsn
davidpdrsn enabled auto-merge (squash) October 10, 2022 16:14
@davidpdrsn
davidpdrsn merged commit 9c0a89c into main Oct 10, 2022
@davidpdrsn
davidpdrsn deleted the derive-from-ref branch October 10, 2022 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants