mirror of
https://github.com/MrBeanCpp/MIT.git
synced 2026-04-13 17:20:12 +08:00
初步搭建代码框架 包括objects, tests, utils
This commit is contained in:
3
src/lib.rs
Normal file
3
src/lib.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
// 不使用lib.rs的话,就无法在tests里引用到src中的模块
|
||||
pub mod objects;
|
||||
pub mod utils;
|
||||
@@ -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
6
src/objects/blob.rs
Normal 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
0
src/objects/commit.rs
Normal file
4
src/objects/mod.rs
Normal file
4
src/objects/mod.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
pub mod commit;
|
||||
pub mod blob;
|
||||
pub mod tree;
|
||||
mod object;
|
||||
1
src/objects/object.rs
Normal file
1
src/objects/object.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub type Hash = String;
|
||||
0
src/objects/tree.rs
Normal file
0
src/objects/tree.rs
Normal file
1
src/utils/mod.rs
Normal file
1
src/utils/mod.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod util;
|
||||
11
src/utils/util.rs
Normal file
11
src/utils/util.rs
Normal 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)
|
||||
}
|
||||
Reference in New Issue
Block a user