Hi List,
First off, this came up today when I started on a set of rust bindings for
libgit2. I skimmed around, but if anyone else is working on the same thing,
let's combine effort.
To my point:
I'm writing bindings by hand instead of using bindgen for now to get a better
feel for rust.
I have this struct (Snipped for brevity) with it's C counterpart commented:
struct Repository {
_odb: *u8, // git_odb *_odb;
// ...
cvar_cache: [GitCvarValue, .. GIT_CVAR_CACHE_MAX] // git_cvar_value
cvar_cache[GIT_CVAR_CACHE_MAX];
}
Where GIT_CVAR_CACHE_MAX is the final element in enum git_cvar_cached. With a
similar enum in rust land:
enum GitCvarCached {
GIT_CVAR_AUTO_CRLF = 0, /* core.autocrlf */
// ...
GIT_CVAR_CACHE_MAX
}
I get a compile error:
src/repository.rs:24:17: 24:54 error: expected constant expr for vector length:
non-constant path in constant expr
src/repository.rs:24 cvar_cache: [GitCvarValue, .. GIT_CVAR_CACHE_MAX] //
git_cvar_value cvar_cache[GIT_CVAR_CACHE_MAX];
This seems to me like it should work. The value of that enum is a compile and
(if I'm reading the docs surrounding enums correctly) run time constant.
My 2(ish) questions are:
1. Should this work?
and then either:
2. Should I work on a patch to make it work?
or
2. How would I idiomatically write this, since I think I saw on IRC today
there's also no neat way to get the length of an enum either.
Cheers
richo
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev