<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="pt">
    <title>Lucas-BRT - Artigos</title>
    <subtitle>Desenvolvedor de Software focado em Performance e Arquitetura.</subtitle>
    <link rel="self" type="application/atom+xml" href="https://lucasbrt.dev/artigos/atom.xml"/>
    <link rel="alternate" type="text/html" href="https://lucasbrt.dev/artigos/"/>
    <generator uri="https://www.getzola.org/">Zola</generator>
    <updated>2026-05-01T00:00:00+00:00</updated>
    <id>https://lucasbrt.dev/artigos/atom.xml</id>
    <entry xml:lang="pt">
        <title>Reconciliando-me com a Intel e quebrando a cabeça com a Asus</title>
        <published>2026-05-01T00:00:00+00:00</published>
        <updated>2026-05-01T00:00:00+00:00</updated>
        
        <author>
          <name>lucasbrt</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://lucasbrt.dev/artigos/reconciliando-me-com-a-intel/"/>
        <id>https://lucasbrt.dev/artigos/reconciliando-me-com-a-intel/</id>
        
        <content type="html" xml:base="https://lucasbrt.dev/artigos/reconciliando-me-com-a-intel/">&lt;h2 id=&quot;minha-historia-com-a-intel&quot;&gt;Minha história com a Intel&lt;a class=&quot;anchor&quot; href=&quot;#minha-historia-com-a-intel&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;h3 id=&quot;os-primeiros-celerons&quot;&gt;Os primeiros Celerons&lt;a class=&quot;anchor&quot; href=&quot;#os-primeiros-celerons&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Ao contrário de muitos jovens da atualidade, eu acabei tendo acesso a computadores de maneira bem esparsa no decorrer de minha vida, e sempre com um grande atraso entre a tecnologia atual e o que realmente chegava aos meus olhos. O primeiro computador que tive, se não me engano, possuía um Intel Celeron com apenas um núcleo, sem acesso à internet e com o lendário Windows XP, o que é meio curioso, já que eu já tinha 16 anos de idade, ou seja, estávamos na época do iPhone X e do Tesla Model 3. Felizmente, aquilo me bastava.&lt;/p&gt;
&lt;p&gt;Não demorou muito para que esse pobre dinossauro parasse de funcionar misteriosamente após minha mãe decidir que era uma boa ideia puxar o computador da tomada enquanto estava ligado, algo que hoje em dia pode não ser tão perigoso, mas naquela época, com uma fonte de baixa qualidade, uma instalação elétrica precária e proteções do sistema operacional contra corrompimento sendo extremamente rudimentares, um desligamento forçado era basicamente uma roleta russa com a vida da pobre máquina.&lt;/p&gt;
&lt;p&gt;Como não havia acesso fácil à informação, mesmo um sistema operacional corrompido poderia significar a morte da máquina como um todo, e assim eu passei o resto do meu ensino médio sem nenhum computador.&lt;/p&gt;
&lt;h3 id=&quot;a-chegada-do-setup-moderno-e-a-escolha-pela-amd&quot;&gt;A chegada do setup moderno e a escolha pela AMD&lt;a class=&quot;anchor&quot; href=&quot;#a-chegada-do-setup-moderno-e-a-escolha-pela-amd&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Os anos se passaram, novos computadores vieram, esses por sua vez também pararam de funcionar de maneiras misteriosas — na realidade, foi a mesma maneira misteriosa; as fontes não eram tão diferentes em sua falta de qualidade — e eu acabei me aprofundando mais e mais no mundo da TI em geral. Logo fiquei sabendo de novos chips, novas placas gráficas que fariam meu setup anterior parecer uma impressora de fax imprimindo cada frame linha por linha.&lt;/p&gt;
&lt;p&gt;Durante esse período eu consegui montar um novo setup, dessa vez com finalmente peças modernas. Eu estava com 2x8 GB DDR4, um Ryzen 3 3200G e um SSD de 256 GB. Um setup de entrada, mas moderno, tanto que era conhecido pelo pessoal do blog Adrenaline como PC baratinho.&lt;/p&gt;
&lt;p&gt;O que provavelmente você deve estar se perguntando agora é: &quot;Lucas, se você sempre usou Intel durante toda sua vida e nunca conseguiu pegar um setup moderno com ela, mesmo querendo, por que não montou uma plataforma Intel quando tinha o dinheiro?&quot;. A resposta é bem simples: apesar da nostalgia ser algo existente, eu nunca fui o tipo de pessoa que se apega muito a marcas, mas sim a especificações e seus resultados, e para complicar, naquela época a Intel já estava com uma sequência de falhas catastróficas em seus processadores, com preços extremamente altos, performance pífia quando comparados aos AMD de mesma faixa, e o principal: eu queria poder jogar alguns jogos sem parecer que estava vendo uma apresentação de slides.&lt;/p&gt;
&lt;h2 id=&quot;o-gatilho-para-a-reconciliacao&quot;&gt;O gatilho para a reconciliação&lt;a class=&quot;anchor&quot; href=&quot;#o-gatilho-para-a-reconciliacao&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Dando mais um longo salto no tempo, agora para 2026, eu estava com as seguintes máquinas em meu arsenal: um desktop com um Ryzen 5 5500, 24 GB DDR4 e uma RTX 3050, e um notebook Positivo Vision R15 com Ryzen 7 5700U e 16 GB de RAM. Sei o que está pensando ao ler que eu estava usando um Positivo, mas como falei, só comprei pela especificação, e pelo preço que eu paguei na época, não havia nada no mercado que oferecesse tal performance, isso porque eu já estava na loucura de codar em Rust, então eu precisaria de muito poder de processamento para aguentar o compilador me xingando. Curiosamente acabei me afeiçoando com a plataforma AMD nesse meio tempo.&lt;/p&gt;
&lt;p&gt;No final de março, o Positivo decidiu simplesmente parar de dar vídeo no meio da faculdade. Inicialmente achei que era algum bug e que, reiniciando, ele voltaria — eu não poderia estar mais enganado.&lt;/p&gt;
&lt;p&gt;Acontece que havia realmente um motivo para suspeitar quando a Positivo lançou esse notebook em específico: o problema é que, ao focar tudo na performance, a Positivo acabou optando por deixar a construção de lado, e como deve saber, uma das partes mais frágeis de qualquer notebook é o cabo flat que conecta o monitor à placa-mãe.&lt;/p&gt;
&lt;p&gt;Chegando em casa peguei um cabo HDMI e testei-o em um monitor externo para ver se minha hipótese estava correta; aparentemente era realmente isso, o notebook estava ligando, mas o monitor não mostrava nada. Elaborarei mais sobre que fim dei a esse notebook em uma futura postagem. O importante é que o problema em si apesar de simples, não era algo que eu tinha ferramentas para consertar e sinceramente nem creio que valeria a pena.&lt;/p&gt;
&lt;h2 id=&quot;escolhendo-um-novo-notebook&quot;&gt;Escolhendo um novo notebook&lt;a class=&quot;anchor&quot; href=&quot;#escolhendo-um-novo-notebook&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Acabei decidindo comprar um novo notebook, e entre minha pesquisa parei para pensar o que realmente me importava em um dispositivo. Depois de pensar um pouco, cheguei a elaborar essa lista do que seria essencial:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Ser forte o suficiente para compilar projetos Rust grandes em um tempo viável.&lt;/li&gt;
&lt;li&gt;Ter uma entrada USB-C com suporte a carregamento.&lt;/li&gt;
&lt;li&gt;Ter uma carcaça de alumínio para ajudar no resfriamento.&lt;/li&gt;
&lt;li&gt;Ter uma boa duração de bateria.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&quot;por-que-evito-notebooks-gamers&quot;&gt;Por que evito notebooks gamers&lt;a class=&quot;anchor&quot; href=&quot;#por-que-evito-notebooks-gamers&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Creio que posso resumir o motivo de cada ponto acima explicando o que eu &lt;strong&gt;NÃO&lt;/strong&gt; gosto em um notebook. Por vezes vi pessoas comprando notebooks gamers para usar na faculdade, o que sinceramente não me afeta, afinal, o dinheiro é delas, mas o pouco de empatia que ainda existe em mim me obrigava a ficar incomodado com um certo comportamento que já foi documentado por diversos meios de comunicação de tecnologia ao decorrer dos últimos anos.&lt;/p&gt;
&lt;p&gt;Boa parte das pessoas que compram um notebook gamer curiosamente não irá usar todo o potencial dele, isso devido ao fato da performance real da maioria desses dispositivos ser somente liberada em sua totalidade quando plugados diretos a fonte de alimentação, o que te obriga a só usar com esse objetivo perto de tomadas. Para piorar, a maioria desses dispositivos esquentam muito, afinal, o sistema de arrefecimento precisa lidar com todo aquele TDP sendo usado pela CPU e a GPU. No final a pessoa que compra um desses no impulso pode acabar pagando muito no bolso, mas sem usufruir efetivamente do produto.&lt;/p&gt;
&lt;h3 id=&quot;encontrando-o-asus-vivobook-s14&quot;&gt;Encontrando o Asus Vivobook S14&lt;a class=&quot;anchor&quot; href=&quot;#encontrando-o-asus-vivobook-s14&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Depois de pesquisar um pouco, acabei encontrando o Asus Vivobook S14, especificamente o que vinha com Intel Core Ultra 5 225H, e pesquisando sobre esse processador — o que fui obrigado, já que não tinha me acostumado com a nova nomenclatura da Intel, apesar de saber de sua existência — acabei descobrindo que ele vinha com a nova arquitetura de núcleos mistos, em que o processador vinha com P-cores para realizar tarefas computacionalmente intensivas e E-cores, focados em economia de energia, e para melhorar ainda mais, ele vinha com uma NPU que eu não tinha tido acesso até agora, o que me deu curiosidade em ver o que eu poderia rodar localmente com isso.&lt;/p&gt;
&lt;p&gt;Ao analisar os testes de performance, acabei percebendo que ele era bem mais forte que meu Ryzen 7 5700U, em alguns testes chegando até o dobro de performance bruta e em multithread, tudo isso enquanto consumia pouca energia e esquentava menos.&lt;/p&gt;
&lt;p&gt;O curioso foi perceber que aparentemente o gráfico integrado nesse chip era bem melhor do que eu achava, isso junto ao fato de ele vir com 16 GB DDR5 soldados e um slot livre para upgrade até 32GB, fez ele parecer um ótimo produto.&lt;/p&gt;
&lt;p&gt;Devido à constante variação dos preços das memórias RAM, o valor desse notebook estava bem alto, por aproximadamente R$ 4.700,00, o que já viabilizaria eu comprar um MacBook Neo na mesma faixa de preço quando esse entrasse em promoção, mas o fato de ele vir com apenas 8 GB de RAM e o fato de eu estar preso àquele hardware sem possibilidade de upgrade foi o martelo final na tomada de decisão.&lt;/p&gt;
&lt;h2 id=&quot;os-primeiros-problemas-com-o-linux&quot;&gt;Os primeiros problemas com o Linux&lt;a class=&quot;anchor&quot; href=&quot;#os-primeiros-problemas-com-o-linux&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Como queria economizar, acabei optando por pegar a versão com Linux, e o que vinha era o maldito KeepOS, que caso não saiba, é uma das distros que as fabricantes que vendem produtos no Brasil adoram colocar. Antes que indague, não, não usei nem mesmo por 5 minutos. Quando ele chegou, apenas me certifiquei que tudo estava funcionando e formatei para uma outra distro mais estável e útil. Mal sabia eu que era exatamente aí que os problemas iriam começar.&lt;/p&gt;
&lt;p&gt;Acabei optando por instalar o Pop OS 24.04, afinal é o mesmo sistema que eu uso diariamente no meu desktop, e o Cosmic, apesar de ser um Desktop Environment novo, já atende bem minhas necessidades. O curioso foi quando o processo de instalação começou a demorar bem mais do que eu lembrava, ainda mais considerando que eu estava com um SSD NVMe, o que deveria agilizar muito o processo de formatação, mas acabei ignorando por acreditar que seria apenas um gargalo gerado pela velocidade de transferência do pendrive usado.&lt;/p&gt;
&lt;h3 id=&quot;travamentos-misteriosos&quot;&gt;Travamentos misteriosos&lt;a class=&quot;anchor&quot; href=&quot;#travamentos-misteriosos&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Ao terminar de instalar o sistema, fui logo atualizando os pacotes do sistema e fui instalar meu monitor de processos principal, o Mission Center. Uso ele principalmente pela funcionalidade de poder monitorar o uso da GPU, o que geralmente não é mostrado nos monitores do Gnome.&lt;/p&gt;
&lt;p&gt;O estranho foi perceber que apesar de estar monitorando o uso, a placa gráfica integrada não estava sendo totalmente identificada. O nome da Arc 130T simplesmente não aparecia. Inicialmente achei que era um bug do Mission Center, mas depois de usar durante algum tempo comecei a reparar algumas estranhas travadas, e o mais estranho é que travava um aplicativo específico, mas todo o resto do OS continuava responsivo, ou travava somente uma parte do DE, enquanto o resto funcionava normalmente.&lt;/p&gt;
&lt;p&gt;Ao monitorar os processos durante o travamento tudo começou a ficar ainda mais suspeito. Nenhum pico de uso de CPU, nenhum pico de uso de RAM, nenhum pico de uso de SSD. A primeira hipótese que tive era que seria algum bug com Wayland e sua interação com a Arc 130T. Como alguém que passou por poucas e boas usando Nvidia durante a transição de Xorg para Wayland, eu sabia que alguma maluquice poderia estar ocorrendo por baixo dos panos.&lt;/p&gt;
&lt;h3 id=&quot;testando-outras-distros&quot;&gt;Testando outras distros&lt;a class=&quot;anchor&quot; href=&quot;#testando-outras-distros&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Cheguei a atualizar os drivers manualmente, tentei atualizar o kernel, tentei quase tudo que minha mente junto com uma LLM pudessem pensar. Em certo ponto achei que a culpa seria do Pop OS, então decidi instalar um novo OS, e nessa brincadeira lá se vai uma tarde toda copiando várias ISOs para pendrive com Ventoy, já que a ISO do Pop OS não permitia ser colocada no Ventoy diretamente.&lt;/p&gt;
&lt;p&gt;Cheguei a testar o Ubuntu 26.04, o CachyOS e o Fedora KDE, mas todos apresentavam o mesmo problema depois de algum tempo de uso.&lt;/p&gt;
&lt;p&gt;Foi aí que comecei a reparar algo curioso: quando eu estava acessando os Linux com o modo Live diretamente pelo pendrive, o travamento nunca ocorria. Parecia que o problema só aparecia quando eu instalava diretamente no SSD ou quando eu ia instalar efetivamente o sistema.&lt;/p&gt;
&lt;p&gt;Inicialmente fiquei preocupado achando que tinha pego um SSD danificado, mas seria improvável, já que até mesmo o tempo de boot do OS era expressivamente diferente quando eu comparava os segundos que demorou no KeepOS com o de qualquer outro OS.&lt;/p&gt;
&lt;p&gt;Então, deveria haver alguma solução de software que estava implementada no KeepOS e que não estava implementada em nenhum outro Linux por padrão, isso me cheirava a algum driver proprietário para se comunicar com o SSD.&lt;/p&gt;
&lt;h2 id=&quot;a-culpa-era-do-vmd&quot;&gt;A culpa era do VMD&lt;a class=&quot;anchor&quot; href=&quot;#a-culpa-era-do-vmd&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Durante mais uma formatação, decidi dar uma olhada com calma na BIOS desse notebook. Que surpresa a minha quando percebi que, por algum motivo que só a Asus deve saber, o maldito VMD Controller estava &lt;strong&gt;habilitado&lt;/strong&gt; por padrão na BIOS.&lt;/p&gt;
&lt;p&gt;Caso não saiba, o VMD (Volume Management Device) é uma camada extra da Intel que roda entre os SSDs e o sistema operacional. Assim, em vez do OS conseguir acessar o SSD diretamente pelo barramento PCIe, ele acessa o controlador VMD que fica na CPU que gerencia tudo e retorna os dados para o OS.&lt;/p&gt;
&lt;p&gt;A tecnologia em si é bastante útil, ela permite que você configure RAID diretamente pela BIOS, além de permitir hot-plug dos discos, ou seja, você poderia plugar um novo disco enquanto o sistema estava rodando, e com poucos comandos ele estaria sendo listado como usável sem precisar reiniciar a máquina.&lt;/p&gt;
&lt;p&gt;Legal, mas qual é o problema de o VMD estar ligado? A resposta é bem simples: o VMD é uma tecnologia que é usada para montar RAIDs e permitir hot-plug, mas ambos os usos da tecnologia são comuns em servidores. Então eu indago, por que caralhos uma BIOS de um notebook com apenas &lt;strong&gt;UM&lt;/strong&gt; slot NVMe precisaria ter suporte a RAID e hot-plug ligado por padrão? Simples: &lt;strong&gt;não precisaria&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Essa opção no caso específico desse notebook acaba apenas adicionando uma camada de falha. Para piorar, o módulo vmd do Linux que foi desenvolvido exatamente para dar suporte a essa tecnologia, por algum motivo, não estava interagindo muito bem com o processador da Intel exatamente por ser muito novo e aparentemente não ter muitas pessoas usando.&lt;/p&gt;
&lt;p&gt;Ou seja, acabei virando uma cobaia por usar hardware novo, com opções de BIOS sem nenhum sentido configuradas por padrão, por uma fabricante que aparentemente não pensava na hipótese de seus clientes instalarem um Linux que não o maldito KeepOS que eles colocaram por padrão.&lt;/p&gt;
&lt;p&gt;Mas bem, desabilitando essa opção, o tempo de boot do sistema — que depois de tanto revezamento estava novamente sendo o CachyOS — foi de aproximadamente &lt;strong&gt;3 minutos&lt;/strong&gt; para incríveis &lt;strong&gt;10 segundos&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Os &quot;travamentos&quot; na realidade eram apenas o sistema operacional não conseguindo realizar a leitura das informações do disco em tempo viável devido aos problemas de comunicação com o VMD, exatamente por isso que nos gerenciadores de tarefas não era mostrado um uso de SSD, pois o problema estava exatamente no fato de ele NÃO estar sendo utilizado.&lt;/p&gt;
&lt;p&gt;Enquanto os programas estavam carregados na RAM, tudo ficava fluido, mas quando eu tentava abrir um programa que não estava carregado ainda, o sistema operacional precisava pedir os dados para o SSD, mas como o VMD estava no caminho o sistema operacional precisava esperar o VMD gerenciar o disco e aí sim retornar com as informações que foram requisitadas, e como a comunicação não estava ocorrendo apropriadamente, se perdia mais tempo na comunicação entre o OS e o VMD do que efetivamente movendo os dados do disco.&lt;/p&gt;
&lt;h2 id=&quot;o-bug-do-wifi-apos-suspensao&quot;&gt;O bug do WiFi após suspensão&lt;a class=&quot;anchor&quot; href=&quot;#o-bug-do-wifi-apos-suspensao&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Outro problema que encontrei foi o fato de, ao retornar o notebook da suspensão, o WiFi não funcionava, precisando que eu reiniciasse o sistema inteiro, já que aparentemente o próprio dispositivo era desconectado e não conseguia ser encontrado novamente ao voltar da suspensão.&lt;/p&gt;
&lt;p&gt;Esse felizmente foi um problema menor, referente à placa de WiFi que esse notebook usa. Essa placa já tinha uma fama de causar certos problemas no kernel, tanto que já havia sido documentada &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://bugs.launchpad.net/ubuntu/+source/linux-hwe-6.14/+bug/2127051&quot;&gt;em 2025&lt;/a&gt; em um fórum do Ubuntu.&lt;/p&gt;
&lt;p&gt;O bug em si aparenta ainda estar sem solução, mas existe um fix temporário que pode ser usado para corrigir o problema enquanto não é desenvolvido um fix permanente no kernel principal. Caso tenha interesse, deixei um script público para corrigir esse problema &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/Lucas-BRT/rtl8852be-suspend-fix&quot;&gt;no meu GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&quot;conclusao&quot;&gt;Conclusão&lt;a class=&quot;anchor&quot; href=&quot;#conclusao&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Em geral, após os primeiros dias de uso terem passado e as devidas correções terem sido realizadas, parece que a compra realmente valeu a pena. A bateria dura várias horas enquanto programo, mesmo com o brilho no máximo e programando em Rust — e sim, tenho a mania de programar com cargo watch rodando — a construção realmente é forte e leve, e por ser uma carcaça totalmente de alumínio, ele permanece frio até mesmo nos ambientes infernais que frequento, além de ser bem confortável de levar para todos os lugares.&lt;/p&gt;
&lt;p&gt;O uso em geral se mostrou bastante performático, mostrando que mesmo sem ter hyperthreading, por ter a mesma quantidade de núcleos que threads, ele consegue manter serviços em multitarefas com extrema fluidez.&lt;/p&gt;
&lt;p&gt;Cheguei a baixar a Steam para testar alguns jogos leves e que surpresa a minha ao perceber que a iGPU, mesmo que em single-channel já estava com aproximadamente o dobro da performance da minha antiga Vega 7. Se no futuro eu vier a pegar um upgrade para 32GB de RAM, talvez eu traga um comparativo do antes e depois efetivamente, já que aparenta ser um conteúdo escasso na internet atualmente.&lt;/p&gt;
&lt;p&gt;O único ponto do notebook que eu ficarei devendo será os testes com a NPU, isso devido ao fato do suporte do Ollama a NPUs ainda estar bem prematuro, para não falar inexistente. Felizmente, o OpenVINO parece estar começando a receber uma atenção, quem sabe daqui a um ano eu não traga os testes. Se funcionar corretamente, eu poderei rodar modelos como Gemma4:e2b localmente consumindo pouquíssima energia, ou algum outro modelo mais utilitário para o tipo de arquitetura que as NPUs se propõem, o que poderá permitir novas ideias de projetos.&lt;/p&gt;
</content>
        
    </entry>
    <entry xml:lang="pt">
        <title>Construindo uma infraestrutura pessoal privada</title>
        <published>2026-01-28T00:00:00+00:00</published>
        <updated>2026-01-28T00:00:00+00:00</updated>
        
        <author>
          <name>lucasbrt</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://lucasbrt.dev/artigos/construindo-seu-paas-pessoal/"/>
        <id>https://lucasbrt.dev/artigos/construindo-seu-paas-pessoal/</id>
        
        <content type="html" xml:base="https://lucasbrt.dev/artigos/construindo-seu-paas-pessoal/">&lt;p&gt;Recentemente percebi que andava subindo muitos projetos pessoais em minha VPS e acabei sendo abordado por alguns amigos perguntando como eu fazia o deploy de tais aplicações, curiosamente, eu opto por não usar serviços como Vercel, pois apesar de sua praticidade momentânea, já tive dor de cabeça com esse tipo de plataforma anteriormente, principalmente devido a limitações de funcionalidade, carga ou mesmo de implicações sobre o código que eu iria subir.&lt;/p&gt;
