cannot borrow as mutable, as it is behind a `&` reference

Here is a more idiomatic implementation for File: impl File { fn row(&self, index: usize) -> Option<&Row> { self.rows.get(index) } fn row_mut(&mut self, index: usize) -> Option<&mut Row> { self.rows.get_mut(index) } } Items of note here: Your implementation would panic if index is out of bounds. The idiomatic way of handling this is to return … Read more

How to make a default subcommand with clap and derive

Based on the official clap documentation. Modified by wrapping the Subcommand in Option, which makes it optional: use clap::{Parser, Subcommand}; #[derive(Parser)] #[command(author, version, about, long_about = None)] #[command(propagate_version = true)] struct Cli { #[command(subcommand)] command: Option<Commands>, } #[derive(Subcommand)] enum Commands { /// Adds files to myapp Add { name: Option<String> }, } fn main() { … Read more

rustup gives command not found error with zsh even after installing with brew

I used the following steps to install Rust on MacOS: Install Rust using: curl –proto ‘=https’ –tlsv1.2 -sSf https://sh.rustup.rs | sh Make sure that you customize the installation and answer No when it asks to modify the Path. Once successfully done, then add the Path variable to .zshrc using: To open .zshrc use nano ~/.zshrc … Read more

Rust use vs mod?

Consider you have a module my_mod with a pub function my_func. You can’t use this function in your crate (or outside your crate) until you include your module using mod my_mod statement. After you include your module, you can use your function like that: mod my_mod; … my_mod::my_func(…) … You can’t use my_mod::my_func statement if … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)