Skip to main content

26 posts tagged with "rust"

View All Tags

Rust Generate SHA1 Hash

· One min read
forfd8960
Author

the crate

[dependencies]
sha1-checked = "0.10.0"
base16ct = { version="0.2.0", features=["alloc"] }

Generate SHA1 Hash bytes

  • build sha1 hasher with Sha1::new()
  • update the hasher with hasher.update(content)
  • call hasher.try_finalize() to get the hash
  • generate hash bytes with
let arr = hf.hash();
arr.to_vec()

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