(file_path: &str, kind: &str, name: &str, line: u32)
| 14 | use sha2::{Digest, Sha256}; |
| 15 | |
| 16 | pub fn node_id(file_path: &str, kind: &str, name: &str, line: u32) -> String { |
| 17 | let mut hasher = Sha256::new(); |
| 18 | hasher.update(file_path.as_bytes()); |
| 19 | hasher.update(b":"); |
| 20 | hasher.update(kind.as_bytes()); |
| 21 | hasher.update(b":"); |
| 22 | hasher.update(name.as_bytes()); |
| 23 | hasher.update(b":"); |
| 24 | hasher.update(line.to_string().as_bytes()); |
| 25 | let digest = hasher.finalize(); |
| 26 | // 32 hex chars = first 16 bytes. |
| 27 | let mut hex = String::with_capacity(kind.len() + 1 + 32); |
| 28 | hex.push_str(kind); |
| 29 | hex.push(':'); |
| 30 | for b in &digest[..16] { |
| 31 | hex.push_str(&format!("{b:02x}")); |
| 32 | } |
| 33 | hex |
| 34 | } |
| 35 | |
| 36 | pub fn file_node_id(file_path: &str) -> String { |
| 37 | format!("file:{file_path}") |
no test coverage detected