rust: add a ObjectID struct
We'd like to be able to write some Rust code that can work with object IDs. Add a structure here that's identical to struct object_id in C, for easy use in sharing across the FFI boundary. We will use this structure in several places in hot paths, such as index-pack or pack-objects when converting between algorithms, so prioritize efficient interchange over a more idiomatic Rust approach. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Feb 7, 2026 at 20:04 UTC
b674d1036a3a82aaccfd5586007006f1f08648ef
4 files changed
+24
Makefile
+1
@@ -1545,6 +1545,7 @@ CLAR_TEST_OBJS += $(UNIT_TEST_DIR)/unit-test.o
1545
1546
UNIT_TEST_OBJS += $(UNIT_TEST_DIR)/test-lib.o
1547
1548
+RUST_SOURCES += src/hash.rs
1549
RUST_SOURCES += src/lib.rs
1550
RUST_SOURCES += src/varint.rs
1551
src/hash.rs
new
+21
@@ -0,0 +1,21 @@
1
+// This program is free software; you can redistribute it and/or modify
2
+// it under the terms of the GNU General Public License as published by
3
+// the Free Software Foundation: version 2 of the License, dated June 1991.
4
+//
5
+// This program is distributed in the hope that it will be useful,
6
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
7
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8
+// GNU General Public License for more details.
9
+//
10
+// You should have received a copy of the GNU General Public License along
11
+// with this program; if not, see <https://www.gnu.org/licenses/>.
12
+
13
+pub const GIT_MAX_RAWSZ: usize = 32;
14
+
15
+/// A binary object ID.
16
+#[repr(C)]
17
+#[derive(Debug, Clone, Ord, PartialOrd, Eq, PartialEq)]
18
+pub struct ObjectID {
19
+ pub hash: [u8; GIT_MAX_RAWSZ],
20
+ pub algo: u32,
21
+}
src/lib.rs
+1
@@ -1 +1,2 @@
1
+pub mod hash;
2
pub mod varint;
src/meson.build
+1
@@ -1,4 +1,5 @@
1
libgit_rs_sources = [
2
+ 'hash.rs',
3
'lib.rs',
4
'varint.rs',
5
]