&lt;p&gt;Sabendo disso, decidi escrever esse draft para explicar como eu realizo meu deploy com o menor custo possível, e com praticidade, Pois, apesar de eu me considerar um dev backend, não sou masoquista ao ponto de ficar configurando proxies reversos manualmente toda santa vez só para subir uma aplicação protótipo.&lt;/p&gt;
&lt;h2 id=&quot;homelab-cloudlab-remotelab&quot;&gt;HomeLab? CloudLab? RemoteLab?&lt;a class=&quot;anchor&quot; href=&quot;#homelab-cloudlab-remotelab&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Provavelmente você já ouviu falar do termo &lt;strong&gt;HomeLab&lt;/strong&gt;, este se baseia em você manter a infraestrutura de deploy de serviços e aplicações direto na sua casa, ou em algum lugar físico sob sua custódia, apesar de eu já ter montado um HomeLab anteriormente, neste draft irei abordar algo mais prático para quem tiver pouco conhecimento sobre redes e hardware, dinheiro ou espaço físico.&lt;/p&gt;
&lt;p&gt;Sinceramente não sei como definir o termo do que montei, para ser sincero, nem pesquisei muito se existe um termo específico para isso, mas o conceito básico é simples: enquanto no HomeLab temos o controle total dos recursos da máquina por ter o acesso físico a ela, no CloudLab/RemoteLab vou tentar terceirizar o serviço de cuidar da máquina em si para algum serviço externo, seja AWS, Azure, Digital Ocean, ou mesmo uma VPS simples.&lt;/p&gt;
&lt;p&gt;O foco é ter uma máquina - preferencialmente rodando Linux - que posso acessar remotamente e configurar ela como bem entender, como o termo RemoteLab pode dar a entender que eu ainda tenho acesso a máquina, mas que ela está apenas em outro lugar físico ainda de minha custódia, usarei o termo &lt;strong&gt;CloudLab&lt;/strong&gt; para deixar claro que, no final das contas, ainda estarei usando um servidor de algum provedor.&lt;/p&gt;
&lt;h2 id=&quot;por-que-ter-um-laboratorio-pessoal-privado&quot;&gt;Por que ter um laboratório pessoal privado?&lt;a class=&quot;anchor&quot; href=&quot;#por-que-ter-um-laboratorio-pessoal-privado&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Existem várias vantagens que eu posso listar quando se trata de ter uma máquina somente sua disponível online, essas vantagens, entretanto, dependem muito do seu ramo de atuação na área da tecnologia e de seus hobbies.&lt;/p&gt;
&lt;p&gt;Para as pessoas da área de DevOps ou Backend, ter um laboratório desses irá, com certeza, aprofundar seu conhecimento sobre redes, linux, otimização de código, CI/CD, dentre outros tópicos importantes para o seu dia a dia no trabalho.&lt;/p&gt;
&lt;p&gt;Para as pessoas de outros ramos, seja Frontend ou apenas alguém que gosta de TI num geral, creio que permitir subir aplicações SelfHost com foco em produtividade, entretenimento ou apenas por aprender algo novo já seja um bom motivador.&lt;/p&gt;
&lt;p&gt;Em geral, eu poderia resumir o fato de ter um laboratório pessoal como uma mistura de local de aprendizado, economia de gastos com plataformas externas e uma fonte de diversão — isso se você for do tipo de pessoa que adora quebrar a cabeça com problemas.&lt;/p&gt;
&lt;h2 id=&quot;quanto-custa&quot;&gt;Quanto custa?&lt;a class=&quot;anchor&quot; href=&quot;#quanto-custa&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Aqui entramos na parte que normalmente iria inviabilizar essa brincadeira para muitas pessoas, VPSs não são de graça, certo?&lt;/p&gt;
&lt;p&gt;Às vezes, sim, apesar das melhores máquinas serem obviamente pagas, existem sim alternativas gratuitas, apesar de obviamente bastante limitadas. Dentre elas, posso listar as máquinas disponibilizadas pela Oracle Cloud Free tier, que geralmente oferece uma máquina fraca, mas se você conseguir criar uma conta no exterior, dizem ser capaz de conseguir uma máquina com a arquitetura ARM e com até 4 vCPUs, além da Google Cloud Free, que é ainda mais limitada.&lt;/p&gt;
&lt;p&gt;Para ser sincero, boa parte dessas máquinas mal aguentará uma aplicação simples sendo subida, então o ideal seria ter uma máquina um pouco mais potente, digamos uma KVM2 da Hostinger.&lt;/p&gt;
&lt;h3 id=&quot;como-conseguir-uma-vps-de-graca&quot;&gt;Como conseguir uma VPS de graça&lt;a class=&quot;anchor&quot; href=&quot;#como-conseguir-uma-vps-de-graca&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Como comentei anteriormente, as principais alternativas gratuitas são a &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://www.oracle.com/br/cloud/free/faq/&quot;&gt;Oracle Cloud Free&lt;/a&gt; Tier e a Google Cloud Free, devido às limitações, vou considerar usar a Oracle Cloud Free Tier por ser vitalício.&lt;/p&gt;
&lt;p&gt;Caso você seja um estudante de ensino superior de qualquer curso, se inscrever para o &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://education.github.com/pack&quot;&gt;Github Education Pack&lt;/a&gt; lhe trará várias vantagens, dentre elas, os créditos da Microsoft Azure e Digital Ocean, disponíveis para você usar as instâncias deles praticamente de graça enquanto os créditos não acabarem, pegue uma de sua preferência, ou as duas, se for esperto, tecnicamente estão de graça.&lt;/p&gt;
&lt;p&gt;Caso opte por investir dinheiro nisso, existem diversos serviços de hospedagem que terão preços bem flexíveis para todos os tipos de máquinas que você possa precisar, mas é bom sempre lembrar que, caso você opte por pegar máquinas em diferentes zonas do mundo, como por exemplo uma no Brasil e outra na Europa, o delay de comunicação entre elas pode ser algo considerável. Então, caso esteja pensando em subir um servidor de jogos ou algo do tipo, &lt;strong&gt;analise isso previamente&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Para todos os efeitos, considerarei a partir daqui que você tem no mínimo uma máquina equivalente à fornecida pela Oracle Cloud Free, ou seja, 1 vCPU com 1 GB de RAM. Caso tenha optado por pegar uma máquina superior, ainda recomendo que pegue a Oracle Cloud Free para usar como a máquina &lt;strong&gt;orquestradora&lt;/strong&gt; das que efetivamente rodarão suas aplicações. Elaborarei mais sobre isso à frente.&lt;/p&gt;
&lt;h2 id=&quot;gerenciando-a-falta-de-recursos&quot;&gt;Gerenciando a falta de recursos&lt;a class=&quot;anchor&quot; href=&quot;#gerenciando-a-falta-de-recursos&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Bem, considerando que você já está com sua máquina criada e sendo possível acessar ela por SSH, vamos precisar realizar algumas configurações antes de subir algo efetivamente nela, afinal, 1 núcleo e 1Gb de RAM é pouco até mesmo para um sistema operacional, imagine então o sofrimento que seria rodar algo efetivo nisso.&lt;/p&gt;
&lt;p&gt;A primeira coisa que você precisa fazer é configurar manualmente a memória SWAP nessa máquina, assim, se você precisar subir aplicações que consumam muita RAM — e &lt;strong&gt;vai&lt;/strong&gt; precisar — o sistema operacional não irá matar o processo, apenas usará o espaço em disco como memória RAM, o que resultará em uma lentidão, mas não impedirá de prosseguirmos.&lt;/p&gt;
&lt;p&gt;Considerando que estamos rodando uma máquina Ubuntu 24.04, que geralmente é a que vem nessas máquinas, você pode usar os seguintes comandos para setar sua memória SWAP.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; fallocate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;l&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; 8G&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; /swapfile&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; chmod&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 600&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; /swapfile&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; mkswap&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; /swapfile&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; swapon&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; /swapfile&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#D20F39, #F38BA8);font-style: italic;&quot;&gt;echo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;/swapfile none swap sw 0 0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; sudo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; tee&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; /etc/fstab&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Os primeiros comandos são apenas para criar o arquivo de SWAP. No meu caso, eu optei por 8 GB. Se você for pesquisar mais a fundo sobre memória SWAP, encontrará várias pessoas falando sobre quanto você deveria alocar, geralmente sendo &lt;strong&gt;30 a 50% da sua memória real&lt;/strong&gt;. Mas isso seria considerando sempre uma máquina como desktop. No caso, como estou em um ambiente bem mais restritivo, o ideal é só permitir que nenhum processo seja morto, &lt;strong&gt;independentemente de quanto tempo demore para ele rodar suas tarefas&lt;/strong&gt;. Então, o exagero de 8 GB tem seus motivos.&lt;/p&gt;
&lt;p&gt;O último comando serve apenas para manter o arquivo de SWAP funcionando após o Reboot da máquina.&lt;/p&gt;
&lt;p&gt;Tendo feito isso, você pode finalmente prosseguir sem medo de o passo seguinte falhar ou ter comportamentos inesperados.&lt;/p&gt;
&lt;h2 id=&quot;configurando-o-seu-paas-de-preferencia&quot;&gt;Configurando o seu PaaS de Preferência&lt;a class=&quot;anchor&quot; href=&quot;#configurando-o-seu-paas-de-preferencia&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Atualmente existem diversas alternativas de PaaS SelfHost, dentre eles podemos listar Coolify, Dokploy dentre outros.&lt;/p&gt;
&lt;p&gt;Para prosseguirmos com o teste, usarei o Dokploy, não tem nada de especial nele, até onde pesquisei aparentemente o Coolify tem até mais funcionalidades.&lt;/p&gt;
&lt;p&gt;O processo de instalação é simples, você só precisa entrar no &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://dokploy.com/&quot;&gt;site do dokploy&lt;/a&gt; e executar o comando de instalação que está fornecido na LandingPage como root.&lt;/p&gt;
&lt;p&gt;O procedimento pode demorar um pouco, isso devido ao fato que o script de instalação irá configurar toda a sua máquina do zero, incluindo a instalação de Docker, Traefik — que é um proxy reverso e load balancer moderno, que serve como alternativa ao Nginx — e várias outras coisas.&lt;/p&gt;
&lt;p&gt;Caso não tenha realizado a configuração da memória SWAP do passo anterior e esteja usando uma máquina limitada como a que comentei anteriormente, é bem provável que o Out of Memory Killer (ou simplesmente, OOM Killer) acabe matando algum processo durante a instalação, corrompendo assim a mesma e te obrigando a instalar tudo novamente.&lt;/p&gt;
&lt;p&gt;A aplicação roda em cima do Docker, junto com o banco de dados, cache e o próprio proxy reverso do Traefik, então ao concluir a instalação você pode verificar o estado de tudo usando o comando docker ps, como mostrado abaixo:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;ubuntu@instance-20260118-1159:~$&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; sudo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; docker&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; ps&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;CONTAINER&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; ID&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;   IMAGE&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;                     COMMAND&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;                  CREATED&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;      STATUS&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        PORTS&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;                                                                                                                   NAMES&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;98d53dd00cff&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;   traefik:v3.6.1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;/entrypoint.sh trae…&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;   7&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; days&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; ago&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;   Up&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 30&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; hours&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;   0.0.0.0:80&lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;80/tcp,&lt;/span&gt;&lt;span&gt; [::&lt;/span&gt;&lt;span&gt;]:80-&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;80/tcp, 0.0.0.0:443-&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;443/tcp, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span&gt;:443-&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;443/tcp, 0.0.0.0:443-&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;443/udp, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span&gt;:443-&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;443/udp   dokploy-traefik&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;c1eea70a05f1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;   dokploy/dokploy:v0.26.5&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;   &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;docker-entrypoint.s…&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;   7&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; days&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; ago&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;   Up&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 7&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; days&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;     0.0.0.0:3000&lt;/span&gt;&lt;span&gt;-&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;3000/tcp,&lt;/span&gt;&lt;span&gt; [::&lt;/span&gt;&lt;span&gt;]:3000-&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;3000/tcp                                                                             dokploy.1.cpuq4jq398p7fzwoldcgrmy4f&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;457d78a7071d&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;   redis:7&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;                   &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;docker-entrypoint.s…&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;   7&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; days&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; ago&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;   Up&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 7&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; days&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;     6379/tcp&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;                                                                                                                dokploy-redis.1.lmstz4cjdi9qp4yaki87pbzz3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;c8190750a03a&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;   postgres:16&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;               &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;docker-entrypoint.s…&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;   7&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; days&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; ago&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;   Up&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 7&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; days&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;     5432/tcp&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;                                                                                                                dokploy-postgres.1.qesooej243lm1x93incw3368j&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Se tudo estiver funcionando corretamente você deve conseguir acessar uma página para criar seu usuário, e após isso ele o levará para uma página parecida com a seguinte:&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-login-page.png&quot; alt=&quot;dokploy-login-page.png&quot; style=&quot;width: 100%;&quot;  /&gt;
&lt;p&gt;Caso não consiga acessar a página usando o IP do seu servidor na porta 3000, verifique se o firewall do linux está permitindo o acesso. Se estiver usando a máquina da Oracle como recomendei, será necessário abrir tanto no linux quanto no painel da Oracle. Não deixarei explícito onde encontrar essa opção, pois, sinceramente, esqueci onde fica e eles podem acabar mudando a interface. Então, &lt;strong&gt;recomendo dar um Google&lt;/strong&gt; — ou uma olhada nas IAs — e ver onde a opção para liberar a porta se encontra atualmente.&lt;/p&gt;
&lt;h2 id=&quot;criando-um-servidor-remoto&quot;&gt;Criando um servidor remoto...?&lt;a class=&quot;anchor&quot; href=&quot;#criando-um-servidor-remoto&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Ao logar na sua conta e ir na aba de monitoramento, provavelmente encontrará algo parecido com isto:&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-100-usage.png&quot; alt=&quot;dokploy-100-usage.png&quot; style=&quot;width: 100%;&quot;  /&gt;
&lt;p&gt;Picos de uso de &lt;strong&gt;100% de CPU&lt;/strong&gt;, além da memória praticamente esgotada. Bem, aqui você pode me indagar: se o servidor &lt;strong&gt;principal&lt;/strong&gt; que está com o PaaS já está com os recursos esgotados, como vou subir aplicações pesadas nele?&lt;/p&gt;
&lt;p&gt;A resposta é simples: &lt;strong&gt;não vou&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Veja bem, a razão pela qual eu listei mais de um local para conseguir uma VPS além de recomendar pegar TODAS as gratuitas que você conseguir é por um motivo crucial: vou usar máquinas dispensáveis para rodar as aplicações, enquanto deixo toda a parte de configuração e gerenciamento em uma máquina fraca, mas confiável.&lt;/p&gt;
&lt;p&gt;Como a Oracle Cloud Free, especificamente a com arquitetura x86 no Brasil não tem tantas reclamações de exclusão, vou usá-la como máquina principal, enquanto isso usarei a minha KVM2 e o Droplet da DigitalOcean como máquinas de Deploy.&lt;/p&gt;
&lt;p&gt;Para isso, você precisa apenas ir na opção &lt;strong&gt;Remote Servers&lt;/strong&gt; que pode ser encontrada na seção Settings.&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-remote-servers-tab.png&quot; alt=&quot;dokploy-remote-servers-tab.png&quot;  /&gt;
&lt;p&gt;e após isso clicar em &lt;strong&gt;Create Server&lt;/strong&gt;, fazendo isso o seguinte popup deve aparecer para você:&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-create-server-popup.png&quot; alt=&quot;dokploy-create-server-popup.png&quot; style=&quot;width: 100%;&quot;  /&gt;
&lt;p&gt;Aqui você pode ver que o passo a passo para configurar um servidor remoto é bem simples, apenas sendo preciso preencher as informações básicas e deixar que o Dokploy lide com o resto.&lt;/p&gt;
&lt;p&gt;Observe que existe a opção Server Type, essa opção serve para você escolher entre dois tipos de servidores: Deploy Server ou Build Server.&lt;/p&gt;
&lt;p&gt;Build Server, como o nome já deixa a indicar, são servidores focados somente em &lt;strong&gt;buildar&lt;/strong&gt; suas aplicações. Caso seja alguém vindo da bolha de desenvolvimento Web pode acabar estranhando ter um servidor somente dedicado a isso, mas pense na seguinte situação:&lt;/p&gt;
&lt;p&gt;Suponha que você tem duas VPSs, uma sendo a central que roda o Dokploy e a outra para deploy efetivamente, esse fluxo pode funcionar tranquilamente para servir aplicações estáticas ou até mesmo aplicações FullStack básicas feitas em Node ou qualquer outra linguagem interpretada de sua preferência.&lt;/p&gt;
&lt;p&gt;O problema ocorre quando você começa a ter uma aplicação com muitas dependências, ou muitos &lt;strong&gt;passos&lt;/strong&gt; para &lt;strong&gt;build&lt;/strong&gt;. Nessa situação, você acaba sobrecarregando o pobre servidor principal que está realizando o &lt;strong&gt;build&lt;/strong&gt;, o que normalmente não seria um problema, tirando o fato de que um deploy simples agora demoraria alguns minutos, já que a máquina tem apenas um núcleo e pouquíssimos recursos de processamento, o que pode tornar a experiência de usar ela enquanto isso ainda pior.&lt;/p&gt;
&lt;p&gt;Isso obviamente afeta outra situação: se aplicações interpretadas grandes já seriam uma dor de cabeça, compilar um projeto usando &lt;strong&gt;Rust&lt;/strong&gt;, que já tem fama de demorar, torna-se então fora de cogitação.&lt;/p&gt;
&lt;p&gt;Para isso, tenho duas soluções:&lt;/p&gt;
&lt;p&gt;Ou você usa o &lt;strong&gt;GitHub Actions&lt;/strong&gt; ou outro serviço de CI/CD gratuito de sua preferência e integra ele com um Registry, configura a pipeline e tenta otimizar tudo para ficar dentro do consumo mensal gratuito disponibilizado pela plataforma.&lt;/p&gt;
&lt;p&gt;Ou, simplesmente, adicione um novo servidor como servidor de build, apenas clique em deploy e deixe que o Dokploy otimize tudo, já que rodará tudo em um servidor &lt;strong&gt;proprietário seu&lt;/strong&gt;, garantindo &lt;strong&gt;performance e propriedade sobre o código&lt;/strong&gt; — caso você seja paranoico ao ponto de achar que a Microsoft irá roubar seu código &lt;strong&gt;genial&lt;/strong&gt; quando passar pelo CI/CD —&lt;/p&gt;
&lt;p&gt;Obviamente, aqui entro em um momento em que estou trocando praticidade por dinheiro. Caso opte por economia, vale a pena gastar um pouco de dor de cabeça configurando tudo no GitHub Actions para deixar o CI funcionando. Caso queira praticidade máxima, só pegue uma VPS, configure ela para Build e seja feliz e paranoico.&lt;/p&gt;
&lt;p&gt;Como sou mão de vaca, atualmente estou optando pela opção do GitHub Actions, se bem que devo admitir que &lt;strong&gt;às vezes&lt;/strong&gt; esqueço de configurar o CI/CD e só jogo tudo para a pobre máquina da Oracle tentar compilar Rust mesmo — e &lt;strong&gt;advinha&lt;/strong&gt;? Acaba &lt;strong&gt;quase explodindo tudo&lt;/strong&gt;! —&lt;/p&gt;
&lt;h3 id=&quot;gerando-chaves-ssh&quot;&gt;Gerando Chaves SSH&lt;a class=&quot;anchor&quot; href=&quot;#gerando-chaves-ssh&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Bem, na sessão anterior, comentei sobre os servidores remotos, mas, como sempre, acabei sendo prolixo e não ensinei a fazer o que foi proposto. Bem, vou solucionar isso agora.&lt;/p&gt;
&lt;p&gt;Como pode ter visto, para criar um Servidor Remoto você precisará de uma &lt;strong&gt;chave SSH&lt;/strong&gt; de alguma VPS sob seu controle. Para isso, o passo a passo é simples.&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-ssh-popup.png&quot; alt=&quot;dokploy-ssh-popup.png&quot; style=&quot;width: 100%;&quot;  /&gt;
&lt;p&gt;Primeiro, escolha um nome para essa chave, é uma boa para você não confundir a qual servidor ela pertence. Após isso, clique em &lt;strong&gt;Generate ED25519 SSH Key&lt;/strong&gt;. O Dokploy irá gerar as chaves para essa máquina.&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-ssh-popup-with-key.png&quot; alt=&quot;dokploy-ssh-popup-with-key.png&quot; style=&quot;width: 100%;&quot;  /&gt;
&lt;p&gt;Caso esteja curioso sobre por que usar ED25519 em vez de RSA, vale a pena a pesquisa, fica como dever de casa para os curiosos.&lt;/p&gt;
&lt;p&gt;O importante é que agora você só precisa mover a chave pública que foi gerada para a máquina que queremos ter acesso. Para isso, você apenas precisa acessar a máquina usando SSH; geralmente existe uma opção para isso no próprio painel da provedora que você obteve a máquina.&lt;/p&gt;
&lt;p&gt;Após isso, o passo a passo é simples:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;sudo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; su&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;mkdir&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;p&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; /root/.ssh&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;nano&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; /root/.ssh/authorized_keys&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Basicamente, &lt;strong&gt;garanta que está como superusuário na máquina&lt;/strong&gt; — geralmente você já estará mesmo —. Após isso, &lt;strong&gt;crie o diretório .ssh&lt;/strong&gt; e dentro dele crie o arquivo authorized_keys caso não exista. Você só precisa colar com o nano a chave pública &lt;strong&gt;em uma nova linha&lt;/strong&gt; no final do arquivo e salvar, após isso a chave poderá ser usada para acessar seu servidor.&lt;/p&gt;
&lt;p&gt;Tendo feito isso, agora pode finalmente criar o servidor remoto que foi comentado anteriormente.&lt;/p&gt;
&lt;h3 id=&quot;configurando-um-servidor-remoto&quot;&gt;Configurando um servidor Remoto&lt;a class=&quot;anchor&quot; href=&quot;#configurando-um-servidor-remoto&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;bom, agora que finalmente criou o servidor, você deve ter algo parecido com o seguinte no seu painel:&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-remote-server-created.png&quot; alt=&quot;dokploy-remote-server-created.png&quot;  /&gt;
&lt;p&gt;observe o botão gigante &lt;strong&gt;Setup Server&lt;/strong&gt;, não preciso falar que &lt;strong&gt;é ele que você vai usar&lt;/strong&gt;. Para ser preciso, ao clicar nele, você deve ver um popup contendo tudo que for necessário para configurar o servidor, e o que você está procurando está na aba &lt;strong&gt;Deployments&lt;/strong&gt;.&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-setup-server-deployments.png&quot; alt=&quot;dokploy-setup-server-deployments.png&quot; style=&quot;width: 100%;&quot;  /&gt;
&lt;p&gt;Se você está se perguntando agora por que você precisa &quot;&quot;setupar&quot;&quot; um servidor antes de usá-lo, significa que provavelmente nunca configurou um deploy manual.&lt;/p&gt;
&lt;p&gt;Imagine que para qualquer aplicação web subir, é obviamente necessário um servidor web. Este, por sua vez, &lt;strong&gt;escuta as portas 80 e 443&lt;/strong&gt; para responder às requisições tanto de HTTP como de HTTPS. Mas é óbvio que não vou colocar meu servidor Express direto nessas portas, certo? &lt;strong&gt;Certo?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Para impedir essas ideias malucas que muitos iniciantes podem ter, o Dokploy oferece um script que configura tudo na máquina automaticamente. Como o tópico do draft de hoje não é ensinar a configurar um servidor do zero, mas sim como configurar um PaaS, deixarei como segunda lição de casa você &lt;strong&gt;ler o script e descobrir o que cada parte dele faz&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;O importante é que após clicar em Setup Server ele irá instalar tudo que for necessário. Um &lt;strong&gt;disclaimer importante&lt;/strong&gt; é que, se por algum motivo você estiver usando uma máquina fraca como máquina remota, provavelmente será uma boa ideia configurar SWAP manualmente, como fiz com a máquina central. Isso &lt;strong&gt;impedirá que o script falhe por falta de RAM&lt;/strong&gt; durante sua instalação devido ao OOM Killer.&lt;/p&gt;
&lt;p&gt;Quando tudo estiver concluído, você poderá ir para a aba &lt;strong&gt;Validate&lt;/strong&gt; e ver se está tudo instalado como esperado. Caso queira explorar mais sobre segurança ou até mesmo como configurar uma GPU para rodar modelos de IA ou algum servidor de vídeo, fica aí como pesquisa.&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-setupserver-validate.png&quot; alt=&quot;dokploy-setupserver-validate.png&quot; style=&quot;width: 100%;&quot;  /&gt;
&lt;p&gt;Após concluir essa parte, sua máquina já deve estar pronta para o uso.&lt;/p&gt;
&lt;h2 id=&quot;subindo-um-projeto&quot;&gt;Subindo um projeto&lt;a class=&quot;anchor&quot; href=&quot;#subindo-um-projeto&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Agora que você está finalmente pronto, vamos pôr as mãos na massa. Vá na aba &lt;strong&gt;Projects&lt;/strong&gt; e crie um novo projeto. Neste projeto, crie um novo serviço. No meu caso, farei o uso de uma funcionalidade muito prática do Dokploy: os &lt;strong&gt;templates&lt;/strong&gt;.&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-project-create-service-menu.png&quot; alt=&quot;dokploy-project-create-service-menu.png&quot;  /&gt;
&lt;p&gt;Aqui você será levado a uma loja de aplicações pré-configuradas para você subir em seu servidor.&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-template-shop.png&quot; alt=&quot;dokploy-template-shop.png&quot; style=&quot;width: 100%;&quot;  /&gt;
&lt;p&gt;Uma que provavelmente você conhece é a ferramenta de desenho &lt;strong&gt;Excalidraw&lt;/strong&gt;, e advinha? Existe como um template de fácil acesso para ela, basta usar o campo de busca digitando o nome da ferramenta.&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-template-shop-excalidraw-search.png&quot; alt=&quot;dokploy-template-shop-excalidraw-search.png&quot; style=&quot;width: 100%;&quot;  /&gt;
&lt;p&gt;Agora que a encontrou, você só precisa clicar em &lt;strong&gt;Create&lt;/strong&gt;.&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-template-excalidraw-server-selection.png&quot; alt=&quot;dokploy-template-excalidraw-server-selection.png&quot; style=&quot;width: 100%;&quot;  /&gt;
&lt;p&gt;Após isso, selecione &lt;strong&gt;o servidor em que será realizado o deploy&lt;/strong&gt;. Lembre-se de selecionar um diferente do &lt;strong&gt;Default&lt;/strong&gt;, já que esse será o que está rodando a plataforma atualmente e será bastante limitado. No meu caso, colocarei em um Droplet que tenho na DigitalOcean.&lt;/p&gt;
&lt;p&gt;Após confirmar, você verá que o serviço do Excalidraw foi criado. Ao clicar nele, obterá a seguinte página:&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-excalidraw-details-page.png&quot; alt=&quot;dokploy-excalidraw-details-page.png&quot; style=&quot;width: 100%;&quot;  /&gt;
&lt;p&gt;Agora, o deploy dele é tão simples quanto apertar &lt;strong&gt;Deploy&lt;/strong&gt; e confirmar. Após isso, você será jogado para essa página em que todos os deploys serão listados. Quando a aplicação estiver pronta, ela mostrará um &lt;strong&gt;indicador verde&lt;/strong&gt; em vez do amarelo, caso algo dê errado ele mostrará um indicador vermelho, nesse caso você só precisa clicar em view e ler os logs para entender o que ocorreu de errado.&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-excalidraw-deployments.png&quot; alt=&quot;dokploy-excalidraw-deployments.png&quot; style=&quot;width: 100%;&quot;  /&gt;
&lt;p&gt;Indo na aba &lt;strong&gt;Domains&lt;/strong&gt;, você encontrará uma página apontando para um domínio temporário criado pelo próprio Dokploy para permitir acesso da aplicação pela internet.&lt;/p&gt;
&lt;p&gt;Caso queira ver como fica, &lt;strong&gt;sinta-se livre para ver a aplicação rodando em &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;http://homelab-excalidraw-19ed4b-174-138-83-120.traefik.me/&quot;&gt;http://homelab-excalidraw-19ed4b-174-138-83-120.traefik.me/&lt;/a&gt;&lt;/strong&gt;. Caso o link esteja quebrado, provavelmente o Eu do futuro apagou a aplicação em alguma maluquice da madrugada. Para aqueles que não tiveram a experiência de ver pessoalmente, &lt;strong&gt;fica o print abaixo de como está rodando&lt;/strong&gt;.&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-excalidraw-webpage.png&quot; alt=&quot;dokploy-excalidraw-webpage.png&quot; style=&quot;width: 100%;&quot;  /&gt;
&lt;h3 id=&quot;vinculando-com-o-github&quot;&gt;Vinculando com o GitHub&lt;a class=&quot;anchor&quot; href=&quot;#vinculando-com-o-github&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Até agora, tudo certo. Consegui subir aplicações usando templates, mas e se você quiser subir um projeto que está no seu &lt;strong&gt;GitHub&lt;/strong&gt;? Bem, para isso é simples: em configurações, vá na aba &lt;strong&gt;Git&lt;/strong&gt;.&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-settings-git.png&quot; alt=&quot;dokploy-settings-git.png&quot;  /&gt;
&lt;p&gt;Selecione o provedor de sua preferência; geralmente será o &lt;strong&gt;GitHub&lt;/strong&gt;.&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-git-providers.png&quot; alt=&quot;dokploy-git-providers.png&quot; style=&quot;width: 100%;&quot;  /&gt;
&lt;p&gt;Após isso, basta criar um novo provedor e vincular a sua conta.&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-create-git-provider.png&quot; alt=&quot;dokploy-create-git-provider.png&quot; style=&quot;width: 100%;&quot;  /&gt;
&lt;p&gt;Opcionalmente, você pode limitar ele para ver somente alguns repositórios específicos, caso não queira deixar todos visíveis.&lt;/p&gt;
&lt;p&gt;Você deverá conseguir subir aplicações normalmente, apenas basta selecionar o provedor, o repositório e a branch na hora de realizar o deploy.&lt;/p&gt;
&lt;h2 id=&quot;configurando-backups&quot;&gt;Configurando Backups&lt;a class=&quot;anchor&quot; href=&quot;#configurando-backups&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;De nada vale ter todo esse trabalho para configurar o servidor principal, se, em algum momento, por algum infortúnio do destino, você acabar apagando tudo e todas as suas configurações acabarem &lt;strong&gt;indo para o lixo&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Para impedir isso, vou configurar um backup simples e gratuito para manter as configurações seguras. Isso pode ser facilmente configurado usando a aba S3 Destinations.&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-settings-s3-destinations.png&quot; alt=&quot;dokploy-settings-s3-destinations.png&quot;  /&gt;
&lt;p&gt;Ao contrário do que o nome diz, ele não suporta apenas a Amazon S3.&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-add-destination.png&quot; alt=&quot;dokploy-add-destination.png&quot; style=&quot;width: 100%;&quot;  /&gt;
&lt;p&gt;Como se pode ver, ao criar uma destination, ele permite selecionar o provedor e, como o objetivo é economizar sempre, você pode usar a &lt;strong&gt;CloudFlare R2&lt;/strong&gt;, que oferece &lt;strong&gt;10 GB sem taxa de transação&lt;/strong&gt; até um valor X milhão de transações por mês (dependendo se são categoria A ou B). Para mais detalhes, &lt;strong&gt;leia a documentação&lt;/strong&gt;, pois o valor e as taxas podem ser atualizadas quando você estiver lendo essa postagem.&lt;/p&gt;
&lt;p&gt;A integração é simples: entre na sua conta da &lt;strong&gt;CloudFlare&lt;/strong&gt;, crie um &lt;strong&gt;bucket&lt;/strong&gt;, adicione o IP do seu servidor na &lt;strong&gt;whitelist&lt;/strong&gt; do bucket, pegue as credenciais e preencha o formulário. É basicamente um &lt;strong&gt;copiar e colar&lt;/strong&gt;. Se tudo estiver certo, você deve conseguir usar o &lt;strong&gt;Test Connection&lt;/strong&gt; para ver se está tudo integrado corretamente.&lt;/p&gt;
&lt;p&gt;Após estar tudo configurado, você pode configurar o backup automático simplesmente indo em Web Server.&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-settings-web-server.png&quot; alt=&quot;dokploy-settings-web-server.png&quot;  /&gt;
&lt;p&gt;Descendo até o final da página, você encontrará uma seção de backups. Ao adicionar um novo, você apenas precisará selecionar a &lt;strong&gt;frequência&lt;/strong&gt; do backup, sua &lt;strong&gt;destination&lt;/strong&gt; e afins.&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-create-backup.png&quot; alt=&quot;dokploy-create-backup.png&quot; style=&quot;width: 100%;&quot;  /&gt;
&lt;p&gt;No final, você terá automaticamente os backups de suas configurações sendo feitas e mantidas em seu bucket. Caso queira restaurar o backup, basta usar a ferramenta de restauração disponível nessa mesma seção.&lt;/p&gt;
&lt;h2 id=&quot;acessando-de-maneira-facil&quot;&gt;Acessando de maneira fácil&lt;a class=&quot;anchor&quot; href=&quot;#acessando-de-maneira-facil&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;De nada adianta configurar seu servidor, subir aplicações, configurar backups e, no final, seu link de acesso ser um IP ou um domínio aleatório gerado pela própria aplicação. Afinal, você não vai querer digitar &lt;code&gt;http://homelab-excalidraw-19ed4b-174-138-83-120.traefik.me/&lt;/code&gt; toda vez que quiser apenas entrar na sua própria aplicação ou no seu próprio painel.&lt;/p&gt;
&lt;p&gt;Felizmente, o Dokploy possui suporte fácil à integração direta para configuração de domínios, tanto para aplicações individualmente como para o painel como um todo, além de incluir certificados SSL do &lt;strong&gt;Let&#39;s Encrypt&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Para isso, você só precisa clicar em &lt;strong&gt;Add Domain&lt;/strong&gt;.&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-excalidraw-domains.png&quot; alt=&quot;dokploy-excalidraw-domains.png&quot; style=&quot;width: 100%;&quot;  /&gt;
&lt;p&gt;Após isso, você só precisa preencher as configurações básicas. Selecione o serviço que você irá querer rodar — por favor, não deixe seu banco de dados aberto na internet — e, após isso, preencha seu domínio. Caso queira ativar HTTPS, é tão simples quanto &lt;strong&gt;marcar uma checkbox&lt;/strong&gt;.&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-add-domain.png&quot; alt=&quot;dokploy-add-domain.png&quot; style=&quot;width: 100%;&quot;  /&gt;
&lt;p&gt;Após isso, você só precisa apontar seu domínio para o IP do servidor que irá rodar a aplicação, o que pode ser facilmente obtido simplesmente clicando no nome da máquina em que a aplicação está configurada. Assim, ele automaticamente copia o IP para sua área de colagem.&lt;/p&gt;
&lt;img src=&quot;/imgs/dokploy-get-ip-from-server.png&quot; alt=&quot;dokploy-get-ip-from-server.png&quot; style=&quot;width: 100%;&quot;  /&gt;
&lt;p&gt;O mesmo pode ser feito para o próprio painel da Dokploy, na área &lt;strong&gt;Web Server&lt;/strong&gt;, em que você só precisará preencher o domínio do seu servidor, o seu email para assinar o certificado do &lt;strong&gt;Let&#39;s Encrypt&lt;/strong&gt; e, se quiser, o mesmo procedimento de simplesmente marcar uma checkbox para ativar o SSL.&lt;/p&gt;
&lt;p&gt;Caso queira economizar com domínios, &lt;strong&gt;lembre-se que você sempre pode usar um subdomínio de um domínio existente&lt;/strong&gt;. Ou seja, caso você já tenha seu domínio &lt;code&gt;joaozinho.dev&lt;/code&gt;, você pode subir seu CloudLab em&lt;code&gt;cloud.joaozinho.dev&lt;/code&gt; ou qualquer outra variação que quiser. Apenas precisa configurar isso no seu provedor e preencher corretamente no Dokploy.&lt;/p&gt;
&lt;h2 id=&quot;conclusao&quot;&gt;Conclusão&lt;a class=&quot;anchor&quot; href=&quot;#conclusao&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Sinceramente, o Dokploy é uma ótima ferramenta para quem gosta de se divertir subindo coisas e não quer ficar dependente de serviços externos. Neste draft, eu apenas arranhei a superfície de tudo que essa ferramenta pode fazer.&lt;/p&gt;
&lt;p&gt;Recomendo &lt;strong&gt;fortemente&lt;/strong&gt; que explore todas as integrações que a plataforma oferece, seja com &lt;strong&gt;IA&lt;/strong&gt;, com &lt;strong&gt;Registries&lt;/strong&gt;, além de suporte para subir aplicações em diferentes ambientes — como no mesmo projeto ter a separação do ambiente de desenvolvimento, homologação e produção — , &lt;strong&gt;rollbacks programáticos&lt;/strong&gt;, &lt;strong&gt;limpeza automática de imagens do Docker não usadas com frequência&lt;/strong&gt; tanto para o servidor principal quanto para os servidores remotos, o que ajuda &lt;strong&gt;e muito&lt;/strong&gt; nessas máquinas com pouco armazenamento.&lt;/p&gt;
&lt;p&gt;Com a crise do Hardware aumentando cada vez mais e mais e os preços indo ao infinito, vale até mesmo considerar fazer um &lt;strong&gt;HomeLab real&lt;/strong&gt; usando um PC velho e o Dokploy como orquestrador, caso queira toda essa praticidade enquanto mantém tudo no seu hardware pessoal, além de poder expor a aplicação usando algo como o Tunnel da CloudFlare.&lt;/p&gt;
&lt;p&gt;As possibilidades são basicamente ilimitadas. Sinta-se livre para inventar maluquices e experimentar ideias. Se algo quebrar, você com certeza irá aprender algo novo consertando, o que acrescenta tanto para sua carreira como desenvolvedor quanto como indivíduo entusiasta de TI.&lt;/p&gt;
</content>
        
    </entry>
    <entry xml:lang="pt">
        <title>SQLx: O Custo Cognitivo da Segurança em Tempo de Compilação</title>
        <published>2025-12-27T00:00:00+00:00</published>
        <updated>2025-12-27T00:00:00+00:00</updated>
        
        <author>
          <name>lucasbrt</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://lucasbrt.dev/artigos/sqlx-o-custo-cognitivo-da-seguranca-em-tempo-de-compilacao/"/>
        <id>https://lucasbrt.dev/artigos/sqlx-o-custo-cognitivo-da-seguranca-em-tempo-de-compilacao/</id>
        
        <content type="html" xml:base="https://lucasbrt.dev/artigos/sqlx-o-custo-cognitivo-da-seguranca-em-tempo-de-compilacao/">&lt;p&gt;Caso já tenha tentado usar Rust para se conectar a algum banco de dados, pode ter tido uma sensação desconfortável, as alternativas atuais da comunidade não são nem de longe tão produtivas quanto de outras linguagens, enquanto em outras linguagens temos ORM&#39;s que abstraem toda a escrita de queries complexas com simples chamadas de métodos encadeados, além de fornecer praticamente de graça os modelos que espelham o banco de dados de maneira simplificada.&lt;/p&gt;
