Decrusting the axum crate

Поділитися
Вставка
  • Опубліковано 28 лип 2024
  • In this stream, we peel back the crust on the axum crate - github.com/tokio-rs/axum/ - and explore its interface, structure, and mechanisms. We talk about tower::Service, the Handler trait, Routers, and the State extractor. We also get into the way axum ensures at compile time that all handlers have access to the state that they'll need at runtime.
    For more details about axum, see docs.rs/axum/latest/axum/.
    0:00:00 Introduction
    0:01:15 axum
    0:24:48 tower::Service
    0:36:58 The Handler trait and its impls
    1:15:20 The State extractor
    1:44:40 axum's use of other crates
    1:48:02 Unstable features axum wants
    1:49:49 State requiring that T: CLone
    2:04:32 FromRef
    2:07:31 Handling custom HTTP methods
    2:10:06 axum_extra
    Live version with chat (part 1): ua-cam.com/users/liventqGaoEFYiQ?...
    Live version with chat (part 2): ua-cam.com/users/live36m4dxJ0AHg?...
  • Наука та технологія

КОМЕНТАРІ • 106

  • @nick-lehmann
    @nick-lehmann Рік тому +423

    Since I didn't find a better place to vote for new videos, I would like to make this the "please do a decrusting tracing" button 🙌🏻

  • @ianakotey
    @ianakotey Рік тому +101

    Man, you're such a joy to listen to. Thanks for the work you do for us

  • @Hellbending
    @Hellbending 3 місяці тому +3

    "Tower de-crustin' when?"
    Memes aside - I think this would be the natural progression of the series as you seem to have covered a large portion of the existing Web-Service/Backend crates and associated tooling.
    Only 1/4 the way through and already had a couple of small things click in the back of my mind so I gotta say - thank you for those moments cos they're so rewarding.
    Really appreciate these my man, like I cannot express that enough. Need more people like yourself doing good work via 'teardowns' and longer-form videos where in-depth things actually get/can be discussed like this, keep up the awesomeness brother! ♥

  • @romanstingler435
    @romanstingler435 Рік тому +32

    If it is possible, don't stop :)
    We love you and your videos

  • @fhools
    @fhools Рік тому +11

    I love the decrust series. I'm really looking forward to a deep dive into tracing crate!

  • @mikemikemike444
    @mikemikemike444 Рік тому +25

    Hey Jon, just wanted to to poke my head in and compliment you on Rust for Rustaceans. I bought it right when I was starting to learn Rust, with an attitude of, "my goal is to get to a point where I more-or-less understand the things in this book." Now, an embarrassing number of months later, I'm reading it and it's beyond awesome. Thanks man and congrats on surviving the move!

    • @SvenBrettschneider
      @SvenBrettschneider 11 місяців тому

      Just bought it :)
      These videos are just so great to watch!

  • @willemmeints3123
    @willemmeints3123 28 днів тому

    I took me three sittings to get through all the content. I'm happy you made this recording. I tried to make sense of everything that's documented but it's hard if you're learning rust and only built one or two applications with it. This is a great walk through with much needed hints to get beyond the basic compile errors!

  • @voidsifr
    @voidsifr Рік тому +13

    OMG, this stream was AWESOME. I am using axum a ton right now but never really dug into it. This really really demystified it for me. Always enjoy your streams even though I often watch them after the fact. I totally understand axum (and Rust stuff in general) way better now. Thank you for your time and awesome work.

  • @user-ru7up7wk2n
    @user-ru7up7wk2n Рік тому +2

    You do a great job explaining complex topics. I watched this start-to-finish, which is rare these days. Thank you!

  • @Jayemjigga
    @Jayemjigga 11 місяців тому +3

    I'd love to see you decrust Bevy :D I use Axum all the time and this was awesome, thanks Jon!

  • @Wodziwob
    @Wodziwob 6 місяців тому +1

    I just hit the incorrect fromrequest vs from fromrequestparts param order thing with the unhelpful compiler message. Your video helped me understand the reason why it acts that way. SO HELPFUL. Thank you so much for doing these.

  • @christopher8641
    @christopher8641 Рік тому +3

    Incredible stream / video. Really cleared up a lot of thing about web related concepts as well. Been reading your book and it is equally filled with quality tips and scenarios. Rust was basically my first programming language and the experience was truly (,brutally) humbling. But, the "crust" and "decrust" series was what really made me have those "Ohhhhh, that makes sense now" moments.

  • @Mahmudul_Hasan92
    @Mahmudul_Hasan92 8 місяців тому

    Thank you for continuing to share your knowledge. These streams are invaluable to me personally, and I sincerely hope that you stay mentally, physically and financially healthy to keep doing them.

  • @f-vall
    @f-vall Рік тому +2

    "Once you have a web server your bottleneck of the application is not dynamic dispatch, so if you can make the ergonomics of using the tool nicer by doing a Box somewhere, it is probably worthwile."
    Well said 👏

  • @JR-wu3rx
    @JR-wu3rx 8 місяців тому

    Thank you so much for making these videos. Honestly there are not many Rust videos where they actually break down the code to understand the design and structure to make me a more informed programmer. They seem to be mostly surface level how-to videos.

  • @indierusty
    @indierusty Рік тому +14

    'Decrusting Bevy ECS' next? I really want to know how function is bevy ECS system and it gets it arguments?.

    • @dealloc
      @dealloc Рік тому +1

      It's pretty much the same as axum's Handler macro expansion. You can find the implementation in bevy_ecs within exclusive_function_system and exclusive_system_param modules.
      They use a _all_tuples_ macro as well, which is more generic, as they pass number of variadics to implement for, but is nevertheless the same result.

    • @tomaspecl1082
      @tomaspecl1082 5 місяців тому

      I was just thinking that it is basically the same as bevy. The stuff that is made possible by all the traits and impls is really awesome and quite magical. But not that magical now, I kind of know how it works.

    • @indierusty
      @indierusty 5 місяців тому

      @@tomaspecl1082 yes it actually make sense to me now. Also know as Extractor functions. It supprised me how simple and powerful this system is.

  • @arlaxia
    @arlaxia 2 місяці тому

    This was perfect, exactly what I needed. I was taking my first steps in Rust web dev recently and was trying to look around axum source code to find out how it did the "handler magic", but couldn't quite figure it out. You explained it fantastically.

  • @jonnyso1
    @jonnyso1 Рік тому +4

    As you were introducing Axum I think it would also be worth including that it does provide ways for creating middlewares and extractors that are a little easier than making a tower service directly.

  • @blakewilloughby398
    @blakewilloughby398 Рік тому +1

    Axum is a great crate! This video is awesome! Thank you sir!❤

  • @zoes17
    @zoes17 Рік тому +3

    New decrusted from Jon, LET'S GO!

  • @flwi
    @flwi 4 місяці тому

    You're soo good at explaining things! I learned a lot and had fun following your explanations along the way!

  • @rsjeyt
    @rsjeyt Рік тому +1

    You're amazing. I literally needed this right now.

  • @edcunningham5562
    @edcunningham5562 Рік тому

    such a good stream, thanks man!

  • @JaLikon65
    @JaLikon65 11 місяців тому +1

    Imagine my surprise as a Rust noob when -- somehow -- at 48mins into an in-depth video how an HTTP Router works, I hear that at the core of this all we need something called "Cow".

  • @andredasilva6807
    @andredasilva6807 Рік тому

    please keep on doing these streams. even if its not possible to catch it live. its fantastic to watch as a video :) its always amazing to look at a crate or a topic in rust in more detail. and i think everyone learns a lot from it. As you mentioned tracing would be really intresting to decrust. Or maybe sqlx. espacially the query / query_as macros. I am currtently using actix which would be really intresting to decrust too. But i think with axum you already have covered a great web framework ;).

  • @DHorse
    @DHorse Рік тому

    You display a deep knowledge.

  • @Tarekconqueso
    @Tarekconqueso 2 місяці тому

    this is a goldmine. Man i wish i was present during the stream, i have so many questions :DD

  • @crabbaby91
    @crabbaby91 11 місяців тому

    Really helpful! I think the reason why we can't swap the Json and AppenderHeaders at 1:0815 is that Json doesn't impl IntoResponseParts, since the AppenderHeaders impls IntoResponse so it can be the last param. anyway, it doesn't affect the result.

  • @dealloc
    @dealloc Рік тому +1

    It's a very interesting pattern, which Bevy also uses and makes it quite easy to work with. Although I have read somewhere that there are some downsides to this pattern, regardless of compile time, but haven't dug deeper into it.
    It would be nice if variadics were supported at syntax level in Rust. But as I understand it, it's not so easy since Rust would need to add variadic types for generics and functions while keeping its error and debug diagnostics easy to read as well.

  • @papafrancesco8782
    @papafrancesco8782 10 місяців тому

    If im not mistaken, this looks a lot like the strategy bevy uses to implement its system architecture. Its crazy to me how a technology so complicated and rust type system dependent that its essentially impossible in any systems level language thats not rust is so widespread in the ecosystem. Great explanation. I once combed through source code for hours trying to figure out how the hell bevy knew at compiletime which system params to pass to which functions. Crazy stuff

  • @polares8187
    @polares8187 Рік тому

    Every time it is a pleasure to watch

  • @sildcave3926
    @sildcave3926 Рік тому

    Thank you for all your work, your videos are extremely usefull

  • @gang_albanii
    @gang_albanii Рік тому

    thank you. ive discovered axum fairly recently and for me, a young rustacean, it was black box.

  • @mustafazakiassagaf1757
    @mustafazakiassagaf1757 Рік тому

    thanks for the video Jon

  • @bok9201
    @bok9201 7 місяців тому

    Excellent content. For us Rust beginners, an example of how to write a handler for a custom response type such as a struct of several strings and a Vec[ ] or similar non-standard types would be useful, but perhaps too basic for your typical audience.

  • @yokebabjr3866
    @yokebabjr3866 Рік тому +4

    Does anyone has a link to "Ralph Youngs introduction to providence" mentionned at 2:04:15 ? Google didn't help me on this

    • @jonhoo
      @jonhoo  Рік тому +4

      www.ralfj.de/blog/2018/07/24/pointers-and-bytes.html and the two follow up posts he's done :)

  • @Loige
    @Loige Рік тому

    Great video as usual! Thanks, Jon. Now looking forward to the tracing one. Been playing a bit with it, but I am sure your decrusting of the library will make me understand it much more in depth!

  • @jaydendangvu
    @jaydendangvu Рік тому

    Love you Jon!

  • @nazarm6215
    @nazarm6215 Рік тому

    Axum has "type checking" for tcp/http requests? That's sweet.

  • @ohmyv3gatron
    @ohmyv3gatron Рік тому

    This is gold! 😊😊

  • @cooldude3010
    @cooldude3010 Рік тому

    Respectfully: you are goated.

  • @knowledgedose1956
    @knowledgedose1956 11 місяців тому

    Hey Jon, thanks for soooo much info! Friendly suggestion to set up a telegram group or even channel for new video announcements, topic polls etc

  • @barmetler
    @barmetler 8 місяців тому

    You're almost typing as fast as you're speaking. I wish I was that fast, but my hands are really holding me back in day to day life XD

  • @elichai2
    @elichai2 11 місяців тому

    Hi! I love your videos and it is the best advanced video content on rust out there.
    I will just say that the amount of red errors on the screen really make it hard to ignore and focus on the code, R-A can be too aggressive for my eyes lol

  • @midewestmond9442
    @midewestmond9442 Рік тому +3

    Thanks 😊

  • @YTCrazytieguy
    @YTCrazytieguy Рік тому +1

    Is the `==` trait bound syntax documented anywhere? it seems really useful

  • @StephenLin-ns8kx
    @StephenLin-ns8kx 11 місяців тому

    Hi Jon, thanks for the video! Definitely learned a bunch watching 🙂
    I have some trouble wrapping my head around the into_make_service() function. The docs explanation was a bit vague for me, stating MakeService is a Service whose response is another Service. Could you help clarify what this is meant to do?

  • @tilakmadichettitheappdeveloper
    @tilakmadichettitheappdeveloper 10 місяців тому

    Lichess open explorer uses the box leak trick too !

  • @w1keee
    @w1keee 11 місяців тому

    hey, i think it would be interesting to decrust the futures crate, because it has useful async types like Stream or Sink

  • @bozhidaratanasov7800
    @bozhidaratanasov7800 Рік тому +1

    Building medium-large sized type hierarchies, like the one you went through with tower::Service and Handler traits, is a skill I am seriously lacking. Would you have a recommended course of action for me or do you think it's something that comes with experience?

  • @Bob-nc5hz
    @Bob-nc5hz 10 місяців тому

    1:13:00 an alternative to "type erasing" (converting to a Response inside the handler) is to return a `Result`, which is one of the reasons I switched over from Warp (which uses Result for something else so you can't use it for diverging results). The more reliable type-checking is why I personally prefer fully typing most of my axum handlers, rather than using `impl IntoResponse` or `Response`, it's too easy to miss some of the bits you wanted to include then (especially when you use a uniform handler error and Result, in API contexts you probably always want to be sure the error value is the application's error type).

  • @underflowexception
    @underflowexception Рік тому

    Awesome thank you

  • @LucasFernandes-zs5nr
    @LucasFernandes-zs5nr 9 місяців тому

    you got a new subscriber just by the title 😅

  • @CamaradaArdi
    @CamaradaArdi Рік тому

    I'd love s decrusting Tokio episode

  • @aihuynh1504
    @aihuynh1504 11 місяців тому

    Thanks!

  • @erikgrundy
    @erikgrundy Рік тому +2

    It's fascinating to see how you can do all this sort of thing with a strong type system and compile time inference. as opposed to how much of what I see in other languages is based on runtime and reflection trickery

  • @jonasPlatte
    @jonasPlatte 11 місяців тому

    The moment you started looking for `into_route`, I knew it was going to be ~impossible to explain 😂

  • @ChefOnACloud
    @ChefOnACloud 11 місяців тому

    ah, the type pattern for State is so clever, you can kind of read it as "Still needs to be provided with an S", thus it makes sense that you can only call serve if `S` is `()`. Feels like the inverse of the `ApiBuilder, ApiBuilder` pattern, where instead of denoting what you have it denotes what you need, making it more generic and useful, since you're using actual required types instead of just markers

  • @EmoPorEmilio
    @EmoPorEmilio Рік тому

    wow, if a handler panics it only panics on that handler task? the web server keeps working. I had no idea. that is so crazy good.

  • @purpbroccoli6338
    @purpbroccoli6338 Рік тому +1

    Please decrust more of the tokio ecosystem!

  • @nathanoy_
    @nathanoy_ Рік тому +1

    In your description it still says "For more details about serde, see ". Seemingly pasted from the serde video, you may want to edit the description. Awesome video btw, this is exactly the content ive been looking for soo long.

    • @jonhoo
      @jonhoo  Рік тому +1

      Oops, good catch, fixed! Thanks 🎉

  • @MattWrightMTB
    @MattWrightMTB Рік тому

    Is there anyway we can download these somewhere?

  • @user-zl6om6kh9s
    @user-zl6om6kh9s Рік тому +1

    Could you have a stream for simply implementing an executor? It is hard to figure out what happened behind spawn and how does tokio implement Future. This trait is rarely implemented by normal applications, it just like magical.

  • @gritcrit4385
    @gritcrit4385 11 місяців тому

    1:58:27 What if we used lazy_static?

  • @CamaradaArdi
    @CamaradaArdi Рік тому

    Adding a feature to a crate you're importing is easier if you do cargo add [crate] -F [feature]

  • @sebatustra1
    @sebatustra1 Рік тому +2

    yoo good stuuuff

  • @coldsir5406
    @coldsir5406 Рік тому

    Is the vim config public?

  • @cherloire7978
    @cherloire7978 Рік тому +6

    You should do leptos as well :)

  • @eudrino
    @eudrino Рік тому

    great stream, thank you for sharing.
    i'm not a big fan of axum's approach to solve this, it is a nice experiment tho.
    also, i've noticed that alot of the missing time went into searching for implementation, so maybe you could implement it yourself like the hashmap vod.
    also maybe we can get bigger fonts, been squinting on my phone the whole time xd

  • @VivekYadav-ds8oz
    @VivekYadav-ds8oz Рік тому +1

    Day N+1 of asking Jon to make a video on creating your own little async/await library/executor.

    • @jonhoo
      @jonhoo  Рік тому

      You mean like ua-cam.com/video/9_3krAQtD2k/v-deo.html :)

    • @VivekYadav-ds8oz
      @VivekYadav-ds8oz Рік тому +1

      @@jonhoo I think I had watched this some years ago when I was even dumber and new to Rust. Now I don't quite remember what it exactly talked about, but I'm not sure it _really_ showed how to implement an Executor 😅

  • @najibullahkhodarahim1698
    @najibullahkhodarahim1698 10 місяців тому

    Can you decrust tonic?! 😊

  • @gritcrit4385
    @gritcrit4385 11 місяців тому

    Axum and tower have so much confusing types if you're not good at type-fu

  • @bramble-east
    @bramble-east 11 місяців тому +1

    Me, a Python developer: "Look what they need to mimic a fraction of *args, **kwargs power".

  • @echoptic775
    @echoptic775 11 місяців тому

    I like rust, but i hate when i see things like that macro for all tuples. Why cant anything be inferred so you dont need to do dumb things like that

  • @christianburke4220
    @christianburke4220 Рік тому

    first

  • @jokicnikola07
    @jokicnikola07 10 місяців тому

    Thanks!

  • @user-zl6om6kh9s
    @user-zl6om6kh9s Рік тому

    Could you have a stream for simply implementing an executor? It is hard to figure out what happened behind spawn and how does tokio implement Future. This trait is rarely implemented by normal applications, it just like magical.

    • @jonhoo
      @jonhoo  Рік тому

      You mean like ua-cam.com/video/9_3krAQtD2k/v-deo.html :)

    • @user-zl6om6kh9s
      @user-zl6om6kh9s Рік тому

      Oh I mean is to make a "implement" series of videos. I heard that smol had only 1,500 lines of code in the early days.That'll be cool@@jonhoo

  • @vimau010
    @vimau010 5 місяців тому

    Thanks!

  • @johnw.8782
    @johnw.8782 Рік тому

    Thanks!