summaryrefslogtreecommitdiffstats
path: root/third_party/rust/uniffi_bindgen/src/interface/function.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--third_party/rust/uniffi_bindgen/src/interface/function.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/third_party/rust/uniffi_bindgen/src/interface/function.rs b/third_party/rust/uniffi_bindgen/src/interface/function.rs
index 2d18288c1c..8effc4c876 100644
--- a/third_party/rust/uniffi_bindgen/src/interface/function.rs
+++ b/third_party/rust/uniffi_bindgen/src/interface/function.rs
@@ -59,6 +59,8 @@ pub struct Function {
// avoids a weird circular dependency in the calculation.
#[checksum_ignore]
pub(super) ffi_func: FfiFunction,
+ #[checksum_ignore]
+ pub(super) docstring: Option<String>,
pub(super) throws: Option<Type>,
pub(super) checksum_fn_name: String,
// Force a checksum value, or we'll fallback to the trait.
@@ -128,6 +130,10 @@ impl Function {
.chain(self.return_type.iter().flat_map(Type::iter_types)),
)
}
+
+ pub fn docstring(&self) -> Option<&str> {
+ self.docstring.as_deref()
+ }
}
impl From<uniffi_meta::FnParamMetadata> for Argument {
@@ -163,6 +169,7 @@ impl From<uniffi_meta::FnMetadata> for Function {
arguments,
return_type,
ffi_func,
+ docstring: meta.docstring.clone(),
throws: meta.throws,
checksum_fn_name,
checksum: meta.checksum,
@@ -242,6 +249,9 @@ pub trait Callable {
fn return_type(&self) -> Option<Type>;
fn throws_type(&self) -> Option<Type>;
fn is_async(&self) -> bool;
+ fn takes_self(&self) -> bool {
+ false
+ }
fn result_type(&self) -> ResultType {
ResultType {
return_type: self.return_type(),
@@ -311,6 +321,10 @@ impl<T: Callable> Callable for &T {
fn is_async(&self) -> bool {
(*self).is_async()
}
+
+ fn takes_self(&self) -> bool {
+ (*self).takes_self()
+ }
}
#[cfg(test)]
@@ -364,4 +378,22 @@ mod test {
);
Ok(())
}
+
+ #[test]
+ fn test_docstring_function() {
+ const UDL: &str = r#"
+ namespace test {
+ /// informative docstring
+ void testing();
+ };
+ "#;
+ let ci = ComponentInterface::from_webidl(UDL, "crate_name").unwrap();
+ assert_eq!(
+ ci.get_function_definition("testing")
+ .unwrap()
+ .docstring()
+ .unwrap(),
+ "informative docstring"
+ );
+ }
}