Skip to main content

32 posts tagged with "rust"

View All Tags

Implement Git with Rust Part0

· 5 min read
forfd8960
Author

What is Git

We use git to manage our code, and do version control.

  • generally, I use git init or git clone to start a project locally.
  • And do some work in the git repo.
  • And then use git add to add the files to the staging area.
  • And then use git commit to commit the changes to the local repository.
  • And then use git push to push the files to the remote repository.
  • And then use git pull origin master to pull the changes from the remote repository.
  • use git checkout -b <new_branch> to create and checkout to a new branch.
  • use git rebase master to rebase changes from master to the current branch.

Rust Json Parser

· 6 min read
forfd8960
Author

What is Json

What is Json

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language Standard ECMA-262 3rd Edition - December 1999.

Deduplicate elements in Vec in Rust

· One min read
forfd8960
Author

How to Deduplicate the elements in a Vector

First Version

in the first version of the deduplicate:

  • First create data_set to matain the data exists state.
  • Iter over the data and check if the specific data in idx is exists
  • If exists then skip.
  • If not exists then push the data to new result: dedup_data.

Build A Simple Cli App with Rust

· One min read
forfd8960
Author

use clap to build a cli App

So, I want to build a Cli App that convert a csv file to json, yaml, toml formated file.

And for Rust, there is crate clap was used to build cli app.

And the final command to use the cli app, is something like this:

./target/debug/rcli csv -i test.csv

Vim Practice

· 2 min read
forfd8960
Author

Delete words backward

  • delete 1 word: db
  • delete n words: d<number>b

Delete word forward

  • dw: delete one word.

Change the current word inpalce

  • cw: chagne the current word

How to Customize your Own Error Type in Rust

· 2 min read
forfd8960
Author

Suppose you are writing a lexical analyzer(Lexer), and you want return some customized errors while the lexer scan tokens, and there are 3 possibel error will happens:

  • Not Supported Tokens.
  • Invalid Strings.
  • Invalid Nums.

SO you can define the errors with a rust enum:

pub enum LexerError {
InvalidToken(char),
InvalidString(String),
InvalidNum(String),
}

Comapre Rust with Golang

· 3 min read
forfd8960
Author

I have been using golang long time to wirte backend business logic.

After writing some rust code and I want do a comparison between golang and rust. This is maybe another good way to help you learn rust.

Build A Simple Interpreter with Rust Part0

· 2 min read
forfd8960
Author

What is Interpreter

From Wikipedia:

In computer science, an interpreter is a computer program that directly executes instructions written in a programming or scripting language, without requiring them previously to have been compiled into a machine language program. An interpreter generally uses one of the following strategies for program execution:

  1. Parse the source code and perform its behavior directly;
  2. Translate source code into some efficient intermediate representation or object code and immediately execute that;
  3. Explicitly execute stored precompiled bytecode made by a compiler and matched with the interpreter Virtual Machine.