-
Notifications
You must be signed in to change notification settings - Fork 234
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A strawfox for #417 to allow an interface to have a method which take… #418
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,12 +23,13 @@ use anyhow::{bail, Result}; | |
/// This is a convenience enum for parsing UDL attributes and erroring out if we encounter | ||
/// any unsupported ones. These don't convert directly into parts of a `ComponentInterface`, but | ||
/// may influence the properties of things like functions and arguments. | ||
#[derive(Debug, Clone, Hash)] | ||
#[derive(Debug, Clone, Hash, PartialEq)] | ||
pub(super) enum Attribute { | ||
ByRef, | ||
Error, | ||
Threadsafe, | ||
Throws(String), | ||
SomethingSomethingArc, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really understand the need for this, so I'm not going to much help naming this. |
||
} | ||
|
||
impl Attribute { | ||
|
@@ -50,6 +51,7 @@ impl TryFrom<&weedle::attribute::ExtendedAttribute<'_>> for Attribute { | |
"ByRef" => Ok(Attribute::ByRef), | ||
"Error" => Ok(Attribute::Error), | ||
"Threadsafe" => Ok(Attribute::Threadsafe), | ||
"SomethingSomethingArc" => Ok(Attribute::SomethingSomethingArc), | ||
_ => anyhow::bail!("ExtendedAttributeNoArgs not supported: {:?}", (attr.0).0), | ||
}, | ||
// Matches assignment-style attributes like ["Throws=Error"] | ||
|
@@ -145,6 +147,10 @@ impl FunctionAttributes { | |
_ => None, | ||
}) | ||
} | ||
|
||
pub(super) fn get_something_something_arc(&self) -> bool { | ||
self.0.iter().any(|a| *a == Attribute::SomethingSomethingArc) | ||
} | ||
} | ||
|
||
impl TryFrom<&weedle::attribute::ExtendedAttributeList<'_>> for FunctionAttributes { | ||
|
@@ -154,6 +160,7 @@ impl TryFrom<&weedle::attribute::ExtendedAttributeList<'_>> for FunctionAttribut | |
) -> Result<Self, Self::Error> { | ||
let attrs = parse_attributes(weedle_attributes, |attr| match attr { | ||
Attribute::Throws(_) => Ok(()), | ||
Attribute::SomethingSomethingArc => Ok(()), // XXX - not valid in ctors? | ||
_ => bail!(format!( | ||
"{:?} not supported for functions, methods or constructors", | ||
attr | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,12 +66,20 @@ use uniffi::UniffiMethodCall; | |
{% match meth.throws() -%} | ||
{% when Some with (e) -%} | ||
{{ this_handle_map }}.method_call_with_result(err, {{ meth.first_argument().name() }}, |obj| -> Result<{% call return_type_func(meth) %}, {{e}}> { | ||
{%- if meth.something_something_arc() -%} | ||
let _retval = {{ obj.name() }}::{%- call to_rs_call_with_prefix("obj", meth) -%}?; | ||
{%- else -%} | ||
let _retval = {{ obj.name() }}::{%- call to_rs_call_with_prefix("&*obj", meth) -%}?; | ||
{%- endif -%} | ||
Comment on lines
+69
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
Ok({% call ret(meth) %}) | ||
}) | ||
{% else -%} | ||
{{ this_handle_map }}.method_call_with_output(err, {{ meth.first_argument().name() }}, |obj| { | ||
{%- if meth.something_something_arc() -%} | ||
let _retval = {{ obj.name() }}::{%- call to_rs_call_with_prefix("obj", meth) -%}; | ||
{%- else -%} | ||
let _retval = {{ obj.name() }}::{%- call to_rs_call_with_prefix("&*obj", meth) -%}; | ||
{%- endif -%} | ||
{% call ret(meth) %} | ||
}) | ||
{% endmatch -%} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to be clear, I think we want a new example rather than abusing this, but this is OK for demo purposes