Bug 1552176 - Generate rust methods from cenum idl r=nika

This patch changes the xpidl parser to generate the rust trait code for
methods that take or return a cenum value.
Previously this would return an error, which means that adding a method
that uses cenums to an existing interface could cause rust code that
implements that interface to fail to build.

The generated methods take or return u8/u16/u32 depending on the width of the
enum. While this is not optimal (the parameter could contain values that are
not actually part of the enum), this is similar to what we do for nsLoadFlags.
In the future it would be nice to generate code that actually checks the
values are present in the enum, and to use a typedef instead of a plain
unsigned int.

Differential Revision: https://phabricator.services.mozilla.com/D51838

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Valentin Gosu 2019-11-10 17:12:32 +00:00
Родитель 60297f04a5
Коммит 0680f64f28
2 изменённых файлов: 15 добавлений и 1 удалений

Просмотреть файл

@ -720,6 +720,20 @@ impl BitsRequest {
fn set_load_flags(&self, _load_flags: nsLoadFlags) -> Result<(), nsresult> {
Err(NS_ERROR_NOT_IMPLEMENTED)
}
xpcom_method!(
get_trr_mode => GetTRRMode() -> u8
);
fn get_trr_mode(&self) -> Result<u8, nsresult> {
Err(NS_ERROR_NOT_IMPLEMENTED)
}
xpcom_method!(
set_trr_mode => SetTRRMode(_trr_mode: u8)
);
fn set_trr_mode(&self, _trr_mode: u8) -> Result<(), nsresult> {
Err(NS_ERROR_NOT_IMPLEMENTED)
}
}
impl Drop for BitsRequest {

Просмотреть файл

@ -943,7 +943,7 @@ class CEnum(object):
return "%s::%s " % (self.iface.name, self.basename)
def rustType(self, calltype):
raise RustNoncompat('cenums unimplemented')
return "%s u%d" % ('*mut' if 'out' in calltype else '', self.width)
def __str__(self):
body = ', '.join('%s = %s' % v for v in self.variants)