-
-
Notifications
You must be signed in to change notification settings - Fork 35
refactor!: extract framework core to cot-core #444
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
base: master
Are you sure you want to change the base?
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
a799923 to
c1c890a
Compare
|
The nightly error should be fixed by rust-lang/rust#150939 |
0033822 to
ead28ff
Compare
m4tx
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks nice, and seems like it lays a solid foundation for our eventual extraction of the ORM to a separate crate!
I've tried to generate the docs with just docs and it seems like there's a ton of warnings coming from cot-core (outside of missing examples, which are expected) - please make sure these are fixed before we consider merging this.
cot/src/error_page.rs
Outdated
| Self::build_error_data(&mut error_data, error); | ||
| } | ||
| Kind::WithMessage(message) => { | ||
| Kind::WithMessage { 0: message, .. } => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps it makes sense to change this enum variant to be a struct variant with named field rather than enum variant? After all, we might (however unlikely) want to add some more fields to it, at which point we'll probably need to add some naming so it's clear what they do. Think "future-proofing the APIs".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do it, but I doubt we'll want to expand that variant, so there's little to it
e364514 to
6a3a723
Compare
6a3a723 to
9b372af
Compare
ced97e4 to
0536013
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 41 out of 47 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
m4tx
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to make sure this change doesn't affect the user's experience. In particular, the docs must work as before, and we cannot expose any internal APIs (as this could cause some breakages in the long run).
| /// [`Bootstrapper`](../../cot/project/struct.Bootstrapper.html). | ||
| /// | ||
| /// It is returned by | ||
| /// [`Bootstrapper::into_bootstrapped_project`](cot::Bootstrapper::finish). | ||
| /// Typically, you don't need to interact with this type directly, except for | ||
| /// creating it in [`Project::middlewares`](cot::Project::middlewares) through | ||
| /// the [`RootHandlerBuilder::build`](cot::project::RootHandlerBuilder::build) | ||
| /// [`Bootstrapper::finish()`](../../cot/project/struct.Bootstrapper.html#method.finish). | ||
| /// Typically, you don't need to interact with this type directly, except | ||
| /// for creating it in | ||
| /// [`Project::middlewares()`](../../cot/project/trait.Project.html#method.middlewares) through the | ||
| /// [`RootHandlerBuilder::build()`](../../cot/project/struct.RootHandlerBuilder.html#method.build) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These links (and probably most others) don't work when you look at the docs from the cot crate. Is there really no way to avoid specifying exact paths? How do other projects handle this? I can see some discussion on this, e.g. rust-lang/docs.rs#1588
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be a skill issue on my side, but whatever I tried, I could not make it work properly. The issue I think is that cot is not a dependency of cot_core, so rustdoc has issues with linking to it. I attempted using unstable rustdoc-map feature with doc.extern-map.registries, but it did not seem to work. We could always just put there normal crates.io links to latest, but I don't like it. Could you assist?
|
|
||
| #[must_use] | ||
| pub(crate) fn backtrace(&self) -> &CotBacktrace { | ||
| pub fn backtrace(&self) -> &CotBacktrace { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an implementation detail and cannot be exposed to users. The CotBacktrace struct is (rightly) not even reexported in Cot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's problematic, it has to be public so that the error page can use it to show backtrace properly. The easiest solution would be to pull that to cot, but then we would have to pull Error as well and it's impossible as it's used in cot_core. Alternatively, we could pull ErrorPage to cot_core, but it's not really core and it's specific to cot. Thoughts?
b7b3ec3 to
9fd687f
Compare
This PR attempts to extract the core functionality of the framework to separate crate to speed up compilation among other reasons.
The modules fully/partially moved:
bodyerrorheadershtmljsonresponserequestmiddlewarehandlerI think moving
routerwould be valid move as well, but in the current format it's too intertwined with OpenAPI functionality (that we don't want to pull into core) that it can be done at a later time.With
cot-corebeing a separate crate, the following items had to become public:cot_core::error::backtrace- needed forErrorPagecot_core::error::error_impl::*- to allow implementing of errors incotError.backtrace()- needed for supplying error backtrace inErrorPageTemplateBuilderBacktrace.frames()- needed for theTemplatederive forErrorPageTemplate(used inerror.htmltemplate)StackFrame.symbol_name()- as aboveStackFrame.location()- as aboveStackFrame- as aboveBody.axum()- needed forrequest_axum_to_cotinproject.rsInvalidContentTypeAppNameRouteNameBoxRequestHandler- used inopenapi.rsandrouter.rsinto_box_request_handler- used inmethod.rsandrouter.rsStayed private with following gotchas:
NotFound.router()- removed deprecatedNotFoundconstructor methods fromError