5 ms·
How are the software libraries for Rust? What did you do for network access, string manipulation and GUI stuff?
by chocolatebunny 11y ago
How are the software libraries for Rust? What did you do for network access, string manipulation and GUI stuff?
- VeilEm 11y agoThe string manipulation is good in Rust, but in Rust strings are unicode and characters are unicode codepoints. IRC is an ASCII protocol and so I went with using binary slices `[u8]` for parsing. For network stuff I used openssl[0] and std::TcpStream [1] I didn't use a GUI. I plan on using piston.rs[2] to build games but there are Qt, GTK+ and even Cocoa integrations for rust. [0] https://crates.io/crates/openssl/ https://crates.io/crates/openssl/ [1] https://doc.rust-lang.org/std/net/struct.TcpStream.html https://doc.rust-lang.org/std/net/struct.TcpStream.html [2] http://www.piston.rs/ http://www.piston.rs/
- fpoling 11y agoYes, its a pity that Rust requires that strings must be UTF-8. Go designers got it right as their strings are just immutable sequences of bytes making them very suitable for network protocols and binary data.
- heinrich5991 11y agoThat's what Rust has byte slices for: `b"abcdef"`
- fpoling 11y agoOne cannot use string library in Rust against byte slices. For example, regexp works only against strings making it unsuitable for processing, say, log files, that may contain non-utf8 bytes.
- heinrich5991 11y agoYea, also found that limitation of the regex library pretty annoying. But conceptually this has nothing to do with string slices being different from byte slices... It might encourage it though.
- kbenson 11y agoFWIW, I think getting the underlying string representation right (and relatedly how it interacts with byte buffers/slices) is really hard. So far, I think Perl 6 probably has the most well thought out structure with regard to that, but they took a decade and a half and lots of testing to come up with what they did. Then again, how it works in Perl 6 is also a function of how the language functions, so it wouldn't be a a direct mapping of concepts, but there are some really good ideas there.
- kibwen 11y agoThis is somewhat incorrect, as Rust doesn't have a standard regex library. You're likely thinking of burntsushi's regex crate, which made its own decision to be Unicode-aware. There's no reason that someone couldn't come up with their own regex library (or fork burntsushi's, or just wrap an existing C regex library) that works as you desire.
- rjtobin 11y agoThere are wrappers for basically any C/C++ library you can think of. I found string support to be pretty great from the standard library (compared to C++), such as UTF-8 and string interpolation. In terms of networking, I threw together a working console IRC client in about 60 lines of Rust (using standard library threads and TcpStreams). And I'm very much a Rust beginner. And Rust forced me to consider error handling in a way I wouldn't have otherwise. I should also say that the community is unusually supportive: I've asked some questions on the IRC channel and got really helpful replies (and haven't noticed any of the snark that comes with a lot of IRC channels).