diff --git a/Cargo.lock b/Cargo.lock index 65efd3c5ab..a622cdc73d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -94,9 +94,9 @@ checksum = "a4668cab20f66d8d020e1fbc0ebe47217433c1b6c8f2040faf858554e394ace6" [[package]] name = "askama" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a4e46abb203e00ef226442d452769233142bbfdd79c3941e84c8e61c4112543" +checksum = "f75363874b771be265f4ffe307ca705ef6f3baa19011c149da8674a87f1b75c4" dependencies = [ "askama_derive", "itoa", @@ -107,9 +107,9 @@ dependencies = [ [[package]] name = "askama_derive" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54398906821fd32c728135f7b351f0c7494ab95ae421d41b6f5a020e158f28a6" +checksum = "129397200fe83088e8a68407a8e2b1f826cf0086b21ccdb866a722c8bcd3a94f" dependencies = [ "askama_parser", "basic-toml", @@ -124,9 +124,9 @@ dependencies = [ [[package]] name = "askama_parser" -version = "0.13.0" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf315ce6524c857bb129ff794935cf6d42c82a6cff60526fe2a63593de4d0d4f" +checksum = "d6ab5630b3d5eaf232620167977f95eb51f3432fc76852328774afbd242d4358" dependencies = [ "memchr", "serde", diff --git a/uniffi_bindgen/Cargo.toml b/uniffi_bindgen/Cargo.toml index 38657ed3f9..20df918aff 100644 --- a/uniffi_bindgen/Cargo.toml +++ b/uniffi_bindgen/Cargo.toml @@ -18,7 +18,7 @@ ffi-trace = ["uniffi_testing?/ffi-trace"] [dependencies] anyhow = "1" -askama = { version = "0.13.0", default-features = false, features = ["config", "derive", "alloc"] } +askama = { version = "0.14", default-features = false, features = ["config", "derive", "alloc"] } camino = "1.0.8" cargo_metadata = { version = "0.19", optional = true } fs-err = "2.7.0" diff --git a/uniffi_bindgen/src/bindings/kotlin/gen_kotlin/mod.rs b/uniffi_bindgen/src/bindings/kotlin/gen_kotlin/mod.rs index ed1c97eca7..110007f17a 100644 --- a/uniffi_bindgen/src/bindings/kotlin/gen_kotlin/mod.rs +++ b/uniffi_bindgen/src/bindings/kotlin/gen_kotlin/mod.rs @@ -619,54 +619,80 @@ mod filters { pub(super) fn type_name( as_ct: &impl AsCodeType, + _: &dyn askama::Values, ci: &ComponentInterface, ) -> Result { Ok(as_ct.as_codetype().type_label(ci)) } - pub(super) fn canonical_name(as_ct: &impl AsCodeType) -> Result { + pub(super) fn canonical_name( + as_ct: &impl AsCodeType, + _: &dyn askama::Values, + ) -> Result { Ok(as_ct.as_codetype().canonical_name()) } - pub(super) fn ffi_converter_name(as_ct: &impl AsCodeType) -> Result { + pub(super) fn ffi_converter_name( + as_ct: &impl AsCodeType, + _: &dyn askama::Values, + ) -> Result { Ok(as_ct.as_codetype().ffi_converter_name()) } - pub(super) fn ffi_type(type_: &impl AsType) -> askama::Result { + pub(super) fn ffi_type( + type_: &impl AsType, + _: &dyn askama::Values, + ) -> askama::Result { Ok(type_.as_type().into()) } - pub(super) fn lower_fn(as_ct: &impl AsCodeType) -> Result { + pub(super) fn lower_fn( + as_ct: &impl AsCodeType, + _: &dyn askama::Values, + ) -> Result { Ok(format!( "{}.lower", as_ct.as_codetype().ffi_converter_name() )) } - pub(super) fn allocation_size_fn(as_ct: &impl AsCodeType) -> Result { + pub(super) fn allocation_size_fn( + as_ct: &impl AsCodeType, + _: &dyn askama::Values, + ) -> Result { Ok(format!( "{}.allocationSize", as_ct.as_codetype().ffi_converter_name() )) } - pub(super) fn write_fn(as_ct: &impl AsCodeType) -> Result { + pub(super) fn write_fn( + as_ct: &impl AsCodeType, + _: &dyn askama::Values, + ) -> Result { Ok(format!( "{}.write", as_ct.as_codetype().ffi_converter_name() )) } - pub(super) fn lift_fn(as_ct: &impl AsCodeType) -> Result { + pub(super) fn lift_fn( + as_ct: &impl AsCodeType, + _: &dyn askama::Values, + ) -> Result { Ok(format!("{}.lift", as_ct.as_codetype().ffi_converter_name())) } - pub(super) fn read_fn(as_ct: &impl AsCodeType) -> Result { + pub(super) fn read_fn( + as_ct: &impl AsCodeType, + _: &dyn askama::Values, + ) -> Result { Ok(format!("{}.read", as_ct.as_codetype().ffi_converter_name())) } pub fn render_default( default: &DefaultValue, + _: &dyn askama::Values, as_ct: &impl AsType, ci: &ComponentInterface, ) -> Result { @@ -694,7 +720,11 @@ mod filters { } // Get the idiomatic Kotlin rendering of an individual enum variant's discriminant - pub fn variant_discr_literal(e: &Enum, index: &usize) -> Result { + pub fn variant_discr_literal( + e: &Enum, + _: &dyn askama::Values, + index: &usize, + ) -> Result { let literal = e.variant_discr(*index).expect("invalid index"); match literal { // Kotlin doesn't convert between signed and unsigned by default @@ -709,6 +739,7 @@ mod filters { pub fn ffi_type_name_by_value( type_: &FfiType, + _: &dyn askama::Values, ci: &ComponentInterface, ) -> Result { Ok(KotlinCodeOracle.ffi_type_label_by_value(type_, ci)) @@ -716,60 +747,78 @@ mod filters { pub fn ffi_type_name_for_ffi_struct( type_: &FfiType, + _: &dyn askama::Values, ci: &ComponentInterface, ) -> Result { Ok(KotlinCodeOracle.ffi_type_label_for_ffi_struct(type_, ci)) } - pub fn ffi_default_value(type_: FfiType) -> Result { + pub fn ffi_default_value( + type_: FfiType, + _: &dyn askama::Values, + ) -> Result { Ok(KotlinCodeOracle.ffi_default_value(&type_)) } /// Get the idiomatic Kotlin rendering of a function name. pub fn class_name>( nm: S, + _: &dyn askama::Values, ci: &ComponentInterface, ) -> Result { Ok(KotlinCodeOracle.class_name(ci, nm.as_ref())) } /// Get the idiomatic Kotlin rendering of a function name. - pub fn fn_name>(nm: S) -> Result { + pub fn fn_name>(nm: S, _: &dyn askama::Values) -> Result { Ok(KotlinCodeOracle.fn_name(nm.as_ref())) } /// Get the idiomatic Kotlin rendering of a variable name. - pub fn var_name>(nm: S) -> Result { + pub fn var_name>(nm: S, _: &dyn askama::Values) -> Result { Ok(KotlinCodeOracle.var_name(nm.as_ref())) } /// Get the idiomatic Kotlin rendering of a variable name. - pub fn var_name_raw>(nm: S) -> Result { + pub fn var_name_raw>( + nm: S, + _: &dyn askama::Values, + ) -> Result { Ok(KotlinCodeOracle.var_name_raw(nm.as_ref())) } /// Get a String representing the name used for an individual enum variant. - pub fn variant_name(v: &Variant) -> Result { + pub fn variant_name(v: &Variant, _: &dyn askama::Values) -> Result { Ok(KotlinCodeOracle.enum_variant_name(v.name())) } - pub fn error_variant_name(v: &Variant) -> Result { + pub fn error_variant_name( + v: &Variant, + _: &dyn askama::Values, + ) -> Result { let name = v.name().to_string().to_upper_camel_case(); Ok(KotlinCodeOracle.convert_error_suffix(&name)) } /// Get the idiomatic Kotlin rendering of an FFI callback function name - pub fn ffi_callback_name>(nm: S) -> Result { + pub fn ffi_callback_name>( + nm: S, + _: &dyn askama::Values, + ) -> Result { Ok(KotlinCodeOracle.ffi_callback_name(nm.as_ref())) } /// Get the idiomatic Kotlin rendering of an FFI struct name - pub fn ffi_struct_name>(nm: S) -> Result { + pub fn ffi_struct_name>( + nm: S, + _: &dyn askama::Values, + ) -> Result { Ok(KotlinCodeOracle.ffi_struct_name(nm.as_ref())) } pub fn async_poll( callable: impl Callable, + _: &dyn askama::Values, ci: &ComponentInterface, ) -> Result { let ffi_func = callable.ffi_rust_future_poll(ci); @@ -780,6 +829,7 @@ mod filters { pub fn async_complete( callable: impl Callable, + _: &dyn askama::Values, ci: &ComponentInterface, ) -> Result { let ffi_func = callable.ffi_rust_future_complete(ci); @@ -803,6 +853,7 @@ mod filters { pub fn async_free( callable: impl Callable, + _: &dyn askama::Values, ci: &ComponentInterface, ) -> Result { let ffi_func = callable.ffi_rust_future_free(ci); @@ -816,12 +867,16 @@ mod filters { /// These are used to avoid name clashes with kotlin identifiers, but sometimes you want to /// render the name unquoted. One example is the message property for errors where we want to /// display the name for the user. - pub fn unquote>(nm: S) -> Result { + pub fn unquote>(nm: S, _: &dyn askama::Values) -> Result { Ok(nm.as_ref().trim_matches('`').to_string()) } /// Get the idiomatic Kotlin rendering of docstring - pub fn docstring>(docstring: S, spaces: &i32) -> Result { + pub fn docstring>( + docstring: S, + _: &dyn askama::Values, + spaces: &i32, + ) -> Result { let middle = textwrap::indent(&textwrap::dedent(docstring.as_ref()), " * "); let wrapped = format!("/**\n{middle}\n */"); diff --git a/uniffi_bindgen/src/bindings/python/filters.rs b/uniffi_bindgen/src/bindings/python/filters.rs index 1e09da8648..c7718058fb 100644 --- a/uniffi_bindgen/src/bindings/python/filters.rs +++ b/uniffi_bindgen/src/bindings/python/filters.rs @@ -19,7 +19,11 @@ use askama::Result; /// /// This makes it so the template code can use something like /// `{{ item.docstring|docstring(4) -}}` to render the correct docstring in both cases. -pub fn docstring(docstring: &Option, indent: usize) -> Result { +pub fn docstring( + docstring: &Option, + _: &dyn askama::Values, + indent: usize, +) -> Result { let Some(docstring) = docstring.as_deref() else { return Ok("".to_string()); }; diff --git a/uniffi_bindgen/src/bindings/ruby/gen_ruby/mod.rs b/uniffi_bindgen/src/bindings/ruby/gen_ruby/mod.rs index 4fe196053e..2af9c34faa 100644 --- a/uniffi_bindgen/src/bindings/ruby/gen_ruby/mod.rs +++ b/uniffi_bindgen/src/bindings/ruby/gen_ruby/mod.rs @@ -115,7 +115,7 @@ impl<'a> RubyWrapper<'a> { mod filters { use super::*; - pub fn type_ffi(type_: &FfiType) -> Result { + pub fn type_ffi(type_: &FfiType, _: &dyn askama::Values) -> Result { Ok(match type_ { FfiType::Int8 => ":int8".to_string(), FfiType::UInt8 => ":uint8".to_string(), @@ -144,7 +144,10 @@ mod filters { }) } - pub fn default_rb(default: &DefaultValue) -> Result { + pub fn default_rb( + default: &DefaultValue, + _: &dyn askama::Values, + ) -> Result { let DefaultValue::Literal(literal) = default else { unimplemented!("not supported."); }; @@ -159,12 +162,12 @@ mod filters { // use the double-quote form to match with the other languages, and quote escapes. Literal::String(s) => format!("\"{s}\""), Literal::None => "nil".into(), - Literal::Some { inner } => default_rb(inner)?, + Literal::Some { inner } => default_rb(inner, &())?, Literal::EmptySequence => "[]".into(), Literal::EmptyMap => "{}".into(), Literal::Enum(v, type_) => match type_ { Type::Enum { name, .. } => { - format!("{}::{}", class_name_rb(name)?, enum_name_rb(v)?) + format!("{}::{}", class_name_rb(name, &())?, enum_name_rb(v, &())?) } _ => panic!("Unexpected type in enum literal: {type_:?}"), }, @@ -183,27 +186,28 @@ mod filters { }) } - pub fn class_name_rb(nm: &str) -> Result { + pub fn class_name_rb(nm: &str, _: &dyn askama::Values) -> Result { Ok(nm.to_string().to_upper_camel_case()) } - pub fn fn_name_rb(nm: &str) -> Result { + pub fn fn_name_rb(nm: &str, _: &dyn askama::Values) -> Result { Ok(nm.to_string().to_snake_case()) } - pub fn var_name_rb(nm: &str) -> Result { + pub fn var_name_rb(nm: &str, _: &dyn askama::Values) -> Result { let nm = nm.to_string(); let prefix = if is_reserved_word(&nm) { "_" } else { "" }; Ok(format!("{prefix}{}", nm.to_snake_case())) } - pub fn enum_name_rb(nm: &str) -> Result { + pub fn enum_name_rb(nm: &str, _: &dyn askama::Values) -> Result { Ok(nm.to_string().to_shouty_snake_case()) } pub fn coerce_rb, S2: AsRef>( nm: S1, + _: &dyn askama::Values, ns: S2, type_: &Type, ) -> Result { @@ -227,9 +231,11 @@ mod filters { Type::CallbackInterface { .. } => { panic!("No support for coercing callback interfaces yet") } - Type::Optional { inner_type: t } => format!("({nm} ? {} : nil)", coerce_rb(nm, ns, t)?), + Type::Optional { inner_type: t } => { + format!("({nm} ? {} : nil)", coerce_rb(nm, &(), ns, t)?) + } Type::Sequence { inner_type: t } => { - let coerce_code = coerce_rb("v", ns, t)?; + let coerce_code = coerce_rb("v", &(), ns, t)?; if coerce_code == "v" { nm.to_string() } else { @@ -237,8 +243,8 @@ mod filters { } } Type::Map { value_type: t, .. } => { - let k_coerce_code = coerce_rb("k", ns, &Type::String)?; - let v_coerce_code = coerce_rb("v", ns, t)?; + let k_coerce_code = coerce_rb("k", &(), ns, &Type::String)?; + let v_coerce_code = coerce_rb("v", &(), ns, t)?; if k_coerce_code == "k" && v_coerce_code == "v" { nm.to_string() @@ -252,11 +258,15 @@ mod filters { }) } - pub fn check_lower_rb>(nm: S, type_: &Type) -> Result { + pub fn check_lower_rb>( + nm: S, + _: &dyn askama::Values, + type_: &Type, + ) -> Result { let nm = nm.as_ref(); Ok(match type_ { Type::Object { name, .. } => { - format!("({}.uniffi_check_lower {nm})", class_name_rb(name)?) + format!("({}.uniffi_check_lower {nm})", class_name_rb(name, &())?) } Type::Enum { .. } | Type::Record { .. } @@ -264,14 +274,18 @@ mod filters { | Type::Sequence { .. } | Type::Map { .. } => format!( "RustBuffer.check_lower_{}({})", - class_name_rb(&canonical_name(type_))?, + class_name_rb(&canonical_name(type_), &())?, nm ), _ => "".to_owned(), }) } - pub fn lower_rb(nm: &str, type_: &Type) -> Result { + pub fn lower_rb( + nm: &str, + _: &dyn askama::Values, + type_: &Type, + ) -> Result { Ok(match type_ { Type::Int8 | Type::UInt8 @@ -286,7 +300,9 @@ mod filters { Type::Boolean => format!("({nm} ? 1 : 0)"), Type::String => format!("RustBuffer.allocFromString({nm})"), Type::Bytes => format!("RustBuffer.allocFromBytes({nm})"), - Type::Object { name, .. } => format!("({}.uniffi_lower {nm})", class_name_rb(name)?), + Type::Object { name, .. } => { + format!("({}.uniffi_lower {nm})", class_name_rb(name, &())?) + } Type::CallbackInterface { .. } => { panic!("No support for lowering callback interfaces yet") } @@ -298,14 +314,18 @@ mod filters { | Type::Duration | Type::Map { .. } => format!( "RustBuffer.alloc_from_{}({})", - class_name_rb(&canonical_name(type_))?, + class_name_rb(&canonical_name(type_), &())?, nm ), Type::Custom { .. } => panic!("No support for lowering custom types, yet"), }) } - pub fn lift_rb(nm: &str, type_: &Type) -> Result { + pub fn lift_rb( + nm: &str, + _: &dyn askama::Values, + type_: &Type, + ) -> Result { Ok(match type_ { Type::Int8 | Type::UInt8 @@ -319,7 +339,9 @@ mod filters { Type::Boolean => format!("1 == {nm}"), Type::String => format!("{nm}.consumeIntoString"), Type::Bytes => format!("{nm}.consumeIntoBytes"), - Type::Object { name, .. } => format!("{}.uniffi_allocate({nm})", class_name_rb(name)?), + Type::Object { name, .. } => { + format!("{}.uniffi_allocate({nm})", class_name_rb(name, &())?) + } Type::CallbackInterface { .. } => { panic!("No support for lifting callback interfaces, yet") } @@ -327,7 +349,7 @@ mod filters { format!( "{}.consumeInto{}", nm, - class_name_rb(&canonical_name(type_))? + class_name_rb(&canonical_name(type_), &())? ) } Type::Record { .. } @@ -338,7 +360,7 @@ mod filters { | Type::Map { .. } => format!( "{}.consumeInto{}", nm, - class_name_rb(&canonical_name(type_))? + class_name_rb(&canonical_name(type_), &())? ), Type::Custom { .. } => panic!("No support for lifting custom types, yet"), }) diff --git a/uniffi_bindgen/src/bindings/swift/gen_swift/mod.rs b/uniffi_bindgen/src/bindings/swift/gen_swift/mod.rs index 865d174d0f..97d1229265 100644 --- a/uniffi_bindgen/src/bindings/swift/gen_swift/mod.rs +++ b/uniffi_bindgen/src/bindings/swift/gen_swift/mod.rs @@ -688,26 +688,41 @@ pub mod filters { &SwiftCodeOracle } - pub fn type_name(as_type: &impl AsType) -> Result { + pub fn type_name( + as_type: &impl AsType, + _: &dyn askama::Values, + ) -> Result { Ok(oracle().find(&as_type.as_type()).type_label()) } - pub fn return_type_name(as_type: Option<&impl AsType>) -> Result { + pub fn return_type_name( + as_type: Option<&impl AsType>, + _: &dyn askama::Values, + ) -> Result { Ok(match as_type { Some(as_type) => oracle().find(&as_type.as_type()).type_label(), None => "()".to_owned(), }) } - pub fn canonical_name(as_type: &impl AsType) -> Result { + pub fn canonical_name( + as_type: &impl AsType, + _: &dyn askama::Values, + ) -> Result { Ok(oracle().find(&as_type.as_type()).canonical_name()) } - pub fn ffi_converter_name(as_type: &impl AsType) -> Result { + pub fn ffi_converter_name( + as_type: &impl AsType, + _: &dyn askama::Values, + ) -> Result { Ok(oracle().find(&as_type.as_type()).ffi_converter_name()) } - pub fn ffi_error_converter_name(as_type: &impl AsType) -> Result { + pub fn ffi_error_converter_name( + as_type: &impl AsType, + _: &dyn askama::Values, + ) -> Result { // special handling for types used as errors. let mut name = oracle().find(&as_type.as_type()).ffi_converter_name(); if matches!(&as_type.as_type(), Type::Object { .. }) { @@ -716,14 +731,20 @@ pub mod filters { Ok(name) } - pub(super) fn ffi_type(type_: &impl AsType) -> askama::Result { + pub(super) fn ffi_type( + type_: &impl AsType, + _: &dyn askama::Values, + ) -> askama::Result { Ok(type_.as_type().into()) } // To better support external types, we always call the "public" lift and lower functions for // "named" types, regardless of whether they are being called from a type in the same crate // (ie, a "local" type) or from a different crate (ie, an "external" type) - pub fn lower_fn(as_type: &impl AsType) -> Result { + pub fn lower_fn( + as_type: &impl AsType, + _: &dyn askama::Values, + ) -> Result { let ty = &as_type.as_type(); let ffi_converter_name = oracle().find(ty).ffi_converter_name(); Ok(match ty.name() { @@ -732,14 +753,17 @@ pub mod filters { }) } - pub fn write_fn(as_type: &impl AsType) -> Result { + pub fn write_fn( + as_type: &impl AsType, + _: &dyn askama::Values, + ) -> Result { let ty = &as_type.as_type(); let ffi_converter_name = oracle().find(ty).ffi_converter_name(); Ok(format!("{}.write", ffi_converter_name)) } // See above re lower_fn - we always use the public version for named types. - pub fn lift_fn(as_type: &impl AsType) -> Result { + pub fn lift_fn(as_type: &impl AsType, _: &dyn askama::Values) -> Result { let ty = &as_type.as_type(); let ffi_converter_name = oracle().find(ty).ffi_converter_name(); Ok(match ty.name() { @@ -748,7 +772,7 @@ pub mod filters { }) } - pub fn read_fn(as_type: &impl AsType) -> Result { + pub fn read_fn(as_type: &impl AsType, _: &dyn askama::Values) -> Result { let ty = &as_type.as_type(); let ffi_converter_name = oracle().find(ty).ffi_converter_name(); Ok(format!("{}.read", ffi_converter_name)) @@ -756,6 +780,7 @@ pub mod filters { pub fn default_swift( default: &DefaultValue, + _: &dyn askama::Values, as_type: &impl AsType, ) -> Result { Ok(oracle() @@ -765,7 +790,11 @@ pub mod filters { } // Get the idiomatic Swift rendering of an individual enum variant's discriminant - pub fn variant_discr_literal(e: &Enum, index: &usize) -> Result { + pub fn variant_discr_literal( + e: &Enum, + _: &dyn askama::Values, + index: &usize, + ) -> Result { let literal = e.variant_discr(*index).expect("invalid index"); match literal { LiteralMetadata::UInt(v, _, _) => Ok(v.to_string()), @@ -775,17 +804,26 @@ pub mod filters { } /// Get the Swift type for an FFIType - pub fn ffi_type_name(ffi_type: &FfiType) -> Result { + pub fn ffi_type_name( + ffi_type: &FfiType, + _: &dyn askama::Values, + ) -> Result { Ok(oracle().ffi_type_label(ffi_type)) } - pub fn ffi_default_value(return_type: Option) -> Result { + pub fn ffi_default_value( + return_type: Option, + _: &dyn askama::Values, + ) -> Result { Ok(oracle().ffi_default_value(return_type.as_ref())) } /// Like `ffi_type_name`, but used in `BridgingHeaderTemplate.h` which uses a slightly different /// names. - pub fn header_ffi_type_name(ffi_type: &FfiType) -> Result { + pub fn header_ffi_type_name( + ffi_type: &FfiType, + values: &dyn askama::Values, + ) -> Result { Ok(match ffi_type { FfiType::Int8 => "int8_t".into(), FfiType::UInt8 => "uint8_t".into(), @@ -806,61 +844,73 @@ pub mod filters { } FfiType::Struct(name) => SwiftCodeOracle.ffi_struct_name(name), FfiType::Reference(inner) => { - format!("const {}* _Nonnull", header_ffi_type_name(inner)?) + format!("const {}* _Nonnull", header_ffi_type_name(inner, values)?) + } + FfiType::MutReference(inner) => { + format!("{}* _Nonnull", header_ffi_type_name(inner, values)?) } - FfiType::MutReference(inner) => format!("{}* _Nonnull", header_ffi_type_name(inner)?), FfiType::VoidPointer => "void* _Nonnull".into(), }) } /// Get the idiomatic Swift rendering of a class name (for enums, records, errors, etc). - pub fn class_name(nm: &str) -> Result { + pub fn class_name(nm: &str, _: &dyn askama::Values) -> Result { Ok(oracle().class_name(nm)) } /// Get the idiomatic Swift rendering of a function name. - pub fn fn_name(nm: &str) -> Result { + pub fn fn_name(nm: &str, _: &dyn askama::Values) -> Result { Ok(quote_general_keyword(oracle().fn_name(nm))) } /// Get the idiomatic Swift rendering of a variable name. - pub fn var_name(nm: &str) -> Result { + pub fn var_name(nm: &str, _: &dyn askama::Values) -> Result { Ok(quote_general_keyword(oracle().var_name(nm))) } /// Get the idiomatic Swift rendering of an arguments name. /// This is the same as the var name but quoting is not required. - pub fn arg_name(nm: &str) -> Result { + pub fn arg_name(nm: &str, _: &dyn askama::Values) -> Result { Ok(quote_arg_keyword(oracle().var_name(nm))) } /// Get the idiomatic Swift rendering of an individual enum variant, quoted if it is a keyword (for use in e.g. declarations) - pub fn enum_variant_swift_quoted(nm: &str) -> Result { + pub fn enum_variant_swift_quoted( + nm: &str, + _: &dyn askama::Values, + ) -> Result { Ok(quote_general_keyword(oracle().enum_variant_name(nm))) } /// Like enum_variant_swift_quoted, but a class name. - pub fn error_variant_swift_quoted(nm: &str) -> Result { + pub fn error_variant_swift_quoted( + nm: &str, + _: &dyn askama::Values, + ) -> Result { Ok(quote_general_keyword(oracle().class_name(nm))) } /// Get the idiomatic Swift rendering of an FFI callback function name - pub fn ffi_callback_name(nm: &str) -> Result { + pub fn ffi_callback_name(nm: &str, _: &dyn askama::Values) -> Result { Ok(oracle().ffi_callback_name(nm)) } /// Get the idiomatic Swift rendering of an FFI struct name - pub fn ffi_struct_name(nm: &str) -> Result { + pub fn ffi_struct_name(nm: &str, _: &dyn askama::Values) -> Result { Ok(oracle().ffi_struct_name(nm)) } /// Get the idiomatic Swift rendering of an if guard name - pub fn if_guard_name(nm: &str) -> Result { + pub fn if_guard_name(nm: &str, _: &dyn askama::Values) -> Result { Ok(oracle().if_guard_name(nm)) } /// Get the idiomatic Swift rendering of docstring - pub fn docstring(docstring: &str, spaces: &i32) -> Result { + pub fn docstring( + docstring: &str, + _: &dyn askama::Values, + spaces: &i32, + ) -> Result { let middle = textwrap::indent(&textwrap::dedent(docstring), " * "); let wrapped = format!("/**\n{middle}\n */"); @@ -868,7 +918,10 @@ pub mod filters { Ok(textwrap::indent(&wrapped, &" ".repeat(spaces))) } - pub fn object_names(obj: &Object) -> Result<(String, String), askama::Error> { + pub fn object_names( + obj: &Object, + _: &dyn askama::Values, + ) -> Result<(String, String), askama::Error> { Ok(SwiftCodeOracle.object_names(obj)) } } diff --git a/uniffi_bindgen/src/scaffolding/mod.rs b/uniffi_bindgen/src/scaffolding/mod.rs index 78b5410ad2..46142dd327 100644 --- a/uniffi_bindgen/src/scaffolding/mod.rs +++ b/uniffi_bindgen/src/scaffolding/mod.rs @@ -23,7 +23,7 @@ impl<'a> RustScaffolding<'a> { mod filters { use super::*; - pub fn type_rs(type_: &Type) -> Result { + pub fn type_rs(type_: &Type, values: &dyn askama::Values) -> Result { Ok(match type_ { Type::Int8 => "i8".into(), Type::UInt8 => "u8".into(), @@ -46,16 +46,18 @@ mod filters { } Type::CallbackInterface { name, .. } => format!("Box"), Type::Optional { inner_type } => { - format!("::std::option::Option<{}>", type_rs(inner_type)?) + format!("::std::option::Option<{}>", type_rs(inner_type, values)?) + } + Type::Sequence { inner_type } => { + format!("std::vec::Vec<{}>", type_rs(inner_type, values)?) } - Type::Sequence { inner_type } => format!("std::vec::Vec<{}>", type_rs(inner_type)?), Type::Map { key_type, value_type, } => format!( "::std::collections::HashMap<{}, {}>", - type_rs(key_type)?, - type_rs(value_type)? + type_rs(key_type, values)?, + type_rs(value_type, values)? ), Type::Custom { name, .. } => format!("r#{name}"), })