Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion uniffi_bindgen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
93 changes: 74 additions & 19 deletions uniffi_bindgen/src/bindings/kotlin/gen_kotlin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,54 +619,80 @@ mod filters {

pub(super) fn type_name(
as_ct: &impl AsCodeType,
_: &dyn askama::Values,
ci: &ComponentInterface,
) -> Result<String, askama::Error> {
Ok(as_ct.as_codetype().type_label(ci))
}

pub(super) fn canonical_name(as_ct: &impl AsCodeType) -> Result<String, askama::Error> {
pub(super) fn canonical_name(
as_ct: &impl AsCodeType,
_: &dyn askama::Values,
) -> Result<String, askama::Error> {
Ok(as_ct.as_codetype().canonical_name())
}

pub(super) fn ffi_converter_name(as_ct: &impl AsCodeType) -> Result<String, askama::Error> {
pub(super) fn ffi_converter_name(
as_ct: &impl AsCodeType,
_: &dyn askama::Values,
) -> Result<String, askama::Error> {
Ok(as_ct.as_codetype().ffi_converter_name())
}

pub(super) fn ffi_type(type_: &impl AsType) -> askama::Result<FfiType, askama::Error> {
pub(super) fn ffi_type(
type_: &impl AsType,
_: &dyn askama::Values,
) -> askama::Result<FfiType, askama::Error> {
Ok(type_.as_type().into())
}

pub(super) fn lower_fn(as_ct: &impl AsCodeType) -> Result<String, askama::Error> {
pub(super) fn lower_fn(
as_ct: &impl AsCodeType,
_: &dyn askama::Values,
) -> Result<String, askama::Error> {
Ok(format!(
"{}.lower",
as_ct.as_codetype().ffi_converter_name()
))
}

pub(super) fn allocation_size_fn(as_ct: &impl AsCodeType) -> Result<String, askama::Error> {
pub(super) fn allocation_size_fn(
as_ct: &impl AsCodeType,
_: &dyn askama::Values,
) -> Result<String, askama::Error> {
Ok(format!(
"{}.allocationSize",
as_ct.as_codetype().ffi_converter_name()
))
}

pub(super) fn write_fn(as_ct: &impl AsCodeType) -> Result<String, askama::Error> {
pub(super) fn write_fn(
as_ct: &impl AsCodeType,
_: &dyn askama::Values,
) -> Result<String, askama::Error> {
Ok(format!(
"{}.write",
as_ct.as_codetype().ffi_converter_name()
))
}

pub(super) fn lift_fn(as_ct: &impl AsCodeType) -> Result<String, askama::Error> {
pub(super) fn lift_fn(
as_ct: &impl AsCodeType,
_: &dyn askama::Values,
) -> Result<String, askama::Error> {
Ok(format!("{}.lift", as_ct.as_codetype().ffi_converter_name()))
}

pub(super) fn read_fn(as_ct: &impl AsCodeType) -> Result<String, askama::Error> {
pub(super) fn read_fn(
as_ct: &impl AsCodeType,
_: &dyn askama::Values,
) -> Result<String, askama::Error> {
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<String, askama::Error> {
Expand Down Expand Up @@ -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<String, askama::Error> {
pub fn variant_discr_literal(
e: &Enum,
_: &dyn askama::Values,
index: &usize,
) -> Result<String, askama::Error> {
let literal = e.variant_discr(*index).expect("invalid index");
match literal {
// Kotlin doesn't convert between signed and unsigned by default
Expand All @@ -709,67 +739,86 @@ mod filters {

pub fn ffi_type_name_by_value(
type_: &FfiType,
_: &dyn askama::Values,
ci: &ComponentInterface,
) -> Result<String, askama::Error> {
Ok(KotlinCodeOracle.ffi_type_label_by_value(type_, ci))
}

pub fn ffi_type_name_for_ffi_struct(
type_: &FfiType,
_: &dyn askama::Values,
ci: &ComponentInterface,
) -> Result<String, askama::Error> {
Ok(KotlinCodeOracle.ffi_type_label_for_ffi_struct(type_, ci))
}

pub fn ffi_default_value(type_: FfiType) -> Result<String, askama::Error> {
pub fn ffi_default_value(
type_: FfiType,
_: &dyn askama::Values,
) -> Result<String, askama::Error> {
Ok(KotlinCodeOracle.ffi_default_value(&type_))
}

/// Get the idiomatic Kotlin rendering of a function name.
pub fn class_name<S: AsRef<str>>(
nm: S,
_: &dyn askama::Values,
ci: &ComponentInterface,
) -> Result<String, askama::Error> {
Ok(KotlinCodeOracle.class_name(ci, nm.as_ref()))
}

/// Get the idiomatic Kotlin rendering of a function name.
pub fn fn_name<S: AsRef<str>>(nm: S) -> Result<String, askama::Error> {
pub fn fn_name<S: AsRef<str>>(nm: S, _: &dyn askama::Values) -> Result<String, askama::Error> {
Ok(KotlinCodeOracle.fn_name(nm.as_ref()))
}

/// Get the idiomatic Kotlin rendering of a variable name.
pub fn var_name<S: AsRef<str>>(nm: S) -> Result<String, askama::Error> {
pub fn var_name<S: AsRef<str>>(nm: S, _: &dyn askama::Values) -> Result<String, askama::Error> {
Ok(KotlinCodeOracle.var_name(nm.as_ref()))
}

/// Get the idiomatic Kotlin rendering of a variable name.
pub fn var_name_raw<S: AsRef<str>>(nm: S) -> Result<String, askama::Error> {
pub fn var_name_raw<S: AsRef<str>>(
nm: S,
_: &dyn askama::Values,
) -> Result<String, askama::Error> {
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<String, askama::Error> {
pub fn variant_name(v: &Variant, _: &dyn askama::Values) -> Result<String, askama::Error> {
Ok(KotlinCodeOracle.enum_variant_name(v.name()))
}

pub fn error_variant_name(v: &Variant) -> Result<String, askama::Error> {
pub fn error_variant_name(
v: &Variant,
_: &dyn askama::Values,
) -> Result<String, askama::Error> {
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<S: AsRef<str>>(nm: S) -> Result<String, askama::Error> {
pub fn ffi_callback_name<S: AsRef<str>>(
nm: S,
_: &dyn askama::Values,
) -> Result<String, askama::Error> {
Ok(KotlinCodeOracle.ffi_callback_name(nm.as_ref()))
}

/// Get the idiomatic Kotlin rendering of an FFI struct name
pub fn ffi_struct_name<S: AsRef<str>>(nm: S) -> Result<String, askama::Error> {
pub fn ffi_struct_name<S: AsRef<str>>(
nm: S,
_: &dyn askama::Values,
) -> Result<String, askama::Error> {
Ok(KotlinCodeOracle.ffi_struct_name(nm.as_ref()))
}

pub fn async_poll(
callable: impl Callable,
_: &dyn askama::Values,
ci: &ComponentInterface,
) -> Result<String, askama::Error> {
let ffi_func = callable.ffi_rust_future_poll(ci);
Expand All @@ -780,6 +829,7 @@ mod filters {

pub fn async_complete(
callable: impl Callable,
_: &dyn askama::Values,
ci: &ComponentInterface,
) -> Result<String, askama::Error> {
let ffi_func = callable.ffi_rust_future_complete(ci);
Expand All @@ -803,6 +853,7 @@ mod filters {

pub fn async_free(
callable: impl Callable,
_: &dyn askama::Values,
ci: &ComponentInterface,
) -> Result<String, askama::Error> {
let ffi_func = callable.ffi_rust_future_free(ci);
Expand All @@ -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<S: AsRef<str>>(nm: S) -> Result<String, askama::Error> {
pub fn unquote<S: AsRef<str>>(nm: S, _: &dyn askama::Values) -> Result<String, askama::Error> {
Ok(nm.as_ref().trim_matches('`').to_string())
}

/// Get the idiomatic Kotlin rendering of docstring
pub fn docstring<S: AsRef<str>>(docstring: S, spaces: &i32) -> Result<String, askama::Error> {
pub fn docstring<S: AsRef<str>>(
docstring: S,
_: &dyn askama::Values,
spaces: &i32,
) -> Result<String, askama::Error> {
let middle = textwrap::indent(&textwrap::dedent(docstring.as_ref()), " * ");
let wrapped = format!("/**\n{middle}\n */");

Expand Down
6 changes: 5 additions & 1 deletion uniffi_bindgen/src/bindings/python/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>, indent: usize) -> Result<String> {
pub fn docstring(
docstring: &Option<String>,
_: &dyn askama::Values,
indent: usize,
) -> Result<String> {
let Some(docstring) = docstring.as_deref() else {
return Ok("".to_string());
};
Expand Down
Loading