Simplify API and use "state" to improve type-safety #27
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The upshot of this PR is that:
Tx
is the only type that needs to be handled directly (i.e.use
d or otherwise named).Tx
'sFromRequestParts
implementation requiresaxum_sqlx_tx::State
, which goes someway to making it harder to forget to supply the extractor's dependencies (it doesn't prevent compilation whenLayer
is forgotten, but thesetup
methods return(State, Layer)
making it harder to miss).0927aab chore: doc typo
c9eccaf feat!: introduce
State
to makeTx
more type-safeTx
now implementsFromRequestParts<State>
, meaning theRouter
mustbe provided an instance of
State
in order for it to compile.State
can be constructed withLayer::new
, which now returns a tupleof
Layer
andState
. The idea behind constructing both in the samefunction is to make it harder to forget to add the
Layer
, howeverLayer::new
is perhaps not the best place for it long-term.Ultimately this has the desired effect of making
Tx
more type-safe -applications that attempt to use
Tx
without providingState
won'tcompile, and the API for obtaining
State
makes it harder to forget toadd the
Layer
.BREAKING CHANGE:
Layer::new
now returns a(Layer, State)
tuple. Thiscan be consumed easily by destructuring assignment.
Tx
now requiresState
to be provided onRouter
s in order for theRouter
to beusable.
32a0a0f feat: introduce
Tx::setup
,Tx::config
, andConfig
APIsThis will centralise the configuration API and reduce the number of
types that need to interacted with directly (i.e.
use
d) down to justTx
.e8f694e refactor!: remove
Layer::new
andLayer::new_with_error
This leaves
Tx::{setup,config}
as the only entrypoints to the API.Error handling documentation was also rewritten.
BREAKING CHANGE:
Layer::{new,new_with_error}
have been removed. UseTx::{setup,config}
instead.e2701a7 refactor!: rationalise generic error type bounds
Required bounds are now present on more
impl
blocks to provide betterdiagnostics if error types are missing required traits.
The
Layer
error type is now only required to implementFrom<sqlx::Error>
(technicallysqlx::Error
is required to implementInto<LayerError>
since this is more flexible).BREAKING CHANGE: The tighter bounds on
impl
blocks shouldn't breakalready working code, however the change to the
Layer
error typebounds will break error overrides that implement
From<axum_sqlx_tx::Error>
- this must be changed toFrom<sqlx::Error>
.e896b5a chore: doc fix