• úvod
  • témata
  • události
  • tržiště
  • diskuze
  • nástěnka
  • přihlásit
    registrace
    ztracené heslo?
    SPIRALIRust - Programovací jazyk

    A language empowering everyone to build reliable and efficient software.

    The Rust Programming Language - The Rust Programming Language
    The book of Rust
    Idiomatic rust
    GitHub - usagi/rust-memory-container-cs: Rust Memory Container Cheat-sheet
    Memory container cheat sheet
    rozbalit záhlaví
    LYCO
    LYCO --- ---
    Jinak takhle od boku:
    - ta chybová hláška se vůbec netýká lifetimů, někde jsi zapomněl zavolat connect() nebo tak něco
    - když nejde nějaká hodnota klonovat, tak ji buď musíš uložit někam kde bude žít dost dlouho (tady asi na heap, v boxu) nebo si ji předávat. Co takhle ji uložit do enumu RequestState, do příslušných variant?
    - Async funkce je sama o sobě stavový stroj a tokio ti ho bude posouvat, potřebuješ vážně implementovat vlastní stavový stroj k tomu všemu? Nemohl bys napsat async funkci která si svůj stav uloží do lokálních proměnných a ten stavový stroj zapsat kódem (nejspíš jako sekvenci cyklů), a pak to jen předat tokiu jako task? Kompilátor pak za tebe vyřeší většinu problémů s lifetimy...
    LYCO
    LYCO --- ---
    VELDRANE: řekni nám ještě, který řádek je ten /root/Bitbucket/krb5proxy/src/proxy.rs:232:84 a co je zač on_upgrade a ctx (kde se vezmou, jaký mají lifetime...)
    VELDRANE
    VELDRANE --- ---
    jo jeste doplnim ze cele to pada na:

    thread 'tokio-runtime-worker' panicked at /root/Bitbucket/krb5proxy/src/proxy.rs:232:84:
    called `Result::unwrap()` on an `Err` value: Os { code: 107, kind: NotConnected, message: "Transport endpoint is not connected" }

    coz je radek v tom handleru:

    tokio::io::copy_bidirectional(&mut client_io, &mut proxy_stream).await.unwrap();
    VELDRANE
    VELDRANE --- ---
    Ahoj, mam takovej vypecenej problem. Pisu https_proxy s podporou kerbera nad hyperem, v zakladu mi to nejak fungovalo i rozhod sem se prepsat to state machine a tady sem narazil. Mam problem ze kdyz vyhodnotim connect, musim upgradovat spojeni, ale to mi neprezije context. Kod vypada nejak takhle:

    
    pub struct RequestContext {
    .
        pub proxy_stream: Option<tokio::net::TcpStream>,
    }
    
    impl RequestState {
    
    pub async fn next(self, ctx: &mut RequestContext) -> RequestState {
        match self {
    .
            RequestState::ConnectingToProxy => ctx.handle_connecting_to_proxy().await,
            RequestState::Tunelling => ctx.handle_tunelling().await,
    .
            }
        }
    }
    
        pub async fn handle_tunelling(&mut self) -> RequestState {
            let mut proxy_stream = self.proxy_stream.as_mut().unwrap(); // nemuzu udelat take protoze pak uz nemam ten stream nejspis:
    
            let proxy_string = self.ap_req.as_ref().unwrap();
            let host = self.original_request.as_ref().unwrap().uri().host().unwrap_or("localhost");
    
            let connect_req = format!(
                "CONNECT {} HTTP/1.1\r\nHost: {}\r\nProxy-Authorization: {}\r\n\r\n",
                self.original_request.as_ref().unwrap().uri(), host, proxy_string
            );
    
            tokio::task::spawn(async move {
                let upgraded_client = on_upgrade.await.unwrap();
                let mut client_io = TokioIo::new(upgraded_client);  
                tokio::io::copy_bidirectional(&mut client_io, &mut proxy_stream).await.unwrap();
            });
    
            self.original_response = Some(resp_to_client.map(|b| b.boxed()));
            return RequestState::Closing;
        }
    

    a jeste main a state machine:

    async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
    .
            tokio::task::spawn(async move {
                if let Err(err) = ServerBuilder::new()
                    .preserve_header_case(true)
                    .title_case_headers(true)
                    .serve_connection(io, service_fn(request_machine))
                    .with_upgrades()
                    .await
                {
                    println!("Failed to serve connection: {:?}", err);
                }
            });
        }
    }
    async fn request_machine(req: Request<hyper::body::Incoming>) -> Result<Response<BoxBody<Bytes, hyper::Error>>, hyper::Error> {
    
        let mut state = RequestState::WaitingForRequest;
        let mut context = RequestContext::new(req).await;
    
    loop {
        
        state = state.next(&mut context).await;
    
        if matches!(state, RequestState::Closing) {
            break; // konec práce
            }
        }
    
        println!("state: {:?}", context);
    
        let response = context.original_response.take().unwrap();
    
        Ok(response.map(|b| b.boxed()))
    }

    Proste sem se zasek na tom ze netusim jak to udelat aby v ramci Tokia prezil tcpstream z vyssich fci te state machine. Nejde udelat clone() toho streamu. AI doporucuju try_clone ale ten vubec neexistuje. Neresil nekdy nekdo neco takovyho ? Kod je zkracenej, muzu doplnit. Jinak pokud to udelam naprasaka v ramci toho hyper handleru tak to vsechno jak vino (ale to nechci).
    MARASAN
    MARASAN --- ---
    A 2025 Survey of Rust GUI Libraries

    A 2025 Survey of Rust GUI Libraries | boringcactus
    https://www.boringcactus.com/2025/04/13/2025-survey-of-rust-gui-libraries.html
    MARASAN
    MARASAN --- ---
    nevim, esi sem nebo do C :)

    C++ creator calls for action to address 'serious attacks' • The Register
    https://www.theregister.com/2025/03/02/c_creator_calls_for_action/
    MARASAN
    MARASAN --- ---
    diziet | Rust is indeed woke
    https://diziet.dreamwidth.org/19480.html
    SPIKE411
    SPIKE411 --- ---
    Ferrous Systems Donates Ferrocene Language Specification to Rust Project - The Rust Foundation
    https://rustfoundation.org/media/ferrous-systems-donates-ferrocene-language-specification-to-rust-project/
    SPIKE411
    SPIKE411 --- ---
    MARASAN: forked from bnjbvr/rouille
    Rust programming, in French.
    MARASAN
    MARASAN --- ---
    GitHub - michidk/rost: Rust programming in German.
    https://github.com/michidk/rost
    VELDRANE
    VELDRANE --- ---
    Moc pekna prednaska na tema “jak kubernetes operator/controller v rustu sam sobe vyrobiti”

    Kubernetes Controllers in Rust: Fast, Safe, Sane - Matei David, Buoyant
    https://youtu.be/rXS-3hFYVjc?si=DFi0RwgDkWxrabMN
    MARASAN
    MARASAN --- ---
    Do not run any Cargo commands on untrusted projects | by Sergey "Shnatsel" Davidoff | Mar, 2025 | Medium
    https://shnatsel.medium.com/do-not-run-any-cargo-commands-on-untrusted-projects-4c31c89a78d6
    SPIKE411
    SPIKE411 --- ---
    C stdlib isn’t threadsafe and even safe Rust didn’t save us | EdgeDB Blog
    https://www.edgedb.com/blog/c-stdlib-isn-t-threadsafe-and-even-safe-rust-didn-t-save-us

    (Titulek je dobré tl;dr, není to nijak překvapivé, ale kdyby někoho zajímaly ty výživné detaily jednoho takového případu…)
    SPIKE411
    SPIKE411 --- ---
    Rust for C# Developers

    Why Every C# Developer Should Explore Rust – Chris Woody Woodruff
    https://woodruff.dev/why-every-c-developer-should-explore-rust/

    Exploring Programming Paradigms: C# and Rust Side by Side – Chris Woody Woodruff
    https://woodruff.dev/exploring-programming-paradigms-c-and-rust-side-by-side/

    Zatím 2 díly z 8.
    SPIKE411
    SPIKE411 --- ---
    Researchers build a bridge from C to Rust and memory safety | InfoWorld
    https://www.infoworld.com/article/3732082/researchers-build-a-bridge-from-c-to-rust-and-memory-safety.html
    KEJML
    KEJML --- ---
    Fish byl přepsán autory to Rustu. Celkem jsou spokojeni:

    Fish 4.0: The Fish Of Theseus
    https://fishshell.com/blog/rustport/
    SPIKE411
    SPIKE411 --- ---
    Making Unsafe Rust a Little Safer: Tools for Verifying Unsafe Code, Including Libraries in C and C++
    https://blog.colinbreck.com/making-unsafe-rust-a-little-safer-tools-for-verifying-unsafe-code/
    XCHAOS
    XCHAOS --- ---
    GitHub - RustPython/RustPython: A Python Interpreter written in Rust
    https://github.com/RustPython/RustPython
    XCHAOS
    XCHAOS --- ---
    Verify the Rust's Standard Library's 7,500 Unsafe Functions - and Win 'Financial Rewards' - Slashdot
    https://developers.slashdot.org/story/24/11/23/2327203/verify-the-rusts-standard-librarys-7500-unsafe-functions---and-win-financial-rewards
    SPIKE411
    SPIKE411 --- ---
    Rust Foundation moves forward on C++ and Rust interoperability | InfoWorld
    https://www.infoworld.com/article/3606753/rust-foundation-moves-forward-on-c-and-rust-interoperability.html
    Kliknutím sem můžete změnit nastavení reklam