Skip to content

Conversation

@seqre
Copy link
Member

@seqre seqre commented Jan 11, 2026

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:

  • basic Cot types
  • body
  • error
  • headers
  • html
  • json
  • response
  • request
  • middleware
  • handler

I think moving router would 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-core being a separate crate, the following items had to become public:

  • cot_core::error::backtrace - needed for ErrorPage
  • cot_core::error::error_impl::* - to allow implementing of errors in cot
  • Error.backtrace() - needed for supplying error backtrace in ErrorPageTemplateBuilder
  • Backtrace.frames() - needed for the Template derive for ErrorPageTemplate (used in error.html template)
  • StackFrame.symbol_name() - as above
  • StackFrame.location() - as above
  • StackFrame - as above
  • Body.axum() - needed for request_axum_to_cot in project.rs
  • InvalidContentType
  • AppName
  • RouteName
  • BoxRequestHandler - used in openapi.rs and router.rs
  • into_box_request_handler - used in method.rs and router.rs

Stayed private with following gotchas:

  • NotFound.router() - removed deprecated NotFound constructor methods from Error

@github-actions github-actions bot added the C-lib Crate: cot (main library crate) label Jan 11, 2026
@github-actions

This comment was marked as resolved.

@seqre seqre force-pushed the cot-core-reloaded branch from a799923 to c1c890a Compare January 11, 2026 19:30
@seqre seqre self-assigned this Jan 11, 2026
@seqre seqre requested review from ElijahAhianyo and m4tx January 11, 2026 19:36
@seqre seqre marked this pull request as ready for review January 11, 2026 19:36
Copilot AI review requested due to automatic review settings January 11, 2026 19:36

This comment was marked as resolved.

@seqre
Copy link
Member Author

seqre commented Jan 12, 2026

The nightly error should be fixed by rust-lang/rust#150939

@seqre seqre force-pushed the cot-core-reloaded branch from 0033822 to ead28ff Compare January 12, 2026 18:59
Copilot AI review requested due to automatic review settings January 12, 2026 18:59

This comment was marked as duplicate.

Copy link
Member

@m4tx m4tx left a 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.

Self::build_error_data(&mut error_data, error);
}
Kind::WithMessage(message) => {
Kind::WithMessage { 0: message, .. } => {
Copy link
Member

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".

Copy link
Member Author

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

Copilot AI review requested due to automatic review settings January 16, 2026 18:08
@seqre seqre force-pushed the cot-core-reloaded branch from e364514 to 6a3a723 Compare January 16, 2026 18:08

This comment was marked as outdated.

@seqre seqre force-pushed the cot-core-reloaded branch from 6a3a723 to 9b372af Compare January 16, 2026 18:11
Copilot AI review requested due to automatic review settings January 16, 2026 18:14
@seqre seqre requested a review from m4tx January 16, 2026 18:14

This comment was marked as duplicate.

@seqre seqre force-pushed the cot-core-reloaded branch from ced97e4 to 0536013 Compare January 16, 2026 18:19
@codecov
Copy link

codecov bot commented Jan 16, 2026

Codecov Report

❌ Patch coverage is 93.60902% with 17 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cot-core/src/request/extractors.rs 94.11% 3 Missing and 4 partials ⚠️
cot-core/src/middleware.rs 85.71% 6 Missing ⚠️
cot/src/request/extractors.rs 86.66% 2 Missing ⚠️
cot-core/src/request.rs 98.21% 0 Missing and 1 partial ⚠️
cot/src/error_page.rs 0.00% 1 Missing ⚠️
Flag Coverage Δ
rust 90.41% <93.60%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cot-core/src/body.rs 84.89% <100.00%> (ø)
cot-core/src/error/backtrace.rs 96.82% <100.00%> (ø)
cot-core/src/error/error_impl.rs 90.13% <100.00%> (ø)
cot-core/src/error/method_not_allowed.rs 100.00% <ø> (ø)
cot-core/src/error/uncaught_panic.rs 75.00% <ø> (ø)
cot-core/src/handler.rs 78.26% <100.00%> (ø)
cot-core/src/html.rs 97.44% <ø> (ø)
cot-core/src/request/path_params_deserializer.rs 63.49% <ø> (ø)
cot-core/src/response.rs 96.66% <ø> (ø)
cot-core/src/response/into_response.rs 99.26% <100.00%> (ø)
... and 26 more
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI review requested due to automatic review settings January 18, 2026 12:43
Copy link

Copilot AI left a 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.

Copilot AI review requested due to automatic review settings January 18, 2026 13:59

This comment was marked as spam.

Copy link
Member

@m4tx m4tx left a 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).

Comment on lines +244 to +251
/// [`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)
Copy link
Member

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

Copy link
Member Author

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?

Copy link
Member

Choose a reason for hiding this comment

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

How about we move these docs to the main crate? If we mention high-level concepts in this doc, I think it's okay to move the docs to the high-level crate.

The problematic one is the new_redirect method inside the ResponseExt trait. I'm honestly thinking that this should be a separate struct (probably defined in cot) rather than a method in an extension trait, as it would be more consistent with the rest of our APIs now, and also would make the core types less "special". Basically instead of Response::new_redirect("link") we should have Redirect::new("link"). What do you think?


#[must_use]
pub(crate) fn backtrace(&self) -> &CotBacktrace {
pub fn backtrace(&self) -> &CotBacktrace {
Copy link
Member

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.

Copy link
Member Author

@seqre seqre Jan 18, 2026

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?

Copy link
Member

Choose a reason for hiding this comment

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

I think the error struct should be kept in the core crate. I can see several approaches here:

  1. #[doc(hidden)] - the easiest way. Perhaps it's good enough (I think some popular crates such as tokio and serde do use it), but it doesn't really stop the users from calling the method.
  2. Defining an extension trait (similar to ResponseExt, for example), and implementing it for the Error type. The extension trait is then public in cot-core, but not reexported in cot. This way the method will be invisible to the normal users, but still accessible if you use cot-core directly.
  3. Sort of similar to the one above: defining an access token. The code explains it all:
mod private {
    pub struct Token;
}

pub struct MyStruct;

impl MyStruct {
    pub fn restricted_method(&self, _: private::Token) {
        println!("Restricted!");
    }
}

#[doc(hidden)]
pub fn get_token() -> private::Token {
    private::Token
}

I'll let you pick the favorite one for the job.

Copilot AI review requested due to automatic review settings January 18, 2026 21:24
@seqre seqre force-pushed the cot-core-reloaded branch from b7b3ec3 to 9fd687f Compare January 18, 2026 21:24
@seqre seqre review requested due to automatic review settings January 18, 2026 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-lib Crate: cot (main library crate)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants