feat: function signatures #2

open
opened by freshlybakedca.ke targeting master from private/coded/push-mltmlnyrnvuk
+1
Cargo.toml
··· 8 8 crate-type = ["staticlib"] 9 9 10 10 [dependencies] 11 + libz-sys = "1.1.23"
+18 -2
nilla.nix
··· 11 11 { config, lib }: 12 12 { 13 13 config = { 14 - inputs.nixpkgs.src = pins.nixpkgs; 14 + inputs.nixpkgs = { 15 + src = pins.nixpkgs; 16 + settings.overlays = [ config.inputs.fenix.result.overlays.default ]; 17 + }; 18 + 19 + inputs.fenix.src = pins.fenix; 15 20 16 21 shells.default = { 17 22 systems = [ "x86_64-linux" ]; 18 23 19 24 shell = 20 - { mkShell, git }: 25 + { mkShell, git, fenix, bacon }: 21 26 mkShell { 22 27 inputsFrom = [ git ]; 28 + packages = [ 29 + (fenix.complete.withComponents [ 30 + "cargo" 31 + "clippy" 32 + "rust-src" 33 + "rustc" 34 + "rustfmt" 35 + "rust-analyzer" 36 + ]) 37 + bacon 38 + ]; 23 39 }; 24 40 }; 25 41 };
+13
npins/sources.json
··· 1 1 { 2 2 "pins": { 3 + "fenix": { 4 + "type": "Git", 5 + "repository": { 6 + "type": "GitHub", 7 + "owner": "nix-community", 8 + "repo": "fenix" 9 + }, 10 + "branch": "main", 11 + "submodules": false, 12 + "revision": "a563f057979806c59da53070297502eb7af22f62", 13 + "url": "https://github.com/nix-community/fenix/archive/a563f057979806c59da53070297502eb7af22f62.tar.gz", 14 + "hash": "sha256-WfItZn6duisxCxyltbu7Hs7kxzNeylgZGOwCYwHe26g=" 15 + }, 3 16 "nilla": { 4 17 "type": "GitRelease", 5 18 "repository": {
+1
src/lib.rs
··· 1 + pub mod reftable; 1 2 pub mod varint;
+64
src/reftable/basics.rs
··· 1 + #[derive(Debug, Clone)] 2 + pub struct ReftableBuf { 3 + pub data: Vec<u8>, 4 + pub len: usize, 5 + } 6 + 7 + impl ReftableBuf { 8 + pub fn new() -> Self { 9 + Self { 10 + data: Vec::new(), 11 + len: 0, 12 + } 13 + } 14 + 15 + pub fn with_capacity(capacity: usize) -> Self { 16 + Self { 17 + data: Vec::with_capacity(capacity), 18 + len: 0, 19 + } 20 + } 21 + 22 + pub fn clear(&mut self) { 23 + self.data.clear(); 24 + self.len = 0; 25 + } 26 + 27 + pub fn as_slice(&self) -> &[u8] { 28 + &self.data[..self.len] 29 + } 30 + } 31 + 32 + impl Default for ReftableBuf { 33 + fn default() -> Self { 34 + Self::new() 35 + } 36 + } 37 + 38 + pub fn binsearch<F>(sz: usize, mut f: F) -> usize 39 + where 40 + F: FnMut(usize) -> Result<bool, String>, 41 + { 42 + todo!() 43 + } 44 + 45 + pub fn names_length(names: &[&str]) -> usize { 46 + todo!() 47 + } 48 + 49 + pub fn parse_names(buf: &str) -> Result<Vec<String>, String> { 50 + todo!() 51 + } 52 + 53 + pub fn common_prefix_size(a: &ReftableBuf, b: &ReftableBuf) -> usize { 54 + todo!() 55 + } 56 + 57 + pub enum HashAlgorithm { 58 + Sha1 = 89, 59 + Sha256 = 247, 60 + } 61 + 62 + pub fn hash_size(id: HashAlgorithm) -> u32 { 63 + todo!() 64 + }
+59
src/reftable/block.rs
··· 1 + use crate::reftable::{basics::ReftableBuf, blocksource::ReftableBlockData}; 2 + use libz_sys::z_stream; 3 + 4 + pub struct BlockWriter { 5 + pub zstream: Box<z_stream>, 6 + pub compressed: Vec<u8>, 7 + 8 + pub block: Vec<u8>, 9 + pub block_size: u32, 10 + 11 + pub header_off: u32, 12 + 13 + pub restart_interval: u16, 14 + pub hash_size: u32, 15 + 16 + pub next: u32, 17 + pub restarts: Vec<u32>, 18 + pub restart_len: u32, 19 + pub restart_cap: u32, 20 + 21 + pub last_key: ReftableBuf, 22 + 23 + pub scratch: ReftableBuf, 24 + pub entries: i32, 25 + } 26 + 27 + pub struct BlockIter { 28 + pub next_off: u32, 29 + pub block: Vec<ReftableBlock>, 30 + 31 + pub last_key: ReftableBuf, 32 + pub scratch: ReftableBuf, 33 + } 34 + 35 + pub struct ReftableBlock { 36 + pub header_off: u32, 37 + 38 + pub block_data: ReftableBlockData, 39 + pub hash_size: usize, 40 + 41 + pub zstream: Box<z_stream>, 42 + pub uncompressed_data: Vec<u8>, 43 + 44 + pub restart_count: u16, 45 + pub restart_off: u32, 46 + 47 + pub full_block_size: u32, 48 + pub block_type: u8, 49 + } 50 + 51 + pub struct BlockReader { 52 + pub zstream: Box<z_stream>, 53 + pub uncompressed: Vec<u8>, 54 + pub uncompressed_len: usize, 55 + 56 + pub block: ReftableBlock, 57 + 58 + pub pos: usize, 59 + }
+21
src/reftable/blocksource.rs
··· 1 + pub struct ReftableBlockData { 2 + data: Vec<u8>, 3 + source: ReftableBlockSource, 4 + } 5 + 6 + impl AsRef<[u8]> for ReftableBlockData { 7 + fn as_ref(&self) -> &[u8] { 8 + &self.data 9 + } 10 + } 11 + 12 + pub trait ReftableBlockSourceOps { 13 + fn size(&self) -> u64; 14 + fn read_block(&self, offset: u64, size: u32) -> Result<Vec<u8>, String>; 15 + fn release_block(&self, data: &ReftableBlockData) -> Result<(), String>; 16 + fn close(&mut self) -> Result<(), String>; 17 + } 18 + 19 + pub struct ReftableBlockSource { 20 + ops: Box<dyn ReftableBlockSourceOps>, 21 + }
+34
src/reftable/error.rs
··· 1 + #[derive(Debug, Clone, PartialEq, Eq)] 2 + pub enum ReftableError { 3 + General(String), 4 + Io, 5 + Format, 6 + NotExist, 7 + Lock, 8 + Api, 9 + Zlib, 10 + EmptyTable, 11 + Refname, 12 + EntryTooBig, 13 + Outdated, 14 + OutOfMemory, 15 + } 16 + 17 + impl std::fmt::Display for ReftableError { 18 + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 19 + match self { 20 + ReftableError::General(msg) => write!(f, "general error: {}", msg), 21 + ReftableError::Io => write!(f, "I/O error"), 22 + ReftableError::Format => write!(f, "corrupt reftable file"), 23 + ReftableError::NotExist => write!(f, "file does not exist"), 24 + ReftableError::Lock => write!(f, "data is locked"), 25 + ReftableError::Api => write!(f, "misuse of the reftable API"), 26 + ReftableError::Zlib => write!(f, "zlib failure"), 27 + ReftableError::EmptyTable => write!(f, "wrote empty table"), 28 + ReftableError::Refname => write!(f, "invalid refname"), 29 + ReftableError::EntryTooBig => write!(f, "entry too large"), 30 + ReftableError::Outdated => write!(f, "data concurrently modified"), 31 + ReftableError::OutOfMemory => write!(f, "out of memory"), 32 + } 33 + } 34 + }
+26
src/reftable/fsck.rs
··· 1 + pub enum ReftableFsckError { 2 + TableName, 3 + MaxValue, 4 + } 5 + 6 + pub struct ReftableFsckInfo { 7 + pub msg: String, 8 + pub path: String, 9 + pub error: ReftableFsckError, 10 + } 11 + 12 + pub fn table_has_valid_name(name: &str) -> bool { 13 + todo!() 14 + } 15 + 16 + pub fn table_check_name(table: &ReftableTable) -> Result<(), String> { 17 + todo!() 18 + } 19 + 20 + pub fn table_checks(table: &ReftableTable) -> Result<(), String> { 21 + todo!() 22 + } 23 + 24 + pub fn reftable_fsck_check(stack: &ReftableStack) -> Result<(), String> { 25 + todo!() 26 + }
src/reftable/iter.rs
src/reftable/merged.rs
+14
src/reftable/mod.rs
··· 1 + pub mod basics; 2 + pub mod block; 3 + pub mod blocksource; 4 + pub mod error; 5 + pub mod fsck; 6 + pub mod iter; 7 + pub mod merged; 8 + pub mod pq; 9 + pub mod record; 10 + pub mod stack; 11 + pub mod system; 12 + pub mod table; 13 + pub mod tree; 14 + pub mod write;
src/reftable/pq.rs
+148
src/reftable/record.rs
··· 1 + use crate::reftable::basics::ReftableBuf; 2 + 3 + pub const REFTABLE_HASH_SIZE_MAX: usize = 32; 4 + pub const REFTABLE_HASH_SIZE_SHA1: usize = 20; 5 + pub const REFTABLE_HASH_SIZE_SHA256: usize = 32; 6 + 7 + #[derive(Debug, Clone, Copy, PartialEq, Eq)] 8 + pub enum RefValueType { 9 + Deletion = 0x0, 10 + Val1 = 0x1, 11 + Val2 = 0x2, 12 + SymRef = 0x3, 13 + } 14 + 15 + impl std::convert::TryFrom<u8> for RefValueType { 16 + type Error = String; 17 + 18 + fn try_from(value: u8) -> Result<Self, String> { 19 + match value { 20 + 0x0 => Ok(RefValueType::Deletion), 21 + 0x1 => Ok(RefValueType::Val1), 22 + 0x2 => Ok(RefValueType::Val2), 23 + 0x3 => Ok(RefValueType::SymRef), 24 + _ => Err(format!("Unknown ref value type: {value}")), 25 + } 26 + } 27 + } 28 + 29 + #[derive(Debug, Clone)] 30 + pub enum RefValue { 31 + Val1([u8; REFTABLE_HASH_SIZE_MAX]), 32 + Val2 { 33 + value: [u8; REFTABLE_HASH_SIZE_MAX], 34 + target_value: [u8; REFTABLE_HASH_SIZE_MAX], 35 + }, 36 + SymRef(String), 37 + } 38 + 39 + #[derive(Debug, Clone)] 40 + pub struct ReftableRefRecord { 41 + pub refname: String, 42 + pub update_index: u64, 43 + pub value: Option<RefValue>, 44 + } 45 + 46 + impl ReftableRefRecord { 47 + pub fn equals(&self, other: &ReftableRefRecord, hash_size: u32) -> bool { 48 + todo!() 49 + } 50 + } 51 + 52 + impl PartialEq for ReftableRefRecord { 53 + fn eq(&self, other: &ReftableRefRecord) -> bool { 54 + self.equals(other, REFTABLE_HASH_SIZE_MAX as u32) 55 + } 56 + } 57 + 58 + #[derive(Debug, Clone, Copy, PartialEq, Eq)] 59 + pub enum LogValueType { 60 + Deletion = 0x0, 61 + Update = 0x1, 62 + } 63 + 64 + impl std::convert::TryFrom<u8> for LogValueType { 65 + type Error = String; 66 + 67 + fn try_from(value: u8) -> Result<Self, String> { 68 + match value { 69 + 0x0 => Ok(LogValueType::Deletion), 70 + 0x1 => Ok(LogValueType::Update), 71 + _ => Err(format!("Unknown log value type: {value}")), 72 + } 73 + } 74 + } 75 + 76 + #[derive(Debug, Clone)] 77 + pub struct LogUpdate { 78 + pub new_hash: [u8; REFTABLE_HASH_SIZE_MAX], 79 + pub old_hash: [u8; REFTABLE_HASH_SIZE_MAX], 80 + pub name: String, 81 + pub email: String, 82 + pub time: u64, 83 + pub tz_offset: i16, 84 + pub message: String, 85 + } 86 + 87 + #[derive(Debug, Clone)] 88 + pub struct ReftableLogRecord { 89 + pub refname: String, 90 + pub update_index: u64, 91 + pub value: Option<LogUpdate>, 92 + } 93 + 94 + impl ReftableLogRecord { 95 + pub fn equals(&self, other: &ReftableLogRecord, hash_size: u32) -> bool { 96 + todo!() 97 + } 98 + } 99 + 100 + impl PartialEq for ReftableLogRecord { 101 + fn eq(&self, other: &ReftableLogRecord) -> bool { 102 + self.equals(other, REFTABLE_HASH_SIZE_MAX as u32) 103 + } 104 + } 105 + 106 + #[derive(Debug, Clone)] 107 + pub struct ReftableObjRecord { 108 + pub hash_prefix: Vec<u8>, 109 + pub offsets: Vec<u64>, 110 + } 111 + 112 + impl PartialEq for ReftableObjRecord { 113 + fn eq(&self, other: &Self) -> bool { 114 + self.hash_prefix == other.hash_prefix && self.offsets == other.offsets 115 + } 116 + } 117 + 118 + #[derive(Debug, Clone)] 119 + pub struct ReftableIndexRecord { 120 + pub offset: u64, 121 + pub last_key: ReftableBuf, 122 + } 123 + 124 + impl PartialEq for ReftableIndexRecord { 125 + fn eq(&self, other: &Self) -> bool { 126 + self.offset == other.offset && self.last_key.as_slice() == other.last_key.as_slice() 127 + } 128 + } 129 + 130 + #[derive(Debug, Clone)] 131 + pub enum ReftableRecord { 132 + Ref(ReftableRefRecord), 133 + Log(ReftableLogRecord), 134 + Obj(ReftableObjRecord), 135 + Index(ReftableIndexRecord), 136 + } 137 + 138 + impl PartialEq for ReftableRecord { 139 + fn eq(&self, other: &Self) -> bool { 140 + match (self, other) { 141 + (ReftableRecord::Ref(a), ReftableRecord::Ref(b)) => a == b, 142 + (ReftableRecord::Log(a), ReftableRecord::Log(b)) => a == b, 143 + (ReftableRecord::Obj(a), ReftableRecord::Obj(b)) => a == b, 144 + (ReftableRecord::Index(a), ReftableRecord::Index(b)) => a == b, 145 + _ => false, 146 + } 147 + } 148 + }
src/reftable/stack.rs
src/reftable/system.rs
src/reftable/table.rs
src/reftable/tree.rs
src/reftable/write.rs