&lt;p&gt;Em comparação, em Rust temos algumas &lt;code&gt;crates&lt;/code&gt; que fornecem alternativas para funções semelhantes, dentre elas podemos listar dois grupos.&lt;/p&gt;
&lt;p&gt;O primeiro tem as que se propõem a seguir uma abordagem de ORM em si, nisso temos &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://diesel.rs/&quot;&gt;Diesel&lt;/a&gt;, que serve tanto como ORM quanto como query builder, e &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://www.sea-ql.org/SeaORM/&quot;&gt;Sea-ORM&lt;/a&gt;, que se propõe a ser o ORM assíncrono e devido a isso, aparenta ter uma adoção um pouco maior.&lt;/p&gt;
&lt;p&gt;Já o segundo grupo, curiosamente composto por apenas pela crate &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/launchbadge/sqlx&quot;&gt;SQLX&lt;/a&gt;, que não se propõe a ser uma ORM, mas mesmo assim fornecendo funcionalidades extremamente úteis, como checagem de queries em tempo de compilação, assincronicidade, dentre outras.&lt;/p&gt;
&lt;h2 id=&quot;escrevendo-queries-simples&quot;&gt;Escrevendo Queries Simples&lt;a class=&quot;anchor&quot; href=&quot;#escrevendo-queries-simples&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Antes de sairmos tentando escrever queries complexas de maneira segura e otimizada vamos aprender a fazer as coisas mais simples.&lt;/p&gt;
&lt;p&gt;Vamos considerar um banco de dados bem simplório, digamos um que contém apenas uma tabela listando usuários do sistema. O Schema ficaria assim:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;sql&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; users&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    id &lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;SERIAL&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; PRIMARY KEY&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    name&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; VARCHAR&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;255&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; NOT NULL&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    age &lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;INTEGER&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; NOT NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Podemos listar todos os usuários cadastrados no banco de dados usando a seguinte query:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;sql&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;SELECT&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; FROM&lt;/span&gt;&lt;span&gt; users;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Vamos agora tentar usar o sqlx para executar essa pesquisa.&lt;/p&gt;
&lt;h3 id=&quot;setup-inicial-com-sqlx&quot;&gt;Setup Inicial com SQLX&lt;a class=&quot;anchor&quot; href=&quot;#setup-inicial-com-sqlx&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Primeiro vamos criar um novo projeto rust usando Cargo.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;cargo&lt;/span&gt;&lt;span&gt; new sqlx-test&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Adicionamos o sqlx e tokio como dependencias no &lt;code&gt;cargo.toml&lt;/code&gt;&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;dependencies&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;span&gt; version&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;0.8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; features&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;runtime-tokio&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; ]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;tokio&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;span&gt; version&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;1.48.0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; features&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;full&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; }&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;E escrevemos uma main simples&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;PgPool&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;const&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; DB_URL&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;str&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;postgres://postgres:postgres@localhost:5432/sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;tokio&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;async&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; main&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Result&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);&quot;&gt; sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Error&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; conn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; PgPool&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;connect&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;DB_URL&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; result&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;query&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;SELECT 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;fetch_one&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;conn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    println!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;:#?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; result&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    Ok&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ao executar usando &lt;code&gt;cargo run&lt;/code&gt; teremos o seguinte resultado:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   Compiling&lt;/span&gt;&lt;span&gt; sqlx-test v0.1.0 &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;/home/lucasbrt/Projects/sqlx-test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Finished&lt;/span&gt;&lt;span&gt; `dev` profile [unoptimized + debuginfo] target&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt; 0.73s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;     Running&lt;/span&gt;&lt;span&gt; `target/debug/sqlx-test`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;PgRow&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;    ?&lt;/span&gt;&lt;span&gt;column&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;?&lt;/span&gt;&lt;span&gt;: 1,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Como podemos ver, ele retorna uma coluna ?column? com o valor 1, já que a coluna em si não é retornada nessa query, o valor ?column? é um indicador que nenhuma coluna existia em um schema do banco para criar uma abstração com Rust.&lt;/p&gt;
&lt;h3 id=&quot;queries-simples-com-sqlx&quot;&gt;Queries simples com SQLX&lt;a class=&quot;anchor&quot; href=&quot;#queries-simples-com-sqlx&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Podemos listar todos os usuários no banco usando o seguinte código&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;derive&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Debug&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;FromRow&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; User&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    id&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; i64&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    name&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; String&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    age&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; i64&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;tokio&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;async&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; main&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Result&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);&quot;&gt; sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Error&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; conn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; PgPool&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;connect&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;DB_URL&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; result&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;query_as&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span&gt;_&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; User&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;select * from users&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;        .&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;fetch_all&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;conn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;        .&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    println!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;:#?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; result&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    Ok&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Observe que precisamos definir a struct &lt;code&gt;User&lt;/code&gt; com todos os campos da tabela no banco de dados, e além disso precisamos derivar a Trait &lt;code&gt;FromRow&lt;/code&gt; para permitir que ele mapeie o resultado da query para essa struct.&lt;/p&gt;
&lt;p&gt;Ao rodar esse código obtemos o seguinte resultado:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Finished&lt;/span&gt;&lt;span&gt; `dev` profile [unoptimized + debuginfo] target&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt; 21.32s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;     Running&lt;/span&gt;&lt;span&gt; `target/debug/sqlx-test`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;[]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;As outras operações CRUD podem ser facilmente realizadas simplesmente mudando o método final que realiza a chamada e mudando o tipo que é fornecido na chamada da função.&lt;/p&gt;
&lt;h2 id=&quot;problemas-de-seguranca-e-developer-experience&quot;&gt;Problemas de segurança e Developer Experience&lt;a class=&quot;anchor&quot; href=&quot;#problemas-de-seguranca-e-developer-experience&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;O problema, como deve saber, é que esse tipo de código é muito frágil, já que o estado do banco de dados pode mudar e o desenvolvedor, humano que é, pode acabar por esquecer de atualizar a struct que espelha a tabela do banco de dados, nessa situação observe o que acontece.&lt;/p&gt;
&lt;p&gt;Primeiro vamos realizar uma atualização simples no banco de dados:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;sql&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;ALTER&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; TABLE&lt;/span&gt;&lt;span&gt; users&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;DROP&lt;/span&gt;&lt;span&gt; COLUMN id;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;ALTER&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; TABLE&lt;/span&gt;&lt;span&gt; users&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;ADD&lt;/span&gt;&lt;span&gt; COLUMN id_uuid UUID &lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; DEFAULT&lt;/span&gt;&lt;span&gt; gen_random_uuid&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Nesse momento concordemos que o a struct que antes espelhava a tabela users não está correta, afinal, o Rust espera um i64, mas o banco estará retornando um UUID, o que obviamente ocasionará em problemas ao executar essa query.&lt;/p&gt;
&lt;p&gt;Vamos adicionar alguns usuários e observar o comportamento obtido.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;sql&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;INSERT INTO&lt;/span&gt;&lt;span&gt; users (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;name&lt;/span&gt;&lt;span&gt;, age) &lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;VALUES&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;jhon&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;20&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;INSERT INTO&lt;/span&gt;&lt;span&gt; users (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;name&lt;/span&gt;&lt;span&gt;, age) &lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;VALUES&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;mary&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;22&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Vamos ver como o código atual se comporta, primeiro vamos tentar compilá-lo:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@nixos ~/P/sqlx-test &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;master&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; cargo&lt;/span&gt;&lt;span&gt; build&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   Compiling&lt;/span&gt;&lt;span&gt; sqlx-test v0.1.0 &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;/home/lucasbrt/Projects/sqlx-test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Finished&lt;/span&gt;&lt;span&gt; `dev` profile [unoptimized + debuginfo] target&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt; 0.59s&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Agora vamos tentar executar e ver como se comporta:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@nixos ~/P/sqlx-test &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;master&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; cargo&lt;/span&gt;&lt;span&gt; run&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Finished&lt;/span&gt;&lt;span&gt; `dev` profile [unoptimized + debuginfo] target&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt; 0.09s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;     Running&lt;/span&gt;&lt;span&gt; `target/debug/sqlx-test`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Error&lt;/span&gt;&lt;span&gt;: ColumnDecode { index: &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;id&lt;/span&gt;&lt;span style=&quot;color: light-dark(#EA76CB, #F5C2E7);&quot;&gt;\&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;, source: &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;mismatched types; Rust type `i64` (as SQL type `INT8`) is not compatible with SQL type `UUID`&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt; }&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Como podemos ver, um erro ocorreu, como havíamos previsto, agora podemos simplesmente atualizar a struct para espelhar corretamente a tabela do banco e continuar a desenvolver, certo? Errado! apesar de isso ser comum em algumas outras linguagens quando se tenta escrever queries diretamente, SQLX propõe uma solução mais elegante e segura.&lt;/p&gt;
&lt;p&gt;Em vez de usarmos a função &lt;code&gt;query_as&lt;/code&gt;, vamos usar a macro &lt;code&gt;query_as!&lt;/code&gt;, a maneira de usar é passando como primeiro parâmetro o tipo que espelha a tabela do banco de dados, o segundo parâmetro é a query em si, além disso, não precisamos mais derivar a trait &lt;code&gt;FromRow&lt;/code&gt; já que a macro lidará com tudo internamente.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;let&lt;/span&gt;&lt;span&gt; result&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;query_as!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;User&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;SELECT * FROM users&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;    .&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;fetch_all&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;conn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;    .&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Fazendo essa simples mudança temos uma nova maneira de garantir a consistência das nossas queries. Vamos tentar rodar o código novamente e ver o resultado.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@nixos ~/P/sqlx-test &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;master&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; cargo&lt;/span&gt;&lt;span&gt; run&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   Compiling&lt;/span&gt;&lt;span&gt; sqlx-test v0.1.0 &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;/home/lucasbrt/Projects/sqlx-test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;error[E0277]&lt;/span&gt;&lt;span&gt;: the trait bound `i64: From&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;Uuid&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;` is not satisfied&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;  --&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; src/main.rs&lt;/span&gt;&lt;span&gt;:17:18&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;17&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;     let&lt;/span&gt;&lt;span&gt; result = sqlx::query_as!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;User&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;SELECT * FROM users&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   |                  &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; the&lt;/span&gt;&lt;span&gt; trait `From&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;Uuid&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;` is not implemented for `i64`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   = help: the following other types implement trait `From&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;`:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;             `i64` implements `From&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;             `i64` implements `From&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;i16&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;             `i64` implements `From&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;i32&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;             `i64` implements `From&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;i8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;             `i64` implements `From&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;u16&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;             `i64` implements `From&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;u32&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;             `i64` implements `From&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;u8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;             `i64` implements `From&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;zerocopy&lt;/span&gt;&lt;span&gt;::byteorder::I16&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;O&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;           and&lt;/span&gt;&lt;span&gt; 2 others&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   = note: required for `Uuid` to implement `Into&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;i64&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   = note: this error originates &lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;in&lt;/span&gt;&lt;span&gt; the macro `&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;crate&lt;/span&gt;&lt;span&gt;::sqlx_macros::expand_query` which comes from the expansion of the macro `sqlx::query_as` &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;in&lt;/span&gt;&lt;span&gt; Nightly builds, run with&lt;/span&gt;&lt;span&gt; -Z&lt;/span&gt;&lt;span&gt; macro-backtrace for more info&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;For&lt;/span&gt;&lt;span&gt; more information about this error, try `rustc&lt;/span&gt;&lt;span&gt; --explain&lt;/span&gt;&lt;span&gt; E0277`.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;error&lt;/span&gt;&lt;span&gt;: could not compile `sqlx-test` &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;bin&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;sqlx-test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span&gt; due to 1 previous error&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Como podemos ver, ocorreu um erro, mas diferentemente de antes, esse foi em tempo de compilação e não execução. Isso ocorre por que a macro &lt;code&gt;query_as!&lt;/code&gt; verifica o resultado da querie em tempo de compilação com o banco de dados, mas para isso é preciso ter a variável &lt;code&gt;DATABASE_URL&lt;/code&gt; definida no ambiente apontando para um banco de dados válido.&lt;/p&gt;
&lt;p&gt;Agora que temos uma maneira de validar nossas queries em tempo de compilação, vamos corrigir a definição da struct, como podemos ver, o erro ocorre devido ao fato do tipo i64 não implementar a trait &lt;code&gt;From&amp;lt;Uuid&amp;gt;&lt;/code&gt;. Poderíamos implementar esse tipo manualmente, ou, mais facilmente, atualizar a struct para mapear corretamente a tabela.&lt;/p&gt;
&lt;p&gt;Primeiro vamos atualizar a struct &lt;code&gt;User&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;types&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Uuid&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;derive&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Debug&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; User&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    id&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Uuid&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    name&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; String&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    age&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; i64&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Agora ao tentarmos rodar o programa temos o seguinte resultado:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@nixos ~/P/sqlx-test &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;master&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; cargo&lt;/span&gt;&lt;span&gt; run&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   Compiling&lt;/span&gt;&lt;span&gt; sqlx-test v0.1.0 &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;/home/lucasbrt/Projects/sqlx-test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Finished&lt;/span&gt;&lt;span&gt; `dev` profile [unoptimized + debuginfo] target&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt; 0.77s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;     Running&lt;/span&gt;&lt;span&gt; `target/debug/sqlx-test`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    User&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        id&lt;/span&gt;&lt;span&gt;: b0caaafc-62b0-498f-a31a-41820c7ef081,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        name&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;jhon&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        age&lt;/span&gt;&lt;span&gt;: 20,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    User&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        id&lt;/span&gt;&lt;span&gt;: 15867cae-4b82-4eb6-864f-0696b79752a8,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        name&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;mary&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        age&lt;/span&gt;&lt;span&gt;: 22,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Como pode ver temos duas vantagens, a primeira é que o que é retornado agora é literalmente uma struct Rust normal, e não alguma abstração do sqlx para mapear a tabela. Além disso, podemos garantir que ao escrever uma querie, o compilador irá garantir que ela funcionará com o banco de dados, garantindo assim uma maior consistência entre a lógica da aplicação em si e o banco de dados.&lt;/p&gt;
&lt;p&gt;Tal segurança entretanto vem com um porém, vejamos o que ocorre se eu tentar rodar o código sem estar com o banco de dados rodando.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@nixos ~/P/sqlx-test &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;master&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; cargo&lt;/span&gt;&lt;span&gt; check&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Checking&lt;/span&gt;&lt;span&gt; sqlx-test v0.1.0 &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;/home/lucasbrt/Projects/sqlx-test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;error&lt;/span&gt;&lt;span&gt;: error communicating with database: Connection refused &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;os&lt;/span&gt;&lt;span&gt; error 111&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;  --&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; src/main.rs&lt;/span&gt;&lt;span&gt;:17:18&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;17&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;     let&lt;/span&gt;&lt;span&gt; result = sqlx::query_as!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;User&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;SELECT * FROM users&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   |                  &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   = note: this error originates &lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;in&lt;/span&gt;&lt;span&gt; the macro `&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;crate&lt;/span&gt;&lt;span&gt;::sqlx_macros::expand_query` which comes from the expansion of the macro `sqlx::query_as` &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;in&lt;/span&gt;&lt;span&gt; Nightly builds, run with&lt;/span&gt;&lt;span&gt; -Z&lt;/span&gt;&lt;span&gt; macro-backtrace for more info&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;error&lt;/span&gt;&lt;span&gt;: could not compile `sqlx-test` &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;bin&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;sqlx-test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span&gt; due to 1 previous error```&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A aplicação depende do banco para rodar, o que acaba tornando a aplicação diretamente acoplada ao banco, o que já é uma má prática, mas piora ainda mais quando paramos para pensar que o banco por si só pode ter seu próprio versionamento, seja por meio de migrations ou qualquer outra tática de atualização, tornando a arquitetura ainda mais complexa.&lt;/p&gt;
&lt;p&gt;Para solucionar isso podemos usar uma variável de ambiente a mais, a &lt;code&gt;SQLX_OFFLINE&lt;/code&gt; com o valor true. O objetivo é fazer com que o SQLX não tente se conectar ao banco de dados para garantir a consistência das queries.&lt;/p&gt;
&lt;p&gt;Ao rodarmos a aplicação temos o seguinte:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@nixos ~/P/sqlx-test &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;master&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; cargo&lt;/span&gt;&lt;span&gt; check&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Checking&lt;/span&gt;&lt;span&gt; sqlx-test v0.1.0 &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;/home/lucasbrt/Projects/sqlx-test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;error&lt;/span&gt;&lt;span&gt;: `SQLX_OFFLINE=true` but there is no cached data for this query, run `cargo sqlx prepare` to update the query cache or unset `SQLX_OFFLINE`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;  --&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; src/main.rs&lt;/span&gt;&lt;span&gt;:17:18&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;17&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;     let&lt;/span&gt;&lt;span&gt; result = sqlx::query_as!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;User&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;SELECT * FROM users&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   |                  &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   = note: this error originates &lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;in&lt;/span&gt;&lt;span&gt; the macro `&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;crate&lt;/span&gt;&lt;span&gt;::sqlx_macros::expand_query` which comes from the expansion of the macro `sqlx::query_as` &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;in&lt;/span&gt;&lt;span&gt; Nightly builds, run with&lt;/span&gt;&lt;span&gt; -Z&lt;/span&gt;&lt;span&gt; macro-backtrace for more info&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;error&lt;/span&gt;&lt;span&gt;: could not compile `sqlx-test` &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;bin&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;sqlx-test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span&gt; due to 1 previous error&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Como podemos ver, antes de rodar com essa variável ligada, precisamos preparar o cache do banco, aí sim poderemos rodar a aplicação offline.&lt;/p&gt;
&lt;p&gt;Vamos subir o banco de dados novamente e após isso rodar o comando &lt;code&gt;cargo sqlx prepare&lt;/code&gt; para criar um cache local da versão atual do banco de dados.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@nixos ~/P/sqlx-test &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;master&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span&gt; [1]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; cargo&lt;/span&gt;&lt;span&gt; sqlx prepare&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Checking&lt;/span&gt;&lt;span&gt; sqlx-test v0.1.0 &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;/home/lucasbrt/Projects/sqlx-test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Finished&lt;/span&gt;&lt;span&gt; `dev` profile [unoptimized + debuginfo] target&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt; 0.17s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;query&lt;/span&gt;&lt;span&gt; data written to .sqlx &lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;in&lt;/span&gt;&lt;span&gt; the current directory&lt;/span&gt;&lt;span&gt;; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;please&lt;/span&gt;&lt;span&gt; check this into version control&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Agora temos um cache local da versão atual do banco de dados, e com isso podemos rodar a aplicação sem o banco estar rodando. Vamos derrubar o banco novamente e tentar compilar o programa.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@nixos ~/P/sqlx-test &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;master&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; cargo&lt;/span&gt;&lt;span&gt; build&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Finished&lt;/span&gt;&lt;span&gt; `dev` profile [unoptimized + debuginfo] target&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt; 0.10s&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Agora a aplicação está compilando, mas será que ela ainda está verificando a integridade do código em relação ao banco?&lt;/p&gt;
&lt;p&gt;Vamos mudar o tipo do id do User novamente e ver se ele retorna um erro.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@nixos ~/P/sqlx-test &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;master&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; cargo&lt;/span&gt;&lt;span&gt; check&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Checking&lt;/span&gt;&lt;span&gt; sqlx-test v0.1.0 &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;/home/lucasbrt/Projects/sqlx-test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;error[E0277]&lt;/span&gt;&lt;span&gt;: the trait bound `i64: From&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;Uuid&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;` is not satisfied&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;  --&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; src/main.rs&lt;/span&gt;&lt;span&gt;:17:18&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;17&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;     let&lt;/span&gt;&lt;span&gt; result = sqlx::query_as!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;User&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;SELECT * FROM users&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   |                  &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; the&lt;/span&gt;&lt;span&gt; trait `From&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;Uuid&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;` is not implemented for `i64`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   = help: the following other types implement trait `From&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;T&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;`:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;             `i64` implements `From&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;bool&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;             `i64` implements `From&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;i16&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;             `i64` implements `From&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;i32&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;             `i64` implements `From&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;i8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;             `i64` implements `From&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;u16&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;             `i64` implements `From&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;u32&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;             `i64` implements `From&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;u8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;             `i64` implements `From&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;zerocopy&lt;/span&gt;&lt;span&gt;::byteorder::I16&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;O&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;           and&lt;/span&gt;&lt;span&gt; 2 others&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   = note: required for `Uuid` to implement `Into&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;i64&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   = note: this error originates &lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;in&lt;/span&gt;&lt;span&gt; the macro `&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;crate&lt;/span&gt;&lt;span&gt;::sqlx_macros::expand_query` which comes from the expansion of the macro `sqlx::query_as` &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;in&lt;/span&gt;&lt;span&gt; Nightly builds, run with&lt;/span&gt;&lt;span&gt; -Z&lt;/span&gt;&lt;span&gt; macro-backtrace for more info&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;For&lt;/span&gt;&lt;span&gt; more information about this error, try `rustc&lt;/span&gt;&lt;span&gt; --explain&lt;/span&gt;&lt;span&gt; E0277`.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;error&lt;/span&gt;&lt;span&gt;: could not compile `sqlx-test` &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;bin&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;sqlx-test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span&gt; due to 1 previous error&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;O erro é mostrado, assim como esperado, e além disso temos uma vantagem a mais, como o compilador precisa apenas ler o diretório de cache .sqlx em vez de se conectar diretamente ao banco, isso reduz o tempo de compilação, mesmo que por pouco, essa pequena diferença se tornará grande caso tenha muitas queries escritas ao decorrer de sua aplicação.&lt;/p&gt;
&lt;p&gt;Infelizmente nenhuma solução é perfeita, e devido a isso temos um trade-off escondido ao usar a abordagem do sqlx_offline, por um lado não precisamos forçar os desenvolvedores a subir bancos em suas máquinas locais e garantir que esse banco esteja rodando com a última migration, mas ao mesmo tempo temos um novo problema.&lt;/p&gt;
&lt;p&gt;Agora precisamos garantir que o desenvolvedor atualize e versione corretamente seu diretório .sqlx que serve como cache do estado atual do seu banco, o que pode se tornar uma dor de cabeça com desenvolvedores inexperientes e ambientes de CI.&lt;/p&gt;
&lt;p&gt;Uma solução para isso seria usar um banco real no durante o CI para permitir rodar os testes e compilar a aplicação, garantindo assim a interoperabilidade entre o banco e a aplicação.&lt;/p&gt;
&lt;p&gt;Cada abordagem possui seus pontos positivos e negativos, então vale a pena considerar bem antes de definir qual usar.&lt;/p&gt;
&lt;h2 id=&quot;construindo-modelos&quot;&gt;Construindo Modelos&lt;a class=&quot;anchor&quot; href=&quot;#construindo-modelos&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Vamos adicionar a tabela produtos para demonstrar outras funcionalidades e detalhes específicos do SQLX.&lt;/p&gt;
&lt;p&gt;Vamos considerar a tabela contendo id, nome do produto, preço, descrição e tipo do produto, que por sua vez é um enum. Usaremos enum já que nesse exemplo sabemos que não ocorrerão tantas mudanças nas definições dos tipos que um produto pode ter. Além disso, Rust trabalha muito com enums, e SQLX promove uma maneira de garantir a interoperabilidade das enums do banco e da linguagem.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;sql&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; TYPE&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; ProductKind&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; AS&lt;/span&gt;&lt;span&gt; ENUM (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;digital&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;physical&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; products&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    id UUID &lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; DEFAULT&lt;/span&gt;&lt;span&gt; gen_random_uuid&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    name&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; VARCHAR&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;255&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; NOT NULL&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    price &lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;BIGINT&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; NOT NULL&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    description&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; TEXT&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    kind ProductKind &lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;NOT NULL&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Agora vamos mostrar como criar o modelo de produto no Rust.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;derive&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Debug&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Type&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;type_name &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;ProductKind&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; rename_all &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;lowercase&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;enum&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; ProductKind&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    Digital&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    Physical&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;derive&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Debug&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Product&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    id&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Uuid&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    name&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; String&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    price&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; i64&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    description&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Option&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;String&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    kind&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; ProductKind&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Observe que para usar o enum ProductKind, precisamos adicionar o atributo #[derive(Debug, sqlx::Type)] e especificar o nome do tipo no banco de dados usando #[sqlx(type_name = &quot;ProductKind&quot;, rename_all = &quot;lowercase&quot;)]. Isso permite que o SQLX reconheça o tipo enum no banco de dados e o mapeie para o tipo enum no Rust.&lt;/p&gt;
&lt;p&gt;Sem isso o SQLX não seria capaz de reconhecer o tipo enum no banco de dados e mapeá-lo para o tipo enum no Rust, já que poderiam existir diferentes enums no banco de dados, e o SQLX não teria como saber qual é o tipo correto para cada enum.&lt;/p&gt;
&lt;p&gt;Além disso, observe que o description não é definido como NOT NULL no banco de dados, o que significa que pode ser nulo. Isso é importante para garantir que o Rust também possa lidar com valores nulos. Para isso, podemos usar Option&lt;String&gt; para o campo description. Assim o Rust irá automaticamente converter o valor nulo do banco de dados para None em Rust.&lt;/p&gt;
&lt;p&gt;Vamos adicionar alguns produtos para realizar testes:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;sql&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;INSERT INTO&lt;/span&gt;&lt;span&gt; products (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;name&lt;/span&gt;&lt;span&gt;, price, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;description&lt;/span&gt;&lt;span&gt;, kind)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;VALUES&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Product A&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1000&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Description for Product A&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;digital&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;       (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Product B&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1900&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Description for Product B&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;digital&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;       (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Product C&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;2900&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Description for Product C&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;digital&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;INSERT INTO&lt;/span&gt;&lt;span&gt; products (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;name&lt;/span&gt;&lt;span&gt;, price, kind)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;VALUES&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Product D&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;3900&lt;/span&gt;&lt;span&gt;, &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;physical&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Vamos escrever a query para obter todos os produtos cadastrados:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;let&lt;/span&gt;&lt;span&gt; result&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;query_as!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    Product&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    r&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        SELECT&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            id,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            name,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            price,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            description,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            kind as &amp;quot;kind: ProductKind&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        FROM products&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;#&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;fetch_all&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;conn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;println!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;:#?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; result&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Observe dois pontos importantes, o primeiro é que definimos cada campo da tabela explicitamente em vez de usar o *, além disso, quando vamos definir o campo kind precisamos especificar para o compilador para qual tipo do Rust aquele campo deverá ser parseado, para isso usamos kind as &quot;kind: ProductKind&quot;.&lt;/p&gt;
&lt;p&gt;Algo para se observar é que isso só é necessário devido ao fato de estarmos usando Enuns do Postgres em vez de uma tabela com o mesmo propósito, o lado positivo de usar a tabela seria a maior flexibilidade, mas em compensação teríamos que implementar a deserialização da tabela para a Enum manualmente.&lt;/p&gt;
&lt;p&gt;Agora rodando nosso código teremos:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@pop-os ~/P/safe-queries-with-sqlx &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;master&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; cargo&lt;/span&gt;&lt;span&gt; run&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Finished&lt;/span&gt;&lt;span&gt; `dev` profile [unoptimized + debuginfo] target&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt; 0.08s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;     Running&lt;/span&gt;&lt;span&gt; `target/debug/sqlx-test`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Product&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        id&lt;/span&gt;&lt;span&gt;: 880b92bc-1169-4188-9c2c-9b31af4e3f2d,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        name&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Product A&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        price&lt;/span&gt;&lt;span&gt;: 10,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        description&lt;/span&gt;&lt;span&gt;: Some&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Description for Product A&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;        )&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        kind&lt;/span&gt;&lt;span&gt;: Digital,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Product&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        id&lt;/span&gt;&lt;span&gt;: 99ddad48-afb2-417c-9bc9-94415e17cba9,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        name&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Product B&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        price&lt;/span&gt;&lt;span&gt;: 19,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        description&lt;/span&gt;&lt;span&gt;: Some&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Description for Product B&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;        )&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        kind&lt;/span&gt;&lt;span&gt;: Digital,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Product&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        id&lt;/span&gt;&lt;span&gt;: 8fe9aba2-41cc-4079-87b7-addbdc129452,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        name&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Product C&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        price&lt;/span&gt;&lt;span&gt;: 29,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        description&lt;/span&gt;&lt;span&gt;: Some&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Description for Product C&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;        )&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        kind&lt;/span&gt;&lt;span&gt;: Digital,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Product&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        id&lt;/span&gt;&lt;span&gt;: b2630a43-74b5-4aac-9c59-e3b58b161d9c,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        name&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Product D&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        price&lt;/span&gt;&lt;span&gt;: 39,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        description&lt;/span&gt;&lt;span&gt;: None,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        kind&lt;/span&gt;&lt;span&gt;: Physical,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Agora que entendemos como cadastrar produtos, vamos criar pedidos como uma tabela de junção entre produtos e clientes.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;sql&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;CREATE&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; TABLE&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; orders&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    id UUID &lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;PRIMARY KEY&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; DEFAULT&lt;/span&gt;&lt;span&gt; gen_random_uuid&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    customer_id UUID &lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; REFERENCES&lt;/span&gt;&lt;span&gt; users(id),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    product_id UUID &lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;NOT NULL&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; REFERENCES&lt;/span&gt;&lt;span&gt; products(id),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    quantity &lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;INTEGER&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; CHECK&lt;/span&gt;&lt;span&gt; (quantity &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0&lt;/span&gt;&lt;span&gt;),&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    created_at &lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;TIMESTAMP&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;TZ&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; NOT NULL&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; DEFAULT&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; NOW&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;);&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Para representar o TIMESTAMPTZ precisamos adicionar a crate chrono e a feature chrono no sqlx.&lt;/p&gt;
&lt;p&gt;Nosso Cargo.toml ficaria assim:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;dependencies&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;chrono&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;0.4.42&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;span&gt; version&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;0.8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; features&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;runtime-tokio&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;postgres&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;uuid&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;bigdecimal&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;chrono&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;tokio&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;span&gt; version&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;1.48.0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; features&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; [&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;full&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; }&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A definição da struct Order ficaria assim:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; chrono&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;DateTime&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Utc&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;derive&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Debug&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Order&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    id&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Uuid&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    customer_id&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Uuid&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    product_id&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Uuid&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    quantity&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; i64&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    created_at&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; DateTime&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Utc&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;E as queries ficariam assim:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;let&lt;/span&gt;&lt;span&gt; user&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;query_as!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    User&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    r&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        SELECT&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        FROM users&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;#&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;fetch_one&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;conn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;let&lt;/span&gt;&lt;span&gt; product&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;query_as!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    Product&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    r&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        SELECT&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            id,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            name,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            price,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            description,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            kind as &amp;quot;kind: ProductKind&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        FROM products&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;#&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;fetch_one&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;conn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;let&lt;/span&gt;&lt;span&gt; order&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;query_as!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    Order&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    r&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        INSERT INTO orders (customer_id, product_id, quantity)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        VALUES ($1, $2, $3)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        RETURNING *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    user&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt;id&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    product&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt;id&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;    1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;fetch_one&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;conn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;println!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;:#?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; order&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ao rodar esse código obtemos o seguinte resultado:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@pop-os ~/P/safe-queries-with-sqlx &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;master&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; cargo&lt;/span&gt;&lt;span&gt; run&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Finished&lt;/span&gt;&lt;span&gt; `dev` profile [unoptimized + debuginfo] target&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt; 0.08s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;     Running&lt;/span&gt;&lt;span&gt; `target/debug/sqlx-test`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Order&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        id&lt;/span&gt;&lt;span&gt;: d6464223-d944-4773-855a-7c4fe8473447,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        customer_id&lt;/span&gt;&lt;span&gt;: 7dd46953-5af1-472c-bffd-d0fd00d1ca4b,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        product_id&lt;/span&gt;&lt;span&gt;: 395a8877-eee5-4f93-91f4-f070fd22cb75,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        quantity&lt;/span&gt;&lt;span&gt;: 1,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        created_at&lt;/span&gt;&lt;span&gt;: 2025-12-24T18:33:42.738837Z,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Agora vamos tentar obter todos os produtos comprados por um usuário.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;let&lt;/span&gt;&lt;span&gt; user&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;query_as!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    User&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    r&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        SELECT&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            *&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        FROM users&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;#&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;fetch_one&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;conn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;println!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;user: &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;:#?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; user&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;let&lt;/span&gt;&lt;span&gt; products&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;query_as!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    Product&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    r&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        SELECT&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            p.id,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            p.name,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            p.price,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            p.description,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            p.kind as &amp;quot;kind: ProductKind&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        FROM products p&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        JOIN orders o&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        ON o.product_id = p.id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        WHERE o.customer_id = $1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    user&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt;id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;fetch_all&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;conn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;println!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;:#?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; products&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;O resultado desse código é o seguinte:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@pop-os ~/P/safe-queries-with-sqlx &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;master&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; cargo&lt;/span&gt;&lt;span&gt; run&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   Compiling&lt;/span&gt;&lt;span&gt; sqlx-test v0.1.0 &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;/home/lucasbrt/Projects/safe-queries-with-sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Finished&lt;/span&gt;&lt;span&gt; `dev` profile [unoptimized + debuginfo] target&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt; 0.65s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;     Running&lt;/span&gt;&lt;span&gt; `target/debug/sqlx-test`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;user&lt;/span&gt;&lt;span&gt;: User {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    id&lt;/span&gt;&lt;span&gt;: 7dd46953-5af1-472c-bffd-d0fd00d1ca4b,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    name&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;jhon&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    age&lt;/span&gt;&lt;span&gt;: 20,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;[&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Product&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        id&lt;/span&gt;&lt;span&gt;: 395a8877-eee5-4f93-91f4-f070fd22cb75,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        name&lt;/span&gt;&lt;span&gt;: &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Product A&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        price&lt;/span&gt;&lt;span&gt;: 10,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        description&lt;/span&gt;&lt;span&gt;: Some&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Description for Product A&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;        )&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        kind&lt;/span&gt;&lt;span&gt;: Digital,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    },&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h3 id=&quot;modelos-para-obter-dados-nao-tabelares&quot;&gt;Modelos Para Obter Dados Não Tabelares&lt;a class=&quot;anchor&quot; href=&quot;#modelos-para-obter-dados-nao-tabelares&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Por vezes precisaremos criar Models para representar dados que não são necessariamente tabelas do banco, por exemplo, se quisermos o nome e a quantidade de pedidos de um determinado usuário usando como base seu ID, precisaremos seguir o seguinte procedimento:&lt;/p&gt;
&lt;p&gt;Definiremos a strut para mapear o resultado.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;derive&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Debug&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; ProductCount&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    name&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; String&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    count&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; i64&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Agora escrevemos a query finalmente.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;let&lt;/span&gt;&lt;span&gt; user_product_count&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;query_as!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    ProductCount&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    r&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        SELECT u.name, COUNT(o.id) AS count&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        FROM users u&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        LEFT JOIN orders o&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        ON o.customer_id = u.id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        GROUP BY u.name&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;fetch_all&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;conn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;println!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;user_product_count: &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;:#?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; user_product_count&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Tudo parece fazer sentido, certo? Bem, temos um pequeno problema, apesar de um COUNT nunca retornar NULL, a inferência do tipo não consegue inferir o tipo de &lt;code&gt;count&lt;/code&gt; como &lt;code&gt;i64&lt;/code&gt;, então precisamos especificar o tipo manualmente, definindo o tipo de &lt;code&gt;count&lt;/code&gt; como &lt;code&gt;Option&amp;lt;i64&amp;gt;&lt;/code&gt; na struct &lt;code&gt;ProductCount&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Caso não realizemos essa alteração o compilador irá informar o seguinte erro:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@pop-os ~/P/safe-queries-with-sqlx &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;master&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; cargo&lt;/span&gt;&lt;span&gt; run&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   Compiling&lt;/span&gt;&lt;span&gt; sqlx-test v0.1.0 &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;/home/lucasbrt/Projects/safe-queries-with-sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;error[E0277]&lt;/span&gt;&lt;span&gt;: the trait bound `i64: From&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;Option&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;i64&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;` is not satisfied&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;  --&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; src/main.rs&lt;/span&gt;&lt;span&gt;:52:30&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;   |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;52&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;       let&lt;/span&gt;&lt;span&gt; user_product_count = sqlx::query_as!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;   |&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;  ______________________________&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;53 | &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;         ProductCount&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;54 | &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;         r&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;55 | &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;|&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;             SELECT&lt;/span&gt;&lt;span&gt; u.name, COUNT&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;o.id&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span&gt; AS count&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;...&lt;/span&gt;&lt;span&gt;  |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;60&lt;/span&gt;&lt;span&gt; | |         &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;#,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;61 | |     )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;   | |_____^ the trait `From&amp;lt;Option&amp;lt;i64&amp;gt;&amp;gt;` is not implemented for `i64`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;   |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;   = help: the following other types implement trait `From&amp;lt;T&amp;gt;`:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;             `i64` implements `From&amp;lt;bool&amp;gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;             `i64` implements `From&amp;lt;i16&amp;gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;             `i64` implements `From&amp;lt;i32&amp;gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;             `i64` implements `From&amp;lt;i8&amp;gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;             `i64` implements `From&amp;lt;u16&amp;gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;             `i64` implements `From&amp;lt;u32&amp;gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;             `i64` implements `From&amp;lt;u8&amp;gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;             `i64` implements `From&amp;lt;zerocopy::byteorder::I16&amp;lt;O&amp;gt;&amp;gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;           and 2 others&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;   = note: required for `Option&amp;lt;i64&amp;gt;` to implement `Into&amp;lt;i64&amp;gt;`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;   = note: this error originates in the macro `&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;::sqlx_macros::expand_query` which comes from the expansion of the macro `sqlx::query_as` (in Nightly builds, run with -Z macro-backtrace for more info)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;For more information about this error, try `rustc --explain E0277`.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;error: could not compile `sqlx-test` (bin &lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;sqlx-test&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;) due to 1 previous error&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Também podemos seguir outra abordagem, que seria indicar ao SQLX que aquele valor nunca seria nulo, para isso basta mudar um pouco a querie.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;let&lt;/span&gt;&lt;span&gt; user_product_count&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;query_as!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    ProductCount&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    r&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        SELECT&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            u.name,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            COUNT(o.id) AS &amp;quot;count!&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        FROM users u&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        LEFT JOIN orders o&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        ON o.customer_id = u.id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        GROUP BY u.name&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;fetch_all&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;conn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Observe que ao adicionar ! ao final do nome da coluna, estamos indicando ao SQLX que o valor nunca será nulo. Apesar de resolver o problema, eu pessoalmente não utilizo muito essa abordagem, já que em queries muito complexas pode ser difícil de manter o código legível e manter o controle sobre os valores nulos, o que pode ocasionar erros em tempo de execução.&lt;/p&gt;
&lt;p&gt;Apesar de tudo, nesse exemplo em específico é meio ridículo aumentar a complexidade do modelo só por medo de usar um ! em um count, então nessa situação é um uso aceitável e até mais produtivo.&lt;/p&gt;
&lt;p&gt;Também podemos usar o método COALESCE para tratar valores nulos:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;let&lt;/span&gt;&lt;span&gt; user_product_count&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; sqlx&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;query_as!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    ProductCount&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    r&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        SELECT&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            u.name,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;            COALESCE(COUNT(o.id), 0) AS &amp;quot;count!&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        FROM users u&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        LEFT JOIN orders o&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        ON o.customer_id = u.id&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        GROUP BY u.name&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;fetch_all&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span&gt;conn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Mas o COALESCE por sua vez adiciona um custo de performance para o banco de dados, e considerando que é algo com outras duas soluções, vamos usar essa abordagem somente quando realmente necessário.&lt;/p&gt;
&lt;h2 id=&quot;riscos-nao-cobertos-pelo-compilador&quot;&gt;Riscos não cobertos pelo compilador&lt;a class=&quot;anchor&quot; href=&quot;#riscos-nao-cobertos-pelo-compilador&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Outro problema crítico aqui é o uso de LEFT JOIN, se usássemos INNER JOIN, apenas os usuários com algum pedido apareceriam, o que tiraria o propósito de contar todos os usuários, mesmo que não tenham feito pedidos, o que é no máximo um problema de negócio, mas não é um problema de código.&lt;/p&gt;
&lt;p&gt;O problema real ocorre quando usamos um FULL JOIN, digamos que você deixou a escrita dessa querie na mão de um desenvolvedor junior que adorava usar ORM&#39;s e não sabe exatamente o que está fazendo, e para piorar você não supervisionou o código dele com atenção e acabou deixando passar um FULL JOIN.&lt;/p&gt;
&lt;p&gt;Ao usar FULL JOIN, ao contrário do que se espera, o SQLX não mostra um erro em tempo de compilação, o que parece certo, afinal, ele irá juntar todos os usuários com todos os pedidos, mas isso é considerando que o banco foi bem modelado e está seguindo boas práticas, o que sabemos que não é sempre verdade.&lt;/p&gt;
&lt;p&gt;Se considerarmos um banco de um sistema legado que esteja sendo reescrito em Rust, e que por algum motivo tenha pedidos sem usuários válidos associados — o que diga-se de passagem, não é muito incomum em sistemas legados — o SQLX irá compilar normalmente, mas em tempo de execução ele iria ocasionar um crash, afinal, ele tentaria pegar o nome de um usuário que não existe.&lt;/p&gt;
&lt;h2 id=&quot;analisando-a-experiencia&quot;&gt;Analisando a Experiência&lt;a class=&quot;anchor&quot; href=&quot;#analisando-a-experiencia&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Esse draft começou inicialmente como um artigo focado em explicar como usar o SQLX para escrever queries &quot;complexas&quot;, no meio da escrita acabei percebendo que não adiantaria nada tentar explicar isso sem garantir que o público soubesse já o mínimo da biblioteca e seus meandros em relação a escrita de queries.&lt;/p&gt;
&lt;p&gt;Curiosamente, enquanto eu me aprofundava nos fundamentos da crate para bolar exemplos, acabei me deparando com vários momentos em que eu precisava parar tudo para estudar esses pequenos detalhes chatos que com certeza iriam diminuir e muito a produtividade de um time não treinado na crate, ou pior ainda, ocasionar erros em tempo de execução caso ninguém tivesse um olhar atento.&lt;/p&gt;
&lt;p&gt;Em comparação com outros pontos do ecossistema Rust, achei interessante a ideia de vincular o compilador ao banco, apesar de não estar disponível em todos os bancos.&lt;/p&gt;
&lt;p&gt;A ideia inicial da crate parece boa, mas creio que para garantir a segurança real do código ela acaba sacrificando muitos pontos de produtividade, o que é curioso, já que escrever SQL puro por sua vez já não é lá o maior exemplo de produtividade.&lt;/p&gt;
&lt;p&gt;A parte realmente mais preocupante foi nessa parte final, em que percebi que apesar de toda essa sobrecarga cognitiva que o desenvolvedor terá que ter ao usar a crate, alguns pontos como o uso do FULL JOIN continua sendo um tópico sensível quando o ambiente não for controlado.&lt;/p&gt;
&lt;p&gt;Eu pessoalmente não faço parte da comunidade de desenvolvimento do SQLX, mas mesmo olhando como um desenvolvedor Rust inexperiente, consigo ver o quão trabalhoso seria tentar garantir a segurança de tantos pontos, incluindo o uso de FULL JOIN especificamente em um banco mal modelado que pode ter já armazenado dados inconsistentes.&lt;/p&gt;
&lt;h2 id=&quot;conclusao&quot;&gt;Conclusão&lt;a class=&quot;anchor&quot; href=&quot;#conclusao&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Creio que os últimos meses experimentando essa crate serviram como uma boa fonte de aprendizado, tanto de Rust, arquitetura e até mesmo de SQL, já que por várias vezes tive que usar funcionalidades do próprio banco para me ajudar a não ficar maluco com as gambiarras que tive que desenvolver para ganhar um pouco mais de produtividade.&lt;/p&gt;
&lt;p&gt;Infelizmente não sei se continuarei usando ela como minha alternativa primária de driver de bancos de dados, nesse momento começo a considerar se investir tempo em algo como Sea-ORM que promete ser mais produtivo e ainda por cima obriga o banco a ser modelado com a própria linguagem.&lt;/p&gt;
&lt;h2 id=&quot;recomendacoes&quot;&gt;Recomendações&lt;a class=&quot;anchor&quot; href=&quot;#recomendacoes&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Se você está começando agora, recomendo que considere usar o SQLX, pois ele irá lhe ajudar a escrever SQL de forma segura, ou pelo menos irá tentar. Caso queira subir um sistema rápido e sem saber o que está fazendo, provavelmente é melhor buscar outra linguagem ou crate para o trabalho.&lt;/p&gt;
</content>
        
    </entry>
    <entry xml:lang="pt">
        <title>Facilitando o Uso da Utoipa em Seus Projetos Rust</title>
        <published>2025-11-14T00:00:00+00:00</published>
        <updated>2025-11-14T00:00:00+00:00</updated>
        
        <author>
          <name>lucasbrt</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://lucasbrt.dev/artigos/torne-utoipa-facil/"/>
        <id>https://lucasbrt.dev/artigos/torne-utoipa-facil/</id>
        
        <content type="html" xml:base="https://lucasbrt.dev/artigos/torne-utoipa-facil/">&lt;p&gt;Rust tem se destacado como uma linguagem de alta performance e segurança, obviamente isso não fica isolado ao desenvolvimento baixo nível, graças ao seu ecossistema rico em crates, Rust também é uma ótima alternativa para desenvolvimento web.&lt;/p&gt;
&lt;p&gt;Um problema porém segue presente: a produtividade do desenvolvedor médio em Rust costuma não ser tão alta quanto em outras linguagens. Sabendo disso, a comunidade Rust tem trabalhado arduamente para criar ferramentas que melhorem essa experiência. Uma dessas ferramenta é a crate &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://crates.io/crates/utoipa&quot;&gt;Utoipa&lt;/a&gt; que permite geração automática de documentação OpenAPI para APIs web desenvolvidas em Rust, contando com integrações para os principais servidores web da linguagem, como &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/actix/actix-web&quot;&gt;Actix-web&lt;/a&gt; e &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/tokio-rs/axum&quot;&gt;Axum&lt;/a&gt;. Seu funcionamento é bem direto e simples, lembrando a implementação do swagger em outras linguagens, você só precisa anotar seus endpoints com atributos específicos e a crate se encarrega de gerar a documentação necessária.&lt;/p&gt;
&lt;p&gt;Apesar de ser simples em conceito, na prática o uso do Utoipa puro pode acabar se tornando uma dor de cabeça, especialmente em projetos maiores onde a quantidade de endpoints e modelos de dados cresce rapidamente. Manter todas essas anotações pode se tornar trabalhoso e propenso a erros.&lt;/p&gt;
&lt;p&gt;Isso devido a seu funcionamento padrão que depende que você defina manualmente o caminho para cada handler na struct que implementar a trait &lt;code&gt;OpenAPI&lt;/code&gt;, o que certamente é trabalhoso e repetitivo, como exemplo temos o seguinte trecho de código de uma API bem pequena que eu estava trabalhando recentemente:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;derive&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;utoipa&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;OpenApi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;openapi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    paths&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;auth&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;login&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;auth&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;register&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;auth&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;refresh&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;auth&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;logout&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;auth&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;me&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;auth&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;update_profile&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;auth&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;change_password&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;auth&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;delete_account&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;user&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;get_user_by_id&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;table&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;create_table&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;table&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;get_tables&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;table&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;get_table_details&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;table&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;update_table&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;table&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;delete_table&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;session&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;create_session&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;session&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;get_sessions&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;session&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;update_session&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;session&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;delete_session&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;table_request&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;create_table_request&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;table_request&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;get_sent_requests&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;table_request&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;get_received_requests&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;table_request&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;accept_request&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;table_request&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;reject_request&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;table_request&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;cancel_request&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;game_system&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;create_game_system&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;http&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;handlers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;health&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;health_check&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    )&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    modifiers&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;SecurityAddon&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    tags&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;        (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;name &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;auth&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; description &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Authentication endpoints&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;        (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;name &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;users&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; description &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;User management endpoints&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;        (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;name &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;tables&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; description &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;RPG table management endpoints&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;        (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;name &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;sessions&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; description &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Session management endpoints&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;        (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;name &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;table-requests&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; description &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Table request management endpoints&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;        (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;name &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;health&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; description &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Health check endpoints&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;        (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;name &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;game_systems&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; description &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;GameSystems endpoints&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    )&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    info&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;        title &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;JOS&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;        description &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Join Our Session (JOS) - API for managing RPG tables and sessions&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;        version &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;1.0.0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    )&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; struct&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; ApiDoc&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;considere que para cada endpoint listado ali, existe um handler correspondente anotado com os atributos do utoipa, o que torna o código repetitivo e difícil de manter.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;utoipa&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;path&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    post&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    path &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;/v1/auth/login&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    tag &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;auth&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    request_body &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; LoginRequest&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    responses&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;axum&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;debug_handler&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;async&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; login&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    State&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;auth_service&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; State&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Arc&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;dyn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; IAuthService&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Json&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;login_payload&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Json&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;LoginRequest&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Result&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;StatusCode&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Json&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;LoginResponse&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; HttpError&lt;/span&gt;&lt;span style=&quot;color: light-dark(#04A5E5, #89DCEB);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    todo!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Inicialmente eu acreditei que não havia outra forma, mesmo querendo morrer por dentro toda vez que precisava adicionar um novo endpoint, até que decidi parar e buscar alguma solução, curiosamente percebi que a maioria dos códigos que usavam &lt;code&gt;Axum&lt;/code&gt; e &lt;code&gt;Utoipa&lt;/code&gt; juntos, acabavam adotando uma abordagem parecida, onde os handlers eram organizados em módulos e submódulos, refletindo a estrutura da API, ou seja, todos acabavam tendo o mesmo problema de repetição e dificuldade de manutenção.&lt;/p&gt;
&lt;p&gt;Após muita pesquisa finalmente me deparei com a crate &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://crates.io/crates/utoipa-axum&quot;&gt;utoipa-axum&lt;/a&gt; que oferece uma proposta para essa solução. Sim, o nome é autoexplicativo, sim, eu deveria ter lido a documentação com calma e tentado entender a proposta do Utoipa antes de sair escrevendo código como um maníaco, mas o curioso é que aparentemente eu não era o único, então aqui estamos nós, já que essa crate felizmente existe, vamos entender um pouco sobre seu funcionamento. Usarei Axum como exemplo, mas pelo o que vi existe uma crate similar para todos os outros frameworks suportados pelo Utoipa.&lt;/p&gt;
&lt;p&gt;O funcionamento do Axum, como você provavelmente já sabe baseia-se em alguns componentes principais, um dos mais usados é o &lt;code&gt;Router&lt;/code&gt; que é responsável por gerenciar as rotas da aplicação, incluindo middlewares, handlers, etc.&lt;/p&gt;
&lt;p&gt;Um hello world com Axum ficaria mais ou menos assim:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; axum&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;routing&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span&gt;get&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Router&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Server&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; serve&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; tokio&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;net&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;TcpListener&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;async&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; hello&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; str&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Hello, World!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;tokio&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;async&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; main&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; app&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Router&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;route&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; get&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;hello&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; listener&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; TcpListener&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;bind&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;0.0.0.0:3000&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;unwrap&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    serve&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;listener&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; app&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;unwrap&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Basicamente, definimos um handler simples que retorna &quot;Hello, World!&quot; e o associamos a rota raiz &lt;code&gt;/&lt;/code&gt; usando o método &lt;code&gt;route&lt;/code&gt; do &lt;code&gt;Router&lt;/code&gt;, também precisamos especificar o método HTTP que será usado, nesse caso &lt;code&gt;get&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Agora, rodando esse código teremos um servidor web simples que responde com &quot;Hello, World!&quot; para requisições GET na raiz &lt;code&gt;/&lt;/code&gt;.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@nixos /t/tes &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;master&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; cargo&lt;/span&gt;&lt;span&gt; run&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Finished&lt;/span&gt;&lt;span&gt; `dev` profile [unoptimized + debuginfo] target&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt; 0.04s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;     Running&lt;/span&gt;&lt;span&gt; `target/debug/tes`&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;e podemos testar isso facilmente ao usar o &lt;code&gt;curl&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@nixos ~&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; curl&lt;/span&gt;&lt;span&gt; -X&lt;/span&gt;&lt;span&gt; GET localhost:3000&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Hello&lt;/span&gt;&lt;span&gt;, World!⏎&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Vamos usar agora adicionar Utoipa a esse exemplo simples, para isso precisamos adicionar as dependências necessárias no &lt;code&gt;Cargo.toml&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;cargo&lt;/span&gt;&lt;span&gt; add utoipa&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Após isso vamos refatorar a aplicação para incluir a documentação OpenAPI usando Utoipa:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; axum&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Router&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; routing&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span&gt;get&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; serve&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; tokio&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;net&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;TcpListener&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; utoipa&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;OpenApi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;derive&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;OpenApi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;openapi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;paths&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;endpoints&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;hello&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; ApiDoc&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;mod&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; endpoints&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    #&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;utoipa&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;path&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; path &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; async&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; hello&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; str&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Hello, World!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;tokio&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;async&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; main&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; doc&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; ApiDoc&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;openapi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; app&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; Router&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;route&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; get&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;endpoints&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span&gt;hello&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; listener&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; TcpListener&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;bind&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;0.0.0.0:3000&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;unwrap&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    println!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;OpenAPI spec: &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;:?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; doc&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt;paths&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt;paths&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;keys&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    serve&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;listener&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; app&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;unwrap&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ao rodar esse código, teremos a mesma funcionalidade de antes, mas agora com a documentação OpenAPI gerada automaticamente pelo Utoipa.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@nixos /t/tes &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;master&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; cargo&lt;/span&gt;&lt;span&gt; run&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   Compiling&lt;/span&gt;&lt;span&gt; tes v0.1.0 &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;/tmp/tes&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Finished&lt;/span&gt;&lt;span&gt; `dev` profile [unoptimized + debuginfo] target&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt; 0.70s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;     Running&lt;/span&gt;&lt;span&gt; `target/debug/tes`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;OpenAPI&lt;/span&gt;&lt;span&gt; spec: [&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Tudo funciona como esperado, mas como comentado anteriormente, definimos a rota de um endpoint manualmente tanto no &lt;code&gt;Router&lt;/code&gt; quanto na struct &lt;code&gt;ApiDoc&lt;/code&gt;, o que não resolve nosso problema de repetição e dificuldade de manutenção.&lt;/p&gt;
&lt;h2 id=&quot;detectando-rotas-automaticamente-com-utoipa-axum&quot;&gt;Detectando Rotas Automaticamente com utoipa-axum&lt;a class=&quot;anchor&quot; href=&quot;#detectando-rotas-automaticamente-com-utoipa-axum&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Para evitar essa repetição, podemos usar a crate &lt;code&gt;utoipa-axum&lt;/code&gt; que oferece uma maneira de detectar automaticamente as rotas definidas no &lt;code&gt;Router&lt;/code&gt; do Axum e gerar a documentação OpenAPI correspondente.&lt;/p&gt;
&lt;p&gt;Primeiro vamos adicionar a dependência &lt;code&gt;utoipa-axum&lt;/code&gt; ao nosso &lt;code&gt;Cargo.toml&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;cargo&lt;/span&gt;&lt;span&gt; add utoipa-axum&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;A principal mudança que faremos será abandonar o uso do &lt;code&gt;Router&lt;/code&gt; padrão do Axum e utilizar o &lt;code&gt;OpenApiRouter&lt;/code&gt;, além disso, em vez de montarmos a documentação separada da montagem da rota em si, agora a própria documentação irá definir como as rotas serão montadas.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; axum&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Router&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; serve&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; tokio&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;net&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;TcpListener&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; utoipa&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;OpenApi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; utoipa_axum&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;router&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;OpenApiRouter&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; routes&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;derive&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;OpenApi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;openapi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;paths&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;crate&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;endpoints&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;hello&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; ApiDoc&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;mod&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; endpoints&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    #&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;utoipa&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;path&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; path &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; async&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; hello&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; str&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Hello, World!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;tokio&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;async&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; main&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span&gt;app&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; doc&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Router&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; utoipa&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;openapi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;OpenApi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; OpenApiRouter&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;        .&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;routes&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;routes!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;endpoints&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span&gt;hello&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;        .&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;split_for_parts&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; listener&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; TcpListener&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;bind&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;0.0.0.0:3000&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;unwrap&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    println!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;OpenAPI spec: &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;:?&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; doc&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt;paths&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt;paths&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;keys&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    serve&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;listener&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; app&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;unwrap&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Perceba que agora estamos usando o &lt;code&gt;OpenApiRouter&lt;/code&gt; para criar o roteador, e em vez de definir as rotas manualmente, usamos o método &lt;code&gt;routes&lt;/code&gt; passando uma lista de handlers anotados com Utoipa gerado pela macro &lt;code&gt;routes!&lt;/code&gt;. O método &lt;code&gt;split_for_parts&lt;/code&gt; nos retorna tanto o &lt;code&gt;Router&lt;/code&gt; quanto a documentação OpenAPI gerada automaticamente.&lt;/p&gt;
&lt;p&gt;Rodando esse código, teremos a mesma funcionalidade de antes, mas agora sem a repetição na definição das rotas:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@nixos /t/tes &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;master&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; cargo&lt;/span&gt;&lt;span&gt; run&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;warning&lt;/span&gt;&lt;span&gt;: struct `ApiDoc` is never constructed&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; --&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; src/main.rs&lt;/span&gt;&lt;span&gt;:8:8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;8&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; |&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; struct&lt;/span&gt;&lt;span&gt; ApiDoc;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  |        &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;^&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  |&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  = note: `&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;[warn(dead_code)]` (part of `#[warn(unused)]`) on by default&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;warning&lt;/span&gt;&lt;span&gt;: `tes` &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;bin&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;tes&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span&gt; generated 1 warning&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    Finished&lt;/span&gt;&lt;span&gt; `dev` profile [unoptimized + debuginfo] target&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;s&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt; 0.05s&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;     Running&lt;/span&gt;&lt;span&gt; `target/debug/tes`&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;OpenAPI&lt;/span&gt;&lt;span&gt; spec: [&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;como pode ver, o warning avisa que não estamos usando a struct &lt;code&gt;ApiDoc&lt;/code&gt;, mas isso é esperado, já que sua única função é servir como um contêiner para os atributos do Utoipa. Isso por que o OpenApiRouter já cria sua própria struct que implementa a trait &lt;code&gt;OpenAPI&lt;/code&gt; internamente. Caso você queira documentar características específicas da API, como título, descrição, etc, você pode fazer isso definindo normalmente na sua ApiDoc e instanciando o OpenApiRouter por meio do with_openapi, como no exemplo abaixo:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;derive&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;OpenApi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;openapi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;info&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;title &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;My API&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; version &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;1.0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; description &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;An example API&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; ApiDoc&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;...&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;let&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span&gt;app&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; doc&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Router&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; utoipa&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;openapi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;OpenApi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    OpenApiRouter&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;with_openapi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;ApiDoc&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;openapi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;        .&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;routes&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;routes!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;endpoints&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span&gt;hello&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;        .&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;split_for_parts&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;...&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;gerando-o-swagger-ui-automaticamente&quot;&gt;Gerando o Swagger UI Automaticamente&lt;a class=&quot;anchor&quot; href=&quot;#gerando-o-swagger-ui-automaticamente&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Como um extra, vamos adicionar o Swagger UI para visualizar a documentação gerada de forma interativa. Para isso, precisamos adicionar mais uma dependência ao nosso &lt;code&gt;Cargo.toml&lt;/code&gt;:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;cargo&lt;/span&gt;&lt;span&gt; add utoipa-swagger-ui&lt;/span&gt;&lt;span&gt; --features&lt;/span&gt;&lt;span&gt; axum&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Agora, podemos integrar o Swagger UI ao nosso servidor Axum, para isso simplesmente adicionamos uma nova rota que serve o Swagger UI, apontando para a documentação OpenAPI gerada:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; axum&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Router&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; serve&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; tokio&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;net&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;TcpListener&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; utoipa&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;OpenApi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; utoipa_axum&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;{&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;router&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;OpenApiRouter&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; routes&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;use&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; utoipa_swagger_ui&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;SwaggerUi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;derive&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;OpenApi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;openapi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;info&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;title &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;My API&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; version &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;1.0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; description &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;An example API&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;struct&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; ApiDoc&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;mod&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; endpoints&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;    #&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;utoipa&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;path&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;get&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; path &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;/&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    pub&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; async&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; hello&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; &amp;amp;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;static&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; str&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        &amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;Hello, World!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;tokio&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;async&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; fn&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; main&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span&gt;app&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; doc&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;Router&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; utoipa&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;openapi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;OpenApi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt;        OpenApiRouter&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;with_openapi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;ApiDoc&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;openapi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;            .&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;routes&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;routes!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;endpoints&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span&gt;hello&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;            .&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;split_for_parts&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; listener&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; TcpListener&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;bind&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;0.0.0.0:3000&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;unwrap&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    let&lt;/span&gt;&lt;span&gt; app&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span&gt; app&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;merge&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;SwaggerUi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;new&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;/docs&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;url&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;/api-docs/openapi.json&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; doc&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    serve&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;listener&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; app&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;await&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;unwrap&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Agora ao rodar o servidor e acessar &lt;code&gt;http://localhost:3000/docs&lt;/code&gt;, você verá a interface do Swagger UI exibindo a documentação da sua API de forma interativa.&lt;/p&gt;
&lt;img src=&quot;/imgs/swagger-ui-axum-utoipa.png&quot; style=&quot;width: 100%;&quot;  /&gt;
&lt;h2 id=&quot;conclusao&quot;&gt;Conclusão&lt;a class=&quot;anchor&quot; href=&quot;#conclusao&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Como pode perceber, o ecossistema Rust está evoluindo rapidamente para oferecer ferramentas que melhoram a produtividade do desenvolvedor. A combinação de Axum com Utoipa e utoipa-axum é um exemplo claro disso, permitindo que você crie APIs web robustas com documentação automática de forma simples e eficiente. Espero que esse artigo tenha ajudado você a entender como facilitar o uso do Utoipa em seus projetos Rust.&lt;/p&gt;
&lt;p&gt;Caso queira dar uma olhada com calma em mais exemplos, pode encontrar mais exemplos dessa integração no meu &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/Lucas-BRT/utoipa-auto-detect-axum-routes&quot;&gt;repositório pessoal&lt;/a&gt;&lt;/p&gt;
</content>
        
    </entry>
    <entry xml:lang="pt">
        <title>Não seja alvo fácil: Como se proteger na internet</title>
        <published>2025-11-10T00:00:00+00:00</published>
        <updated>2025-11-10T00:00:00+00:00</updated>
        
        <author>
          <name>lucasbrt</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://lucasbrt.dev/artigos/nao-seja-alvo-facil/"/>
        <id>https://lucasbrt.dev/artigos/nao-seja-alvo-facil/</id>
        
        <content type="html" xml:base="https://lucasbrt.dev/artigos/nao-seja-alvo-facil/">&lt;p&gt;No dia 27/10/2025, chegou ao meu conhecimento que mais um grande vazamento de dados havia ocorrido. Sinceramente, não é algo tão incomum hoje em dia; por várias vezes vemos notícias falando de invasões e meses depois uma grande base de dados sendo vazada na deep web.&lt;/p&gt;
&lt;p&gt;Várias matérias foram feitas abordando o ocorrido, sendo publicadas tanto por portais de notícias em geral como &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://oglobo.globo.com/economia/tecnologia/noticia/2025/10/27/megavazamento-expoe-180-milhoes-de-senhas-e-e-mails-do-gmail-veja-se-seus-dados-foram-vazados-e-saiba-como-se-proteger.ghtml&quot;&gt;O Globo&lt;/a&gt;, quanto por portais focados em tecnologia como &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://olhardigital.com.br/2025/10/27/seguranca/megavazamento-expoe-180-milhoes-de-senhas-de-gmail-outlook-e-outros/&quot;&gt;Olhar Digital&lt;/a&gt; e &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://canaltech.com.br/seguranca/megavazamento-expoe-183-milhoes-de-credenciais-do-gmail-veja-o-que-fazer/&quot;&gt;CanalTech&lt;/a&gt;. Curiosamente, dentre esses — que são os primeiros a aparecer nos mecanismos de busca — apenas o CanalTech aborda o assunto com precisão. Recomendo a leitura deles para ter um conhecimento melhor do ocorrido em si.&lt;/p&gt;
&lt;p&gt;O que me chamou a atenção foi que todos pecavam em uma das principais partes, que é como se proteger desses ataques. Todos citaram o mesmo passo a passo básico que qualquer pessoa já deveria saber.&lt;/p&gt;
&lt;p&gt;Para piorar ainda mais a situação, acabei descobrindo que uma pessoa conhecida estava entre as pessoas que tiveram os dados vazados, e como desgraça nunca vem aos poucos, essa pessoa acabou sendo afetada diretamente, já que, infelizmente, alguém conseguiu usar os dados vazados para acessar a plataforma onde a pessoa mantinha seus trabalhos e acabou por deletar a conta.&lt;/p&gt;
&lt;h2 id=&quot;entendendo-como-servicos-guardam-seus-dados&quot;&gt;Entendendo como serviços guardam seus dados&lt;a class=&quot;anchor&quot; href=&quot;#entendendo-como-servicos-guardam-seus-dados&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Para entendermos como nos proteger, é importante entender como são feitas as invasões, e para isso precisamos entender o que exatamente está sendo invadido. Para visualizar melhor até onde vai a toca do coelho, vamos imaginar um fluxo normal que ocorre milhares de vezes por dia: a criação de uma conta em alguma plataforma ou site.&lt;/p&gt;
&lt;h3 id=&quot;criando-uma-conta&quot;&gt;Criando uma conta&lt;a class=&quot;anchor&quot; href=&quot;#criando-uma-conta&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Quando estiver criando uma conta, geralmente você irá se deparar com uma tela contendo um formulário. Esse, por sua vez, pedirá que você preencha um login e senha. A grande maioria das pessoas erroneamente apenas coloca sua senha padrão ou, caso seja do tipo que tem a ilusão de inteligência, coloca a senha padrão com um pouco de &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://en.wikipedia.org/wiki/Leet&quot;&gt;leetspeak&lt;/a&gt;, seja trocando um A maiúsculo por um 4, um L minúsculo por 1, etc. Infelizmente, essa crença é o equivalente tecnológico de colocar o açúcar em um pote escrito &quot;sal&quot; por acreditar que as formigas não irão tentar procurar.&lt;/p&gt;
&lt;p&gt;O importante agora é o que exatamente ocorre quando o botão de registrar-se é clicado. Por motivos de simplificar a leitura para os leitores não tão técnicos — e para facilitar minha escrita, já que quero deixar esta postagem o menos técnica que conseguir — iremos considerar que você está em uma rede segura, acessando um site autêntico e com certificado SSL e todas as outras camadas de segurança mais comuns configuradas corretamente.&lt;/p&gt;
&lt;p&gt;Quando você clica no botão de registrar-se, o que ocorre é que o seu navegador envia uma requisição para o servidor do site com as informações que você preencheu. Essa requisição irá chegar em algum endpoint do servidor, ou seja, algum ponto do código que está esperando um pacote específico contendo os dados que você preencheu. Esse endpoint será a porta de entrada de um grande fluxo lógico que &lt;strong&gt;geralmente&lt;/strong&gt; vai incluir tratamento de dados, validações, verificações de vários tipos e, então, finalmente, o armazenamento no banco de dados do servidor, para que este possa responder informando que a conta foi criada.&lt;/p&gt;
&lt;p&gt;Provavelmente você está com uma imagem mental agora de que o banco de dados deve se parecer com algo como isto:&lt;/p&gt;
&lt;div class=&quot;table-wrapper&quot; style=&quot;overflow-x: auto;&quot;&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: left&quot;&gt;nomeUsuario&lt;/th&gt;&lt;th style=&quot;text-align: left&quot;&gt;email&lt;/th&gt;&lt;th style=&quot;text-align: left&quot;&gt;senha&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;João&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;joaojoao@gmail.com&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;123JoaoJ&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;Lucas&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;lucaslucas@hotmail.com&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;PãoBelaVida999&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;Rayanne&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;rayanne@yahoo.com&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;51/88/79&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;Para sua sorte, a maioria dos serviços atualmente na internet não é idiota a esse ponto de gravar sua senha em texto aberto. Se fosse assim, obviamente qualquer um com acesso ao banco de dados poderia ver sua poderosa senha &lt;strong&gt;51/88/79&lt;/strong&gt; e sair fazendo de tudo com ela. Sabendo disso, qualquer desenvolvedor que se preze faz &lt;strong&gt;hashing&lt;/strong&gt; das senhas antes de gravá-las no banco.&lt;/p&gt;
&lt;h2 id=&quot;entendendo-hashing&quot;&gt;Entendendo Hashing&lt;a class=&quot;anchor&quot; href=&quot;#entendendo-hashing&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Hashing, por si só, já é um assunto para várias postagens. Se alguém falar que entende &lt;strong&gt;realmente&lt;/strong&gt; sobre hashing, provavelmente só está se enganando ou é secretamente formado em matemática. Eu, medíocre que sou, não iria me arriscar a aprofundar nos princípios matemáticos por trás de cada algoritmo e como ele garante a segurança, então irei tomar o caminho dos covardes e explicar com a analogia mais usada na internet.&lt;/p&gt;
&lt;p&gt;Imagine que você tem uma caixa mágica. Você pode colocar algum objeto nela e, logo após isso, ela cospe outro objeto totalmente diferente do que você colocou. Olhando para o objeto resultante você não consegue adivinhar o que foi colocado na caixa inicialmente, a menos que você tenha visto o objeto sendo colocado e esse novo objeto saindo.&lt;/p&gt;
&lt;p&gt;Provavelmente não. Minhas habilidades de escrita nesse momento tiveram uma queda vertiginosa e foram abaixo do nível normal, então vamos usar exemplos um pouco mais gráficos.&lt;/p&gt;
&lt;p&gt;Digamos que você pega um gato e o coloca dentro da caixa mágica — Não coloque gatos em caixas misteriosas, por favor. Após isso, a caixa cospe um carrinho de brinquedo. Inicialmente você não entende qual é a relação de uma coisa com a outra, então para garantir que realmente existe alguma relação você coloca outro gato, e curiosamente, outro carrinho idêntico sai do outro lado.&lt;/p&gt;
&lt;img src=&quot;/imgs/analogia-da-caixa-gato-carro.svg&quot; style=&quot;filter: invert(100%); width: 100%;&quot; alt=&quot;analogia-da-caixa&quot; /&gt;
&lt;p&gt;Logo você entende que um gato entra na caixa e um carro sai. Então, você pode estar tentado a colocar o carro de volta para conseguir seu gato, certo? Bem, aí é que mora o problema: ao colocar o carro na caixa, o que ela cospe agora é um Notebook e não seu gato.&lt;/p&gt;
&lt;p&gt;O curioso é que para qualquer um que conheça a caixa e que nunca tenha tentado colocar um gato nela, um carro ou notebook não tem nenhuma ligação com o gato, ou seja, só você sabe que existe essa relação de mão única.&lt;/p&gt;
&lt;p&gt;Nesse momento você está provavelmente se indagando onde diabos eu quero chegar com essa maldita caixa. Bem, vamos agora voltar ao tom mais realista: em vez de uma caixa mágica, imagine uma função. Essa função recebe uma entrada qualquer e retorna sempre uma String de tamanho fixo. Chamaremos essa função de função de hash.&lt;/p&gt;
&lt;img src=&quot;/imgs/analogia-da-caixa-hash-real.svg&quot; style=&quot;filter: invert(100%); width: 100%;&quot; alt=&quot;analogia-da-caixa&quot; /&gt;
&lt;p&gt;Podemos, então, usar dessa propriedade para aumentar a segurança de nossas senhas. Em vez de guardá-las diretamente, vamos primeiro passá-las por essa função e fazer o Hashing e armazenar o resultado. Assim, caso alguém tente ler as senhas do banco, ele não saberá qual foi a senha digitada pelo usuário. Para deixar um pouco mais visual, a tabela &quot;real&quot; ficaria mais parecida com algo como isto:&lt;/p&gt;
&lt;div class=&quot;table-wrapper&quot; style=&quot;overflow-x: auto;&quot;&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th style=&quot;text-align: left&quot;&gt;nomeUsuario&lt;/th&gt;&lt;th style=&quot;text-align: left&quot;&gt;email&lt;/th&gt;&lt;th style=&quot;text-align: left&quot;&gt;senha&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;João&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;joaojoao@gmail.com&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;$2a$12$UgLTWOiX3P9/9GKEegTscO3i0n.JPAUEmte2q66SGRn.pTH6lMY5q&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;Lucas&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;lucaslucas@hotmail.com&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;$2a$12$mROYNHgV0/Slsx3vDVnPQu9Q0HziXlHA6w8NhZ1/qsXjSogSPv/Ta&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;text-align: left&quot;&gt;Rayanne&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;rayanne@yahoo.com&lt;/td&gt;&lt;td style=&quot;text-align: left&quot;&gt;$2a$12$HsfLKEu/PkDchVHxL22qX.uBLC/aSvQbsdpunMyw.USw7tq9oUKFu&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;Perceba que logo após o prefixo, que serve como identificador do algoritmo usado, todo o resto do conteúdo da String é pseudoaleatório. Não tem como eu adivinhar que aquele Hash veio da senha &lt;strong&gt;PãoBelaVida999&lt;/strong&gt; apenas olhando para ele.&lt;/p&gt;
&lt;p&gt;E toda vez que o usuário for logar? Bem, o fluxo é interessante: o site apenas precisa pegar a senha que ele digitou, fazer o hashing com a mesma função e comparar se o &lt;strong&gt;Hash&lt;/strong&gt; resultante é o mesmo. Assim, mesmo sem ninguém saber diretamente sua senha, podemos tanto mantê-la segura quanto manter você acessando suas contas.&lt;/p&gt;
&lt;img src=&quot;/imgs/analogia-da-caixa-hash-real-fluxo-login.svg&quot; style=&quot;filter: invert(100%); width: 100%;&quot; alt=&quot;analogia-da-caixa&quot; /&gt;
&lt;h2 id=&quot;complicando-as-coisas&quot;&gt;Complicando as coisas&lt;a class=&quot;anchor&quot; href=&quot;#complicando-as-coisas&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Os mais espertos devem ter percebido uma falha de segurança bem gritante nessa explicação: afinal, se duas pessoas tiverem a mesma senha, o Hash delas será o mesmo. Logo, quando alguém roubar o banco de dados, só precisará ficar testando várias vezes até encontrar a senha que bate com o maior número de hashes, já que probabilisticamente é uma senha que, quando for quebrada, liberará o maior número de contas e, consequentemente, trará mais vantagens para o atacante.&lt;/p&gt;
&lt;p&gt;Para sua sorte, sua conta está salva devido ao trabalho de várias mentes inteligentes do passado. Veja bem, se o problema é que as senhas de entrada eram iguais e isso resultava em hashes iguais, os cientistas chegaram a uma solução bem curiosa: adicionar um número aleatório para deixar a entrada original um pouco mais imprevisível, o que resultaria em um hash final totalmente diferente do hash da senha original pura.&lt;/p&gt;
&lt;p&gt;Esse pequeno valorzinho aleatório gerado no momento da criação da conta é só uma pequena parte do que vai ser enviado para a função, mas mesmo assim faz total diferença. Esse valor é chamado de &lt;strong&gt;sal&lt;/strong&gt; — obviamente por ser outra coisa pequena e que faz toda diferença quando se mistura com algo e se passa por um processo. Dependendo de qual literatura estiver lendo, o termo &lt;strong&gt;seed&lt;/strong&gt;(semente) também é usado.&lt;/p&gt;
&lt;img src=&quot;/imgs/analogia-da-caixa-hash-real-salt.svg&quot; style=&quot;filter: invert(100%); width: 100%;&quot; alt=&quot;analogia-da-caixa&quot; /&gt;
&lt;p&gt;No final, também teremos uma string com o mesmo tamanho, mas dessa vez, caso dois usuários diferentes digitem a mesma senha, o hash resultante será diferente!&lt;/p&gt;
&lt;p&gt;Experimente você mesmo: digite uma senha e compare o que acontece com e sem sal para dois usuários. O SHA-256 aqui serve só para ilustrar, na prática se usam funções feitas para senhas, como bcrypt e Argon2.&lt;/p&gt;
&lt;div class=&quot;ai-example&quot;&gt;
    &lt;p class=&quot;ai-example-note&quot;&gt;
        Este exemplo interativo foi gerado com IA. O texto do artigo é meu, veja como uso IA &lt;a href=&quot;https://lucasbrt.dev/ai-manifesto/&quot;&gt;neste manifesto&lt;/a&gt;.
    &lt;/p&gt;
    &lt;div class=&quot;sim&quot; data-sim=&quot;hash&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;script src=&quot;/js/sim-hash.js&quot; defer&gt;&lt;/script&gt;
&lt;p&gt;Mas calma: se duas pessoas podem digitar a mesma senha e resultar em hashes diferentes, como poderia ser realizado o fluxo de login? Afinal, você não sabe qual sal foi adicionado à sua senha, já que ele é gerado no momento da criação da conta e fica apenas no servidor.&lt;/p&gt;
&lt;p&gt;Felizmente, &lt;strong&gt;mais uma vez&lt;/strong&gt;, já pensaram nisso. O que ocorre é que o seu sal específico também é gravado no banco. Então, quando precisamos logar, o servidor realiza o seguinte fluxo:&lt;/p&gt;
&lt;img src=&quot;/imgs/analogia-da-caixa-hash-real-fluxo-login-salt.svg&quot; style=&quot;filter: invert(100%); width: 100%;&quot; alt=&quot;analogia-da-caixa&quot; /&gt;
&lt;p&gt;Como pode ver, no momento que o servidor pega sua senha, ele irá buscar no banco de dados pelo seu sal que está salvo e usará esse mesmo sal para fazer o hash da sua senha da tentativa atual. Aí sim, finalmente, irá comparar com o hash da senha em si, que estava armazenada em parte da String do banco. A partir daí, o fluxo segue normalmente.&lt;/p&gt;
&lt;p&gt;Perceba que pouco a pouco estamos nos aprofundando mais e mais em como tudo isso funciona, e acredite, estou ocultando a maior parte do conteúdo para deixar o mais simples possível, mas se por algum motivo você quiser saber mais sobre o assunto, vale a pena dar uma olhada sobre &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://en.wikipedia.org/wiki/Hash_function&quot;&gt;funções de hash&lt;/a&gt;, além de &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://en.wikipedia.org/wiki/Bcrypt&quot;&gt;bcrypt&lt;/a&gt; que atualmente é uma das funções mais usadas no mundo web e &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://en.wikipedia.org/wiki/Argon2&quot;&gt;Argon2&lt;/a&gt; que se propõe a ser mais segura.&lt;/p&gt;
&lt;p&gt;Bem, até o momento você provavelmente está se sentindo bem seguro. Afinal, eu mostrei que várias camadas de segurança já estão implementadas em praticamente todos os lugares, então por que se preocupar em fazer algum esforço ativo para se proteger?&lt;/p&gt;
&lt;h2 id=&quot;o-elo-mais-fraco&quot;&gt;O elo mais fraco&lt;a class=&quot;anchor&quot; href=&quot;#o-elo-mais-fraco&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Se tem algo de que não se pode discordar, é que a força de uma corrente é determinada pelo seu elo mais fraco. Isso já foi dito tantas e tantas vezes que acaba que muitas pessoas não entendem seu real significado.&lt;/p&gt;
&lt;p&gt;Após ver que na parte do servidor a segurança já é um padrão (ou ao menos deveria ser), você acaba ficando relaxado, seja por comodismo, seja por achar que não tem nenhum problema sair colocando suas informações em qualquer lugar. É nesse momento que você se torna ainda mais vulnerável.&lt;/p&gt;
&lt;p&gt;Vamos supor que você está criando uma conta em um site que acaba de descobrir na internet. Você coloca seu e-mail principal, sem problemas, mas como acha que não vai usá-lo muitas vezes, acaba por usar uma senha fraca e simples de lembrar. Vamos supor que o site aceitasse o absurdo que é &quot;123456789&quot;.&lt;/p&gt;
&lt;p&gt;Veja que curioso: todas as camadas de segurança comentadas anteriormente consideram que o atacante, ou o curioso, não sabe a senha original. Então, ele teria que sair tentando, colocando qualquer coisa até algum dia, quando o universo acabasse, ele conseguir acertar a sequência de caracteres que geraria aquele Hash específico que é sua senha. Mas com uma senha como &quot;123456789&quot;, qualquer idiota poderia acessar sua conta; provavelmente seria uma das primeiras 100 coisas que alguém tentaria ao invadir sua conta.&lt;/p&gt;
&lt;p&gt;O exemplo é realmente simplório. Nesse momento, você deve estar assim como os crentes da religião do saleiro protetor de açúcar que comentei anteriormente. Você acha que será alguém tentando uma senha numérica em ordem, digitando manualmente, começando do 00000000 até o ZZZZZZZZ, passando por acentos e quaisquer outros caracteres que possam ser aceitos no campo, testando cada combinação. Mas aí é que se engana: se os cientistas que bolaram as proteções são inteligentes, os invasores não ficam para trás.&lt;/p&gt;
&lt;h2 id=&quot;como-descobrem-suas-senhas&quot;&gt;Como descobrem suas senhas&lt;a class=&quot;anchor&quot; href=&quot;#como-descobrem-suas-senhas&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Em vez de computar tudo manualmente, atacantes costumam usar GPUs e seu enorme poder de paralelizar tarefas para tentar quebrar as senhas. Então, em vez de tentar uma por vez, eles tentarão milhares ou milhões. Em vez de testar quaisquer palavras aleatórias, eles irão usar outros bancos de dados repletos de senhas já vazadas anteriormente — as temidas &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://en.wikipedia.org/wiki/Rainbow_table&quot;&gt;Rainbow Tables&lt;/a&gt;. Isso faz com que toda e qualquer combinação que você, com sua mente humana e previsível, venha a pensar já possa estar em um banco desses. Acreditar que não é apenas ser negacionista. O ideal é já supor que uma senha igual à sua já foi vazada anteriormente, principalmente se você usa a mesma senha em vários lugares. Para complicar ainda mais, às vezes eles conseguem ir ainda mais fundo; às vezes são descobertas falhas de segurança nos próprios algoritmos de criptografia.&lt;/p&gt;
&lt;p&gt;É esse o estado atual da internet que você usa, uma corrida de gato e rato entre várias pessoas tentando obter todos os seus dados e outras tentando manter tudo seguro. Toda vez que você usa uma senha fraca, você está dando mais armas ainda para o time de invasores que cedo ou tarde podem acabar obtendo seus acessos. Você pode achar que não é ninguém, que não é importante e por isso estará seguro, mas eu diria que é tão inseguro quanto. Se você fosse alguém realmente importante, você provavelmente se preocuparia com sua segurança; como não se preocupa, as chances de você ser pego só aumentam.&lt;/p&gt;
&lt;p&gt;Você ainda pode argumentar que só deixa senhas fáceis em sites que não tenham nenhum vínculo financeiro, mas mesmo assim, sua vida pode se complicar pelo simples fato de um maluco do outro lado do mundo estar entediado e querer testar se existe uma conta no Figma com o e-mail X e senha Y que vazou recentemente e acabar encontrando uma conta para fazer o que quiser. E se for sua conta de trabalho? E se tiver alguma informação confidencial? E se apenas tiver algo que você investiu muito tempo? O importante é pensar que por mais que você não seja vítima direta, há várias maneiras de ser vítima de maneira indireta.&lt;/p&gt;
&lt;h2 id=&quot;como-melhorar-sua-protecao&quot;&gt;Como melhorar sua proteção&lt;a class=&quot;anchor&quot; href=&quot;#como-melhorar-sua-protecao&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;O primeiro passo é começar a usar um &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://en.wikipedia.org/wiki/Password_manager&quot;&gt;gerenciador de senhas&lt;/a&gt;. Ele será responsável por evitar que você tenha que decorar cada senha de cabeça, além de poder gerar senhas totalmente aleatórias.&lt;/p&gt;
&lt;p&gt;Navegadores atuais como Google, Edge e Firefox já têm uma implementação inicial disso. Provavelmente, se você é minimamente preocupado ou preguiçoso, usa um deles. O fato é que esses gerenciadores embutidos no próprio navegador, por sua vez, também têm uma série de falhas de segurança, então vamos considerá-los uma boa recomendação apenas para quem estava até agora usando a mesma senha para tudo com pequenas variações.&lt;/p&gt;
&lt;p&gt;Caso já esteja usando um desses, o próximo estágio é parar de usar os integrados no navegador. Busque algum serviço dedicado para isso, pode ser &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://bitwarden.com&quot;&gt;Bitwarden&lt;/a&gt;, &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://1password.com/pt&quot;&gt;1Password&lt;/a&gt;, &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://proton.me/pass&quot;&gt;ProtonPass&lt;/a&gt;, ou qualquer outro. Esses serviços são especializados em segurança e o foco do negócio deles é proteger suas contas. Eu pessoalmente usei durante anos o Bitwarden e atualmente migrei para o ProtonPass, e está sendo uma ótima experiência.&lt;/p&gt;
&lt;p&gt;O principal é saber usar a ferramenta. Os gerenciadores dedicados irão requerer de você uma chave mestra, ou seja, uma senha principal que você usará para ter acesso a todas as senhas que estarão dentro do serviço. Se preza por sua segurança, nem pense em usar palavras ou senhas pequenas. Pense em uma frase, algo de mais de 30 caracteres, com acentos, números e tudo que tiver direito. Considere que essa será a única senha que você terá que lembrar, então é bom que ela seja o mais forte que sua memória conseguir sustentar.&lt;/p&gt;
&lt;p&gt;Outro erro é usar senhas curtas mesmo com o gerenciador. Todos esses gerenciadores te permitem selecionar o tamanho da senha gerada. Sempre escolha pelo maior valor possível; quanto maior a senha, menor será a probabilidade de colisão dela com outra senha que estará no banco, então use e abuse de senhas grandes, já que não precisará lembrar delas mesmo.&lt;/p&gt;
&lt;p&gt;Para ter uma noção de quanto o tamanho e a variedade de caracteres importam, teste abaixo. Digite uma senha (de teste!) ou gere uma aleatória e compare o tempo estimado para quebrar um hash rápido com um hash lento:&lt;/p&gt;
&lt;div class=&quot;ai-example&quot;&gt;
    &lt;p class=&quot;ai-example-note&quot;&gt;
        Este exemplo interativo foi gerado com IA. O texto do artigo é meu, veja como uso IA &lt;a href=&quot;https://lucasbrt.dev/ai-manifesto/&quot;&gt;neste manifesto&lt;/a&gt;.
    &lt;/p&gt;
    &lt;div class=&quot;sim&quot; data-sim=&quot;crack&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;script src=&quot;/js/sim-crack.js&quot; defer&gt;&lt;/script&gt;
&lt;p&gt;Aqui um ponto que até eu acho chato, mas é o ponto crucial: por favor, ative a verificação de dois fatores (2FA) em &lt;strong&gt;TODOS&lt;/strong&gt; os serviços que puder. Parece algo chato ter que ficar confirmando com seu celular toda vez que for logar em algo. Mas isso é uma camada a mais que faz toda a diferença. Se por algum motivo descobrirem a senha do seu e-mail principal e ele não tiver autenticação de dois fatores, o invasor poderá simplesmente logar, apagar o e-mail de informação de novo login antes de você perceber e ficar com acesso completo ao seu e-mail, igual a um parasita que você nem tem noção de que contraiu.&lt;/p&gt;
&lt;h3 id=&quot;extras&quot;&gt;Extras&lt;a class=&quot;anchor&quot; href=&quot;#extras&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Aqui vai uma dica extra: caso queira criar uma conta em algum serviço, mas não sabe se vai realmente precisar dele, em vez de sujar sua caixa de entrada (inbox) com e-mails idiotas e deixar seu e-mail de bobeira em mais um banco de dados pela internet, use serviços de e-mail temporário como &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://temp-mail.org/pt/&quot;&gt;TempMail&lt;/a&gt;. Nele você pode gerar de graça um e-mail temporário, então use e abuse desse site. Na data desta postagem, eles estão testando um novo serviço de &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://temp-number.org&quot;&gt;número temporário&lt;/a&gt;, então vale a pena dar uma olhada.&lt;/p&gt;
&lt;p&gt;Caso esteja realmente paranoico, pode acabar pensando: &quot;bem, quem garante que os serviços que estão guardando minhas senhas não vão ser hackeados também e aí eu perderei todas de uma vez?&quot;. Para isso, você pode hospedar seu próprio provedor pessoal de senhas. O que eu pessoalmente mais ouvi falar foi o &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://github.com/dani-garcia/vaultwarden&quot;&gt;VaultWarden&lt;/a&gt;, que serve para armazenar suas senhas do Bitwarden, mas existem alternativas para praticamente todos os provedores, vale a pena pesquisar.&lt;/p&gt;
&lt;h2 id=&quot;paranoia-vs-praticidade&quot;&gt;Paranoia Vs. Praticidade&lt;a class=&quot;anchor&quot; href=&quot;#paranoia-vs-praticidade&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Se você chegou até aqui, pode estar pensando que fui meio paranoico em certos pontos, e de certa forma, foi proposital. O importante é ter a noção de quais perigos existem e como tentar se proteger deles. Até onde você vai depende totalmente de você. Talvez você ache prático ficar só com os gerenciadores de senha do navegador sem o 2FA porque vive trocando de celular. Talvez queira ativar todas as camadas de segurança possíveis e rodar todos os seus dados em uma rede local privada protegida com 900 camadas de segurança que você pessoalmente configurou. No final, o importante é não virar piada por não ter se protegido.&lt;/p&gt;
</content>
        
    </entry>
    <entry xml:lang="pt">
        <title>Haskell: Da Loucura à Recursão</title>
        <published>2025-10-24T00:00:00+00:00</published>
        <updated>2025-10-24T00:00:00+00:00</updated>
        
        <author>
          <name>lucasbrt</name>
        </author>
        
        <link rel="alternate" type="text/html" href="https://lucasbrt.dev/artigos/haskell-da-loucura-a-recursao/"/>
        <id>https://lucasbrt.dev/artigos/haskell-da-loucura-a-recursao/</id>
        
        <content type="html" xml:base="https://lucasbrt.dev/artigos/haskell-da-loucura-a-recursao/">&lt;p&gt;Poucos assuntos na área da computação são tão confusos ao primeiro contato quanto a recursão. Você, assim como a maioria dos desenvolvedores, seguiu um trajeto bastante comum. Provavelmente, iniciou usando Python para fazer pequenos scripts e exercícios de lógica, depois se aventurou com JavaScript e a manipulação de objetos gráficos no DOM e, talvez, acabou indo para o Java com sua verbosidade e suas classes.&lt;/p&gt;
&lt;p&gt;O importante é que esse fluxo seguido por muitos com poucas variações agrega conhecimento a cada estágio. Mesmo que, aos poucos, o desenvolvedor perceba que está cada vez mais confortável em solucionar algoritmos e problemas lógicos, e mesmo que a sintaxe mude — da maneira direta e simples do Python para a verbosa e explícita do Java — algo permanece em comum entre todas elas: o paradigma &lt;em&gt;imperativo&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;A quebra dessa crescente ocorre, entretanto, no momento em que nos deparamos com o paradigma &lt;em&gt;funcional&lt;/em&gt;. Provavelmente você já se deparou com algum código semelhante a este:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; fibonacci&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);font-style: italic;&quot;&gt; num&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    //&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Caso base, fibonacci de 1 e 2 são 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span&gt;num &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; ||&lt;/span&gt;&lt;span&gt; num &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; return&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;    //&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Caso recursivo, fibonacci de N = fibonacci(N - 1) + fibonacci(N - 2)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; fibonacci&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;num &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; fibonacci&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;num &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Normalmente, decoramos essa função, entendemos a lógica básica por trás dela e seguimos em frente, confiantes de que temos a recursão como mais um item em nossa caixa de ferramentas.&lt;/p&gt;
&lt;h2 id=&quot;aprofundando-um-pouco&quot;&gt;Aprofundando um pouco&lt;a class=&quot;anchor&quot; href=&quot;#aprofundando-um-pouco&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;A função aparenta calcular Fibonacci corretamente, certo? Bem, como não podemos depender apenas de argumentos vagos, vamos fazer alguns testes.&lt;/p&gt;
&lt;p&gt;Esta é a máquina que usarei para rodar esses testes. Obviamente, ela possui potência mais que suficiente para rodar um simples cálculo de Fibonacci.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;          ▗▄▄▄&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;       ▗▄▄▄▄&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    ▄▄▄▖&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;             lucasbrt@nixos&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;          ▜███▙&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;       ▜███▙&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;  ▟███▛&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;             -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;-------------&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;           ▜███▙&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;       ▜███▙▟███▛&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;              OS:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; NixOS&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 25.11&lt;/span&gt;&lt;span&gt; (Xantusia&lt;/span&gt;&lt;span&gt;) x86_64&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;            ▜███▙&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;       ▜██████▛&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;               Host:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; R78512AI-15&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;     ▟█████████████████▙&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; ▜████▛&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;     ▟▙&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;         Kernel:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; Linux&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 6.12.52&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    ▟███████████████████▙&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; ▜███▙&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    ▟██▙&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        Uptime:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 3&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; hours,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 33&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; mins&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;           ▄▄▄▄▖&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;           ▜███▙&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;  ▟███▛&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;        Packages:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1555&lt;/span&gt;&lt;span&gt; (nix-system&lt;/span&gt;&lt;span&gt;), 28 (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;nix-user&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;          ▟███▛&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;             ▜██▛&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; ▟███▛&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;         Shell:&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; bash&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 5.3.3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;         ▟███▛&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;               ▜▛&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; ▟███▛&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;          Display&lt;/span&gt;&lt;span&gt; (BOE0AF7&lt;/span&gt;&lt;span&gt;): 1920x1080 in 15&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;, 60 Hz [Built-in]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;▟███████████▛                  ▟██████████▙    DE: COSMIC&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;▜██████████▛                  ▟███████████▛    WM: cosmic-comp (Wayland)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;      ▟███▛ ▟▙               ▟███▛             Cursor: Cosmic&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;     ▟███▛ ▟██▙             ▟███▛              Terminal: .cosmic-term-wr&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    ▟███▛  ▜███▙           ▝▀▀▀▀               CPU: AMD Ryzen 7 5700U (16) @ 4.37 GHz&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;    ▜██▛    ▜███▙ ▜██████████████████▛         GPU: AMD Lucienne [Integrated]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;     ▜▛     ▟████▙ ▜████████████████▛          Memory: 2.63 GiB / 15.00 GiB (18%)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;           ▟██████▙       ▜███▙                Swap: 0 B / 16.50 GiB (0%)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;          ▟███▛▜███▙       ▜███▙               Disk (/): 57.34 GiB / 451.15 GiB (13%) - ext4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;         ▟███▛  ▜███▙       ▜███▙              Local IP (wlo1): 192.168.0.28/24&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;         ▝▀▀▀    ▀▀▀▀▘       ▀▀▀▘              Battery (499866-3S1P): 90% [Charging, AC Connected]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;                                               Locale: en_US.UTF-8&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Usaremos o comando &lt;code&gt;time&lt;/code&gt;, que veio no shell Fish, para medir o tempo de execução do programa. Para situar os que não o conhecem, vamos usá-lo junto ao comando &lt;code&gt;sleep&lt;/code&gt; para demonstrar a exibição. O programa &lt;code&gt;sleep&lt;/code&gt;, por sua vez, espera um determinado tempo.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@nixos ~&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; time&lt;/span&gt;&lt;span&gt; sleep 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;    1.00 secs      fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time    0.73 millis  729.00 micros    0.00 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    4.35 millis  620.00 micros    3.73 millis&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ok, tudo indo conforme o planejado. O tempo de 1 segundo mostra que o programa executou em 1 segundo, excelente. O próximo passo será configurar o código C completo para testarmos de maneira mais prática. Para simplificar nossa vida, consideremos o código abaixo, que será compilado com &lt;code&gt;clang&lt;/code&gt; versão 21.1.1, sem nenhuma otimização customizada.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;include&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;stdio.h&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;include&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;stdlib.h&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; fibonacci&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);font-style: italic;&quot;&gt; num&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span&gt;num &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; ||&lt;/span&gt;&lt;span&gt; num &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; return&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; fibonacci&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;num &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; fibonacci&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;num &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; main&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);font-style: italic;&quot;&gt; argc&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; char&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);font-style: italic;&quot;&gt;argv&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;[]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span&gt;argc &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        printf&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;%i&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; fibonacci&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;atoi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;argv&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Bem, tudo configurado. Vamos rodar alguns testes. Para deixar claro, a bateria será realizada com uma sequência dos seguintes valores: 1, 10, 30 e 50.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@nixos /t/benchmark&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; clang&lt;/span&gt;&lt;span&gt; main.c &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./a.out 20 &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./a.out 30 &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./a.out 40  &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./a.out 50&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;6765&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;    1.93 millis    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time    0.00 millis    0.00 micros    0.00 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    2.05 millis  938.00 micros    1.12 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;832040&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;    4.78 millis    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time    3.38 millis  323.00 micros    3.06 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    1.46 millis  437.00 micros    1.02 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;102334155&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;  346.08 millis    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time  344.65 millis  539.00 micros  344.12 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    1.52 millis  521.00 micros    1.00 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;-298632863&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;   41.93 secs    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time   41.93 secs    0.14 millis   41.93 secs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    0.00 secs    1.21 millis    0.00 secs&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Bom, como podemos ver, existe um certo padrão: o tempo de execução para Fibonacci de 20 é basicamente irrisório; o de 30 é um salto pequeno; estranhamente, o salto para 40 já é bem significativo, mas o que realmente impressiona é o de 50. Primeiro, o resultado está obviamente errado, mas isso se deve a uma falha em nossa implementação do código em C, já que decidi usar apenas &lt;code&gt;int&lt;/code&gt; para armazenar o resultado, e o limite de overflow é significativamente baixo. Mas, além do resultado, o custo em tempo de execução é obviamente drástico, ainda mais considerando que estamos calculando um número tão pequeno.&lt;/p&gt;
&lt;p&gt;Obviamente, algo não está muito certo aqui, mas, se pararmos para analisar, é até simples de entender a fonte do problema. O problema está, obviamente, na recursão. Para cada chamada de um número N, precisamos chamar a mesma função para mais dois números: N - 1 e N - 2. Podemos desenhar esse problema como uma árvore de chamadas de funções.&lt;/p&gt;
&lt;img src=&quot;/imgs/fibonacci-3-call-tree.svg&quot; style=&quot;filter: invert(100%); width: 100%;&quot; alt=&quot;Árvore de chamada da função Fibonacci para o número 3&quot;&gt;
&lt;p&gt;Como podemos ver, a árvore de chamada de Fibonacci de 3 é relativamente pequena, o que explica a execução rápida.&lt;/p&gt;
&lt;p&gt;Mas, ao observarmos uma chamada de Fibonacci de 5, podemos notar alguns pontos curiosos:&lt;/p&gt;
&lt;img src=&quot;/imgs/fibonacci-5-call-tree.svg&quot; style=&quot;filter: invert(100%); width: 100%;&quot; alt=&quot;Árvore de chamada da função Fibonacci para o número 5&quot;&gt;
&lt;ol&gt;
&lt;li&gt;A quantidade de chamadas da função subiu de 3 para 9, um crescimento significativo, dada a pequena diferença entre os dois números iniciais.&lt;/li&gt;
&lt;li&gt;Em vários pontos, a árvore de chamada invoca a função repetidas vezes com os mesmos valores. Fibonacci de 3 é chamado duas vezes e, mesmo já sabendo o valor após a primeira iteração, o programa continua a ter de recalculá-lo, quebrando-se em mais dois galhos da árvore.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;O problema aqui está cada vez mais claro: a abordagem simples e recursiva do cálculo de Fibonacci tem um grande ponto negativo: a performance. Não só pelo processamento, mas também pelo uso de memória, já que cada chamada de função precisa ter sua própria cópia dos valores utilizados dentro do escopo, o que aumenta, e muito, a memória desperdiçada com informações duplicadas.&lt;/p&gt;
&lt;h2 id=&quot;uma-possivel-solucao&quot;&gt;Uma possível solução&lt;a class=&quot;anchor&quot; href=&quot;#uma-possivel-solucao&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Ok, agora já vimos que não é viável usar essa abordagem para calcular números grandes de Fibonacci (para ser realista, nem os pequenos). Então, o que fazer agora? Bem, podemos usar mais uma vez o paradigma &lt;em&gt;imperativo&lt;/em&gt;. Vamos ver como resolver esse problema usando-o, já que qualquer problema pode ser solucionado tanto na abordagem imperativa quanto na funcional.&lt;/p&gt;
&lt;p&gt;Aqui, pedi para o ChatGPT gerar essa função, já que eu, pessoalmente, não lembrava como implementá-la, mas, para propósitos didáticos, será o suficiente. Caso não compreenda o que está acontecendo aqui, aproveite para parar um pouco e tentar entender o algoritmo. É uma boa maneira de comparar as duas abordagens e ver que, mesmo que a troca de paradigmas tenha um custo neural até nos acostumarmos, às vezes, esse custo é menor do que ter de resolver o problema com a abordagem &quot;incorreta&quot;.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; fibonacci&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);font-style: italic;&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span&gt;n &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; return&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span&gt;n &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; return&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    int&lt;/span&gt;&lt;span&gt; a &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    int&lt;/span&gt;&lt;span&gt; b &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    int&lt;/span&gt;&lt;span&gt; temp&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;int&lt;/span&gt;&lt;span&gt; i &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;span&gt; i &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;=&lt;/span&gt;&lt;span&gt; n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;span&gt; i&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        temp &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span&gt; a &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;+&lt;/span&gt;&lt;span&gt; b&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        a &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span&gt; b&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        b &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span&gt; temp&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    return&lt;/span&gt;&lt;span&gt; b&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Bem, para ver como nos saímos com essa abordagem, vamos rodar novamente nossos testes e ver como o programa se comporta. Por falta de paciência, vamos rodar todos os testes de uma vez.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@nixos /t/benchmark&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; clang&lt;/span&gt;&lt;span&gt; main.c &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./a.out 20 &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./a.out 30 &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./a.out 40  &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./a.out 50&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;6765&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;    1.81 millis    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time    0.04 millis    0.04 millis    0.00 micros&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    1.88 millis    1.10 millis  771.00 micros&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;832040&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;    1.24 millis    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time  676.00 micros    0.00 micros  676.00 micros&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time  604.00 micros  604.00 micros    0.00 micros&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;102334155&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;    1.27 millis    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time    0.00 millis    0.00 micros    0.00 micros&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    1.32 millis  621.00 micros  699.00 micros&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;-298632863&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;    2.31 millis    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time    0.74 millis    0.00 micros  744.00 micros&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    1.68 millis  931.00 micros  744.00 micros&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Veja que curioso: mesmo considerando as pequenas variações de execução, é óbvio que a performance foi drasticamente melhorada. Mas, calma, isso tem uma implicação curiosa. Até o momento, passamos por código em C, falamos sobre recursão e paradigmas, mas o ponto principal da postagem ainda não foi abordado. Onde Haskell entra nessa história?&lt;/p&gt;
&lt;p&gt;Haskell, como já devem estar cientes, é uma linguagem funcional; logo, não existem loops explícitos, e tudo é resolvido com o uso de recursão. Então, como ela consegue ser minimamente performática?&lt;/p&gt;
&lt;h2 id=&quot;a-solucao-proposta-pelas-linguagens-funcionais&quot;&gt;A solução proposta pelas linguagens funcionais&lt;a class=&quot;anchor&quot; href=&quot;#a-solucao-proposta-pelas-linguagens-funcionais&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Curiosamente, por padrão, Haskell não otimiza milagrosamente suas recursões. Para entendermos isso, vamos primeiro compreender como seria o equivalente da primeira implementação de Fibonacci recursiva em Haskell.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;haskell&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;--&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Definimos uma função fib que, ao receber 0, retorna 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fib &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;--&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Definimos outra função fib, essa que, ao receber 1, retorna 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fib &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt;--&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);font-style: italic;&quot;&gt; Finalmente, no caso recursivo, definimos que, ao receber N, fib retorna a chamada dela mesma -1 + a chamada dela mesma -2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fib n &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span&gt; fib &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;n &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; +&lt;/span&gt;&lt;span&gt; fib &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;n &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Caso esteja curioso sobre como em Haskell podemos definir a mesma função três vezes, sinta-se à vontade para ver mais sobre um conceito chamado &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://www.haskell.org/tutorial/patterns.html&quot;&gt;pattern matching&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Executando o código acima em nossa bateria de testes, temos o seguinte resultado:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@nixos /t/benchmark&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; ghc&lt;/span&gt;&lt;span&gt; main.hs &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./main 20 &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./main 30 &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./main 40 &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./main 50&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;6765&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;    6.46 millis    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time    1.43 millis  660.00 micros    0.77 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    5.29 millis  645.00 micros    4.65 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;832040&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;  106.30 millis    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time   99.88 millis    0.00 micros   99.88 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    6.85 millis  918.00 micros    5.93 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;102334155&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;   12.16 secs    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time   12.13 secs    1.21 millis   12.13 secs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    0.06 secs    0.40 millis    0.06 secs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;12586269025&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;   25.15 mins    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time   25.11 mins    0.00 micros   25.11 mins&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    0.13 mins  801.00 micros    0.13 mins&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Como podemos notar — e meu notebook sofreu neste último teste —, o crescimento da performance segue um padrão em comum com o código em C. Isso se deve ao fato de a abordagem ser a mesma; então, tirando pequenas diferenças devido a otimizações da linguagem em si, a curva de performance tende a seguir um padrão exponencial, como anteriormente.&lt;/p&gt;
&lt;p&gt;Mas, então, como podemos solucionar esse problema? Como tornar possível o cálculo de Fibonacci ou outros cálculos recursivos sem gastar todo o processamento e a memória disponíveis na máquina?&lt;/p&gt;
&lt;p&gt;Bem, aqui vamos explorar três maneiras que podem solucionar esse problema.&lt;/p&gt;
&lt;h3 id=&quot;recursao-de-cauda-tco&quot;&gt;Recursão de Cauda (TCO)&lt;a class=&quot;anchor&quot; href=&quot;#recursao-de-cauda-tco&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Já iniciamos nossa lista com uma técnica curiosa. A ideia por trás dela é, basicamente, garantir que a última operação realizada pela função seja a chamada recursiva dela mesma.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;haskell&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;module&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; Main&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; where&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; System.Environment&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;getArgs&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;go &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0&lt;/span&gt;&lt;span&gt; a _ &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span&gt; a&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;go &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1&lt;/span&gt;&lt;span&gt; _ b &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span&gt; b&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;go k a b &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span&gt; go &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;k &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span&gt; b &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;a &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;+&lt;/span&gt;&lt;span&gt; b&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fib_tco n &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span&gt; go n &lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; ::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; IO&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;main &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    (&lt;/span&gt;&lt;span&gt;n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span&gt;_&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; &amp;lt;-&lt;/span&gt;&lt;span&gt; getArgs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    print &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt; fib_tco &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt; read &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;$&lt;/span&gt;&lt;span&gt; n&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Rodando a bateria de testes com essa nova abordagem, temos os seguintes resultados:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@nixos /t/benchmark&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; ghc&lt;/span&gt;&lt;span&gt; main_tco.hs &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./main_tco 20 &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./main_tco 30 &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./main_tco 40 &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./main_tco 50&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;6765&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;    5.05 millis    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time    1.21 millis    1.21 millis    0.00 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    4.06 millis    0.17 millis    3.89 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;832040&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;    5.81 millis    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time    2.03 millis    1.07 millis    0.96 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    3.88 millis    0.03 millis    3.86 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;102334155&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;    6.17 millis    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time    3.13 millis    1.05 millis    2.08 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    3.13 millis    0.01 millis    3.11 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;12586269025&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;    4.12 millis    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time    1.15 millis    0.00 micros    1.15 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    3.11 millis  806.00 micros    2.30 millis&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Como é possível perceber, o ganho de performance foi gritante, mas, curiosamente, o que ocorre aqui &quot;por baixo dos panos&quot; é mais um truque do compilador do que uma mudança no algoritmo em si.&lt;/p&gt;
&lt;p&gt;Como foi comentado, a última operação realizada nessa recursão é a própria chamada da função. Ao perceber isso, o compilador do Haskell (no meu caso, o GHC) identifica esse padrão e substitui a chamada recursiva por uma operação de &lt;code&gt;jump&lt;/code&gt;, o que seria equivalente a transformar todo o código recursivo acima em uma versão imperativa, assim como a otimização que fizemos em C anteriormente.&lt;/p&gt;
&lt;p&gt;Isso, além de evitar o consumo de memória descontrolado — pelo fato de não haver várias cópias da função sendo acumuladas na stack —, também evita a perda de processamento, já que, apesar de ainda termos de recalcular cada função toda vez, o programa não tem o processo de esperar a memória copiar os valores da pilha para a nova chamada.&lt;/p&gt;
&lt;h3 id=&quot;memoizacao&quot;&gt;Memoização&lt;a class=&quot;anchor&quot; href=&quot;#memoizacao&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;O termo &quot;memoização&quot; já deve ser conhecido por alguns desenvolvedores, especialmente os desenvolvedores front-end React, que adoram usar &lt;code&gt;useMemo()&lt;/code&gt; em todos os lugares, e também por desenvolvedores que participam de maratonas de programação e precisam lutar pela otimização de problemas usando &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://en.wikipedia.org/wiki/Dynamic_programming&quot;&gt;Programação Dinâmica&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Se observarmos com atenção a primeira implementação, notamos algumas chamadas repetidas. Para ser exato, Fibonacci de 3 é chamado duas vezes, Fibonacci de 2 é chamado três vezes, e Fibonacci de 1 é chamado duas vezes. Nesse exemplo, não parece muita coisa, mas já vimos que isso crescerá de maneira exponencial.&lt;/p&gt;
&lt;p&gt;A ideia por trás da memoização é, basicamente, ter alguma variável externa para armazenar as informações que já foram calculadas.&lt;/p&gt;
&lt;p&gt;Então, que tal se, em vez de gastarmos processamento realizando uma nova chamada de função, verificarmos primeiro se já realizamos aquele cálculo? Se já o realizamos, vamos simplesmente pegar o valor que já foi calculado. Se não, calculamos e armazenamos o resultado.&lt;/p&gt;
&lt;img src=&quot;/imgs/fibonacci-5-call-tree-memoization.svg&quot; style=&quot;filter: invert(100%); width: 100%;&quot; alt=&quot;Árvore de chamada da função Fibonacci para o número 5, destacando chamadas repetidas.&quot;&gt;
&lt;p&gt;Observe que em vez de recalcularmos o fib de 3 e 2 novamente na esquerda da árvore, podemos apenas usar o valor que já foi calculado previamente no galho direito, economizando tempo e chamadas repetidas de operações que já foram executadas.&lt;/p&gt;
&lt;p&gt;Mexa no &lt;code&gt;n&lt;/code&gt; abaixo e ligue a memoização para comparar a árvore de chamadas e o total de chamadas nos dois casos:&lt;/p&gt;
&lt;div class=&quot;ai-example&quot;&gt;
    &lt;p class=&quot;ai-example-note&quot;&gt;
        Este exemplo interativo foi gerado com IA. O texto do artigo é meu, veja como uso IA &lt;a href=&quot;https://lucasbrt.dev/ai-manifesto/&quot;&gt;neste manifesto&lt;/a&gt;.
    &lt;/p&gt;
    &lt;div class=&quot;sim&quot; data-sim=&quot;fibonacci&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;script src=&quot;/js/sim-fibonacci.js&quot; defer&gt;&lt;/script&gt;
&lt;p&gt;Um exemplo de código de Fibonacci usando memoização em Haskell ficaria assim:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;haskell&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;module&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; Main&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; where&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;import&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; System.Environment&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;getArgs&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fibs &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; :&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; :&lt;/span&gt;&lt;span&gt; zipWith &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;+&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span&gt; fibs &lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;tail fibs&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;fib_memo n &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span&gt; fibs &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;!!&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span&gt;fromInteger n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;main&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; ::&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);font-style: italic;&quot;&gt; IO&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;main &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; do&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    (&lt;/span&gt;&lt;span&gt;n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;:&lt;/span&gt;&lt;span&gt;_&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; &amp;lt;-&lt;/span&gt;&lt;span&gt; getArgs&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    print &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt; fib_memo &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;.&lt;/span&gt;&lt;span&gt; read &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;$&lt;/span&gt;&lt;span&gt; n&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Não entendeu nada? Tudo bem, nem eu. A sintaxe de Haskell é realmente um pouco estranha, ainda mais para quem não tem tanta prática com a linguagem. Vamos tentar mostrar um código equivalente em C mais à frente.&lt;/p&gt;
&lt;h2 id=&quot;e-as-linguagens-imperativas&quot;&gt;E as linguagens imperativas?&lt;a class=&quot;anchor&quot; href=&quot;#e-as-linguagens-imperativas&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Curiosamente, essas técnicas de otimização aplicadas em linguagens funcionais também podem ser usadas em linguagens imperativas. Vamos implementar essas otimizações em C e ver como se comportam.&lt;/p&gt;
&lt;h3 id=&quot;memoizacao-em-c&quot;&gt;Memoização em C&lt;a class=&quot;anchor&quot; href=&quot;#memoizacao-em-c&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;include&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;stdio.h&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;include&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;stdlib.h&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;define&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; MAX_GLOBAL_CACHE&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1000&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;long&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; long&lt;/span&gt;&lt;span&gt; memo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;MAX_GLOBAL_CACHE&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; init_memo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;int&lt;/span&gt;&lt;span&gt; i &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;span&gt; i &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span&gt; MAX_GLOBAL_CACHE&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;span&gt; i&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        memo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;i&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;long&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; long&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; fibonacci&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);font-style: italic;&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span&gt;n &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; ||&lt;/span&gt;&lt;span&gt; n &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; return&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span&gt;memo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; !=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; return&lt;/span&gt;&lt;span&gt; memo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    memo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; fibonacci&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;n &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; fibonacci&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;n &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    return&lt;/span&gt;&lt;span&gt; memo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; main&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);font-style: italic;&quot;&gt; argc&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; char&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);font-style: italic;&quot;&gt;argv&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;[]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span&gt;argc &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        init_memo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;        printf&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;%lld&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; fibonacci&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;atoi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;argv&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Vamos quebrar o código em partes para entendê-lo com mais precisão:&lt;/p&gt;
&lt;p&gt;Primeiro, definimos o tamanho máximo do cache que usaremos para armazenar os resultados computados:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;define&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; MAX_GLOBAL_CACHE&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1000&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Depois, definimos um array de números inteiros. Perceba que usei &lt;code&gt;long long&lt;/code&gt; em vez de &lt;code&gt;int&lt;/code&gt;, mas, nesse caso, é apenas para não ultrapassarmos o limite do valor máximo que o &lt;code&gt;int&lt;/code&gt; suporta em C, como no exemplo anterior, em que já mostramos que a performance é um problema ainda maior que a memória em si:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;long&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; long&lt;/span&gt;&lt;span&gt; memo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;MAX_GLOBAL_CACHE&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Agora, vamos inicializar esse array com o valor -1, que usaremos como uma flag para sinalizar que a posição ainda não foi calculada.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;void&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; init_memo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    for&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;int&lt;/span&gt;&lt;span&gt; i &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;span&gt; i &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span&gt; MAX_GLOBAL_CACHE&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;span&gt; i&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;++&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        memo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;i&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Agora, sim, vem o diferencial dessa abordagem:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;long&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; long&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; fibonacci&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);font-style: italic;&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span&gt;n &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; ||&lt;/span&gt;&lt;span&gt; n &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; return&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span&gt;memo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; !=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; return&lt;/span&gt;&lt;span&gt; memo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    memo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; fibonacci&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;n &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; fibonacci&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;n &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    return&lt;/span&gt;&lt;span&gt; memo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Observe que a primeira parte segue o padrão, o caso base não muda, mas logo na segunda linha temos algo diferente.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;if&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span&gt;memo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; !=&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; -&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; return&lt;/span&gt;&lt;span&gt; memo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Essa linha pode ser traduzida basicamente como: &quot;Verifique se o número N já foi calculado e está no cache; se estiver, retorne-o&quot;.&lt;/p&gt;
&lt;p&gt;Se a linha acima não retornar nada, significa que devemos calcular a função recursivamente:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;memo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; =&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; fibonacci&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;n &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; +&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; fibonacci&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;n &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 2&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Após isso, apenas retornamos o valor que foi computado:&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;return&lt;/span&gt;&lt;span&gt; memo&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span&gt;n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Com isso garantimos que ao tentarmos acessar um valor que já foi calculado, precisaremos apenas realizar um acesso à memória, e não uma nova chamada de função.&lt;/p&gt;
&lt;p&gt;Vamos ver como fica a medição de performance dessa nova abordagem em C.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@nixos /tmp&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; clang&lt;/span&gt;&lt;span&gt; main.c &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./a.out 1 &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./a.out 10 &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./a.out 30 &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./a.out 35&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;    3.71 millis    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time    0.88 millis  881.00 micros    0.00 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    2.97 millis  823.00 micros    2.15 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;55&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;    3.50 millis    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time    1.25 millis    1.25 millis    0.00 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    2.35 millis    0.33 millis    2.02 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;832040&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;    3.44 millis    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time    0.81 millis  812.00 micros    0.00 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    2.71 millis  803.00 micros    1.90 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;9227465&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;    3.43 millis    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time    1.25 millis    1.25 millis    0.00 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    2.25 millis    0.32 millis    1.93 millis&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Como podemos ver, o tempo de execução foi drasticamente melhorado, sendo praticamente equivalente à versão imperativa.&lt;/p&gt;
&lt;h3 id=&quot;recursao-de-cauda-tco-1&quot;&gt;Recursão de Cauda (TCO)&lt;a class=&quot;anchor&quot; href=&quot;#recursao-de-cauda-tco-1&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;Vamos refatorar nossa implementação inicial para implementar uma versão simples de recursão de cauda.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;include&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;stdio.h&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;#&lt;/span&gt;&lt;span style=&quot;color: light-dark(#DF8E1D, #F9E2AF);&quot;&gt;include&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt; &amp;lt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;stdlib.h&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;typedef&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; unsigned&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; long&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; long&lt;/span&gt;&lt;span&gt; ull&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;ull &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;_fib_tco_helper&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);font-style: italic;&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; ull &lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);font-style: italic;&quot;&gt;a&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; ull &lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);font-style: italic;&quot;&gt;b&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    if&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; (&lt;/span&gt;&lt;span&gt;n &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;==&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;        return&lt;/span&gt;&lt;span&gt; a&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; _fib_tco_helper&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;n &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;-&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; b&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span&gt; a &lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;+&lt;/span&gt;&lt;span&gt; b&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;ull &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;fib_tco&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);font-style: italic;&quot;&gt; n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;    return&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; _fib_tco_helper&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;n&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 0&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;ULL&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt; 1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;ULL&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; main&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;int&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);font-style: italic;&quot;&gt; argc&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; char&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; *&lt;/span&gt;&lt;span style=&quot;color: light-dark(#E64553, #EBA0AC);font-style: italic;&quot;&gt;argv&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;[]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;    printf&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;%llu&lt;/span&gt;&lt;span style=&quot;color: light-dark(#40A02B, #A6E3A1);&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;,&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt; fib_tco&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;atoi&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;(&lt;/span&gt;&lt;span&gt;argv&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;[&lt;/span&gt;&lt;span style=&quot;color: light-dark(#FE640B, #FAB387);&quot;&gt;1&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;]&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;)&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Vamos comentar brevemente sobre algumas mudanças realizadas em relação ao algoritmo original.&lt;/p&gt;
&lt;p&gt;Como sei que essa otimização irá funcionar (afinal de contas, estamos nesta parte para falar exatamente sobre isso), usarei outro valor para poder calcular números maiores.&lt;/p&gt;
&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;c&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt;typedef&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; unsigned&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; long&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; long&lt;/span&gt;&lt;span&gt; ull&lt;/span&gt;&lt;span style=&quot;color: light-dark(#7C7F93, #9399B2);&quot;&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;pre class=&quot;giallo&quot; style=&quot;color-scheme: light dark; color: light-dark(#4C4F69, #CDD6F4); background-color: light-dark(#EFF1F5, #1E1E2E);&quot; &gt;&lt;code data-lang=&quot;fish&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;lucasbrt&lt;/span&gt;&lt;span&gt;@nixos /t/benchmark&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span style=&quot;color: light-dark(#179299, #94E2D5);&quot;&gt; clang&lt;/span&gt;&lt;span&gt; main_tco.c &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./a.out 10 &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./a.out 20 &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./a.out 30  &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./a.out 40 &lt;/span&gt;&lt;span&gt;&amp;amp;&amp;amp; &lt;/span&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;time&lt;/span&gt;&lt;span&gt; ./a.out 50&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;55&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;    3.85 millis    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time    1.37 millis    1.37 millis    0.00 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    2.60 millis    0.35 millis    2.25 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;6765&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;    3.95 millis    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time    0.36 millis    0.36 millis    0.00 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    3.57 millis    1.41 millis    2.17 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;832040&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;    3.35 millis    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time    1.21 millis    0.23 millis  980.00 micros&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    2.25 millis    1.27 millis  980.00 micros&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;102334155&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;    3.65 millis    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time    0.00 millis    0.00 millis    0.00 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    3.78 millis    1.91 millis    1.87 millis&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;12586269025&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;________________________________________________________&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;Executed&lt;/span&gt;&lt;span style=&quot;color: light-dark(#8839EF, #CBA6F7);&quot;&gt; in&lt;/span&gt;&lt;span&gt;    3.37 millis    fish           external&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   usr&lt;/span&gt;&lt;span&gt; time    1.18 millis    0.22 millis  964.00 micros&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span style=&quot;color: light-dark(#1E66F5, #89B4FA);font-style: italic;&quot;&gt;   sys&lt;/span&gt;&lt;span&gt; time    2.31 millis    1.34 millis  964.00 micros&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Excelente, a performance foi drasticamente aprimorada. Agora, vamos para a questão importante.&lt;/p&gt;
&lt;h2 id=&quot;afinal-qual-abordagem-usar&quot;&gt;Afinal, qual abordagem usar?&lt;a class=&quot;anchor&quot; href=&quot;#afinal-qual-abordagem-usar&quot; aria-label=&quot;Link direto para esta seção&quot;&gt;#&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Se pararmos para analisar, todas as técnicas de otimização mostradas aqui que são aplicadas em linguagens funcionais podem (e, na maioria das vezes, devem) ser adaptadas e aplicadas em linguagens imperativas. Sabendo disso, o mais importante é usar o paradigma que lhe for mais confortável, mas com um adendo: o fato de experimentarmos diferentes paradigmas, querendo ou não, abre a mente para uma nova maneira de abordar os problemas. Isso pode acabar gerando insights bem mais produtivos para sua carreira do que apenas decorar táticas como uma lista de conteúdos e seguir para o próximo. Sabendo disso, caso nunca tenha experimentado Haskell, experimente &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://en.wikipedia.org/wiki/Functional_programming&quot;&gt;linguagens funcionais&lt;/a&gt;. Outros conceitos dela, como imutabilidade e &lt;a rel=&quot;noopener external&quot; target=&quot;_blank&quot; href=&quot;https://en.wikipedia.org/wiki/Algebraic_data_type&quot;&gt;Tipos de Dados Algébricos&lt;/a&gt; são extremamente úteis e atualmente estão sendo implementados pouco a pouco em linguagens mais populares.&lt;/p&gt;
</content>
        
    </entry>
</feed>
