I made a program using Macroquad, then I built it in release mode, the binary was 63 MiB in size.
So I used cargo vendor to have a better look at Macroquad and one of its dependencies, glam.
I then started to delete code, like, lots and lots of code(about 30_000 lines of code); none of it affected my main project, some of it became 'dead_code' just by removing the pub keyword.
The result is that my project was unaffected and the binary went down to 52 MiB.
Is there a way to automate removal of unneeded elements from dependencies? This is potentially huge.
I've been coming back to the same project a few times. It's essentially just a program that interacts with an API. Only problem is whenever I get back to it, I realize how annoying it is to debug through all the "too many requests" responses I get back from the API because it has a max of 200 requests per second.
On solution would be to filter out those responses but that just feels like the wrong move, so I'm guessing the better solution would be to put some sort of rate limiter on my program. My two questions are: does that seem like a good solution and if it is, do I embed the rate limiter in my program, i.e. using the ratelimit crate or would a better solution be to run my program in a container and connect it to a reverse proxy(I think) container and control rate limiting from there?
TLDR: I think that the primary benefit of async/await is that it lets us concisely express complex concurrency; any (potential) performance improvements are just a second-order effect. We should thus judge async primarily based on how it simplifies our code, not how (or if) it makes the code faster.
What I learned about Rust while making pastebin in Rust
First iteration
Hello, I have recently started to make a pastebin to learn more about Rust and understand the underlying concept of Rust so I first made a very naive pastebin where I used axum to serve the files and used a TCPListener to handle file upload. I didn't use axum to handle file upload because I didn't know how to do it, so basically my program was listening to two different port 8080 and 3000 where on port 3000 I served the files and on 8080 I handle file upload using simple TCP connection. I also used a static variable to name the uploaded file, but in Rust mutable static variable considered unsafe since it could lead to race condition, but at that time I didn't know much about Atomic variables so I wraped the code with unsafe.
Second iteration
I uploaded my code of First iteration to Lemmy, and people on Lemmy gave me a lot of suggestions, like using Atomic variable to eliminate the need of unsafe block an
Hello, last time I shared my dirty code of pastebin and people suggested me a lot of things so I have implemented those. now the code is reduced to only 42 lines of code :D
I added this language to my watch list some time ago and forgot about it, until I got a notification about a new release (0.15) yesterday.
I'm someone who is familiar with system languages (C, Rust) and shell languages (Bash, Zsh, ..). But don't have much experience, at a proficient level, with any languages setting in between.
So I gave Koto's language guide a read, and found it to be very well-written, and the premise of the language in general to be interesting. I only got annoyed near the end when I got to @base, because I'm an anti-OOP diehard 😉
I hope this one well start to enjoy some adoption.
I was making a pastebin in Rust which I shared to the Rust community but there was one person who asked "why didn't you use upload functionality of axum" (I implemented the upload functionality using by simply using TCP connection). now I think that it might be a good idea to have file upload using axum but I couldn't find how to do it in their documentation. could someone point me to the right direction please? :)
the code I have written isn't very idiomatic or efficient. I am still new to Rust so I am learning things. I am amazed that I can write a pastebin in just 60 lines of Rust code. It's awesome. I am thinking about deploying it on my server.
any suggestions would be appreciated :)
code:
undefined
use axum::{extract::Path, routing::get, Router};
use std::fs::{read_to_string, File};
use std::io::prelude::*;
use std::net::{TcpListener, TcpStream};
use std::str;
const MAX_FILE_SIZE: usize = 1024 * 1024 * 10;
static mut FILE_COUNT: usize = 0;
fn handle_client(stream: &mut TcpStream) -> std::io::Result<()> {
let mut buf = vec![0; 1024];
unsafe {
let file_name = FILE_COUNT.to_string();
FILE_COUNT += 1;
let mut file = File::create(file_name)?;
let mut size: usize = 0;
loop {
let read_data = stream.read(&mut buf).unwrap();
size += read_data;
if size >= MAX_FILE_SIZE {
return Ok(())
}
They wrote that they were using a lot of unsafe Rust and it was getting in their way. They also mentioned that Zig had “more tools for working in a memory-unsafe environment, such as reporting memory leaks in tests”, making the overall process much better.
So is Zig a better alternative to writing unsafe Rust?
I wanted to test this myself and see how hard unsafe Rust would be by building a project that required a substantial amount of unsafe code.
Then I would re-write the project in Zig to see if would be easier/better.
After I finished both versions, I found that the Zig implementation wa
some time ago I shared a Guess game that I made from scratch and this time I thought to do something different so I decided to make a Guess game over IRC.
It's pretty basic but I learned a lot about destructing Enum, unwrap and if let syntax.
I would appreciate any suggestion :)
here is the source code:
undefined
use futures::prelude::*;
use irc::client::prelude::*;
use rand::Rng;
#[tokio::main]
async fn main() -> irc::error::Result<()> {
let config = Config {
nickname: Some("beep_boop".to_owned()),
server: Some("irc.libera.chat".to_owned()),
channels: vec!["#test".to_owned()],
..Default::default()
};
let mut client = Client::from_config(config).await?;
client.identify()?;
let mut stream = client.stream()?;
let mut secret_number = rand::thread_rng().gen_range(0..101);
let mut attempts = 0;
while let Some(message) = stream.next().await.transpose()? {
print!("{}", message);
match message.command {
I learned about struct in Rust, so I just wanted to share what I have learned.
what is struct in Rust? It's the same as what's in C language. eg,
undefined
struct Point {
x: i32,
y: i32,
}
that's it this is how we define a struct. we can create all sort of struct with different data types. ( here I have used only i32 but you can use any data type you want)
now Rust also have which we find in OOPs languages like Java. it's called method. here is how we can define methods for a specific struct in Rust.