Skip to content

Commit

Permalink
Implement Display trait
Browse files Browse the repository at this point in the history
  • Loading branch information
arg0d committed Oct 23, 2023
1 parent 6f6afd3 commit 2b505e4
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions bindgen/templates/ObjectTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ public class {{ type_name }}: FFIObject<{{ safe_handle_type }}>, I{{ type_name }
{% endmatch %}
{% endfor %}

{%- for tm in obj.uniffi_traits() -%}
{%- match tm %}
{%- when UniffiTrait::Display { fmt } %}
public override string ToString() {
return {{ Type::String.borrow()|lift_fn }}({%- call cs::to_ffi_call_with_prefix("this.GetHandle()", fmt) %});
}
{%- else %}
{%- endmatch %}
{%- endfor %}

{% if !obj.alternate_constructors().is_empty() -%}
{% for cons in obj.alternate_constructors() -%}
{%- call cs::docstring(cons, 4) %}
Expand Down
22 changes: 22 additions & 0 deletions dotnet-tests/UniffiCS.binding_tests/TestTraitMethod.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

using uniffi.trait_methods;

public class TestTraitMethods {
[Fact]
public void TraitMethodsWork() {
using (var methods = new TraitMethods("yo")) {
Assert.Equal("TraitMethods(yo)", methods.ToString());
}
}

[Fact]
public void TraitMethodsProcMacro() {
using (var methods = new ProcTraitMethods("yo")) {
Assert.Equal("ProcTraitMethods(yo)", methods.ToString());
}
}
}

1 change: 1 addition & 0 deletions fixtures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ uniffi-fixture-callbacks = { path = "../3rd-party/uniffi-rs/fixtures/callbacks"
uniffi-fixture-coverall = { path = "../3rd-party/uniffi-rs/fixtures/coverall" }
uniffi-fixture-docstring = { path = "../3rd-party/uniffi-rs/fixtures/docstring" }
uniffi-fixture-time = { path = "../3rd-party/uniffi-rs/fixtures/uniffi-fixture-time" }
uniffi-fixture-trait-methods = { path = "../3rd-party/uniffi-rs/fixtures/trait-methods" }
1 change: 1 addition & 0 deletions fixtures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod uniffi_fixtures {
uniffi_coverall::uniffi_reexport_scaffolding!();
uniffi_fixture_callbacks::uniffi_reexport_scaffolding!();
uniffi_fixture_docstring::uniffi_reexport_scaffolding!();
uniffi_trait_methods::uniffi_reexport_scaffolding!();

global_methods_class_name::uniffi_reexport_scaffolding!();
uniffi_cs_custom_types_builtin::uniffi_reexport_scaffolding!();
Expand Down

0 comments on commit 2b505e4

Please sign in to comment.