Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1552176 - Generate rust methods from cenum idl r=nika
Browse files Browse the repository at this point in the history
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
  • Loading branch information
valenting committed Nov 10, 2019
1 parent e98047a commit 970d4a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions toolkit/components/bitsdownload/src/bits_interface/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion xpcom/idl-parser/xpidl/xpidl.py
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ def nativeType(self, calltype):
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)
Expand Down

0 comments on commit 970d4a2

Please sign in to comment.