-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Dear Rusties,
I am currently in the early stages of writing a file system access library for mozilla-central that might eventually replace some or all of mozilla-central low-level file access code with something faster and a little higher level. I also consider porting ? perhaps even prototyping ? this library to Rust. For this purpose, I need a little guidance on a few points. *** #ifdef My code heavily relies on #ifdefs with macros to compile code conditionally, depending on both: - - which platform is targeted (in mozilla-central, that's macros XP_WIN, XP_UNIX); - - which primitives are available in libc (through autoconf's AC_CHECK_FUNS and the macros HAVE_xxxxx that it defines). What is the best way to achieve this in Rust? *** Foreign types - From what I see in the code of unix_os.rs, we can simply define `type foobar` in a foreign module and use this in the code. Are there any limitations to this that I should know before employing the technique? *** Unicode On Unix platforms, file names are `char*`. On Windows platforms, they are `wchar*`. In mozilla-central, I use the strings API to make my life simpler and to handle all conversions for me. How should I do this with Rust? As far as I understand, the current win32_os.rs simply assumes that any `str` passed can be used as a valid `char*`, and relies on Cygwin to handle any oddity. As most of the features of Win32 are not available through Cygwin, this is probably something that I cannot use. *** Garbage-collection / destruction I am not familiar with Rust resources yet, but chances are that I will need to interact with them to get destruction and garbage-collection on file descriptors and directory structures. - - Do I understand correctly that resources a the right tool for the task? - - From the documentation, I understand that a failed task will not call destructors. Do I understand correctly? If so, this seems like a major issue, as a process with failed tasks will leak file descriptors. *** Error-handling For file access, some error conditions are indeed failures, while some are simply information that should be propagated. As I understand, Rust will not have ML/C++-style exceptions in any foreseeable future. I therefore see the following possibilities: - - Either aggressively `spawn_notify` tasks, `unsupervise` them and `fail` in case of any error, with some convention to pass `errno`; - - or have each function return `either::t<Result, Error>` and propagate error conditions manually, much as is done in current mozilla-central code; - - or offer both styles, with some naming convention to differentiate them ? say submodules `fails` / `dnf`. Any suggestion on the best policy? Well, that covers most of my interrogations. Any suggestion or idea? Thanks, David -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.11 (Darwin) iQEcBAEBAgAGBQJOwMj3AAoJED+FkPgNe9W+5XIH/iHhkD5SFjJtEaabRtmvEwie dqKHzv10wD0nO4yNB9N2SUpUHNbysm3Cc1d5Rug48eBiqaPjRJYm2Gila0dYeOI3 SJs/8AQ6Bis0mLbggs9lBNNsfmBPw+E7RjXTsqS0AZG20Cyn1xeCPI1fnXuzKyms 2lrDSduSZNyVbbpWV/9zR9+7iXASX/wx1CaNbaznJ92Uf+FMFdkwV20VXtlnkQYU yWHMicwswmYuav3xRYGtCKG+qKgFxh0KRkJl0gXuNdR//v/qZaRC6YCneMjm/Qeb jlfO2jdE3NXxYwqsZA4gxbPVHpIYn9g27s0hO4WwkR84Ou9Qux2FwuIKPGOqPS4= =2EG1 -----END PGP SIGNATURE----- _______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev