From: Ezekiel Newren Date: Mon, 25 Aug 2025 20:40:19 GMT Subject: Re: [PATCH v3 06/15] ivec: create a vector type that is interoperable between C and Rust Message-ID: In-Reply-To: <71B2DFE6-77E5-47FE-9FAC-AFC1B85DA0E2@gmail.com> On Sun, Aug 24, 2025 at 7:31 AM Ben Knoble wrote: > I’m mildly surprised Vec isn’t a good fit: isn’t it a pointer, length, capacity triple? But it sounds like the main issue is allocator interop… which I would also have thought was supported? At least the current version is documented as being generic against an Allocator, too. Conceptually yes, semantically and syntactically no. On top of Vec not being defined with #[repr(C)] (which ensures field order, C ABI layout, padding, etc...) the struct definition for Vec isn't constant between Rust versions. I'd be open to suggestions for an alternative to my ivec type. === Rust version 1.61.0 === from: https://doc.rust-lang.org/1.61.0/src/alloc/vec/mod.rs.html#400 #[stable(feature = "rust1", since = "1.0.0")] #[cfg_attr(not(test), rustc_diagnostic_item = "Vec")] #[rustc_insignificant_dtor] pub struct Vec { buf: RawVec, len: usize, } from: https://doc.rust-lang.org/1.61.0/src/alloc/raw_vec.rs.html#52 #[allow(missing_debug_implementations)] pub(crate) struct RawVec { ptr: Unique, cap: usize, alloc: A, } === Rust version 1.89.0 === from: https://doc.rust-lang.org/1.89.0/src/alloc/vec/mod.rs.html#414 #[stable(feature = "rust1", since = "1.0.0")] #[rustc_diagnostic_item = "Vec"] #[rustc_insignificant_dtor] pub struct Vec { buf: RawVec, len: usize, } from: https://doc.rust-lang.org/1.89.0/src/alloc/raw_vec/mod.rs.html#74 #[allow(missing_debug_implementations)] pub(crate) struct RawVec { inner: RawVecInner, _marker: PhantomData, } from: https://doc.rust-lang.org/1.89.0/src/alloc/raw_vec/mod.rs.html#86 #[allow(missing_debug_implementations)] struct RawVecInner { ptr: Unique, /// Never used for ZSTs; it's `capacity()`'s responsibility to return usize::MAX in that case. /// /// # Safety /// /// `cap` must be in the `0..=isize::MAX` range. cap: Cap, alloc: A, } > Am I reading the patch correctly that the ivec implementation is primarily C? I’m not familiar with too many FFI projects in Rust, but I might have hoped we could write parts in Rust to gain any benefits from that, too. Is that a fool’s errand I’m thinking of? The ivec type is defined and implemented in C (interop/ivec.[ch]) and Rust (rust/interop/src/ivec.rs). When I started writing the ivec type I didn't know if the Git community would accept a hard dependency on Rust, so I made ivec usable in C without needing Rust.