初步搭建代码框架 包括objects, tests, utils

This commit is contained in:
mrbeanc
2023-12-16 18:37:29 +08:00
parent 42e80a53cf
commit e5141c159b
12 changed files with 78 additions and 0 deletions

3
src/lib.rs Normal file
View File

@@ -0,0 +1,3 @@
// 不使用lib.rs的话就无法在tests里引用到src中的模块
pub mod objects;
pub mod utils;

View File

@@ -1,3 +1,5 @@
use std::collections::HashMap;
type Index = HashMap<String, bool>;
fn main() {
println!("Hello, world!");
}

6
src/objects/blob.rs Normal file
View File

@@ -0,0 +1,6 @@
use crate::objects::object::Hash;
#[derive(Debug, Clone)]
pub struct Blob {
hash: Hash,
data: String,
}

0
src/objects/commit.rs Normal file
View File

4
src/objects/mod.rs Normal file
View File

@@ -0,0 +1,4 @@
pub mod commit;
pub mod blob;
pub mod tree;
mod object;

1
src/objects/object.rs Normal file
View File

@@ -0,0 +1 @@
pub type Hash = String;

0
src/objects/tree.rs Normal file
View File

1
src/utils/mod.rs Normal file
View File

@@ -0,0 +1 @@
pub mod util;

11
src/utils/util.rs Normal file
View File

@@ -0,0 +1,11 @@
use sha1::{
Digest,
Sha1
};
pub fn calc_hash(data: &String) -> String {
let mut hasher = Sha1::new();
hasher.update(data);
let hash = hasher.finalize();
hex::encode(hash)
}