Skip to content

Commit 43c4b52

Browse files
committed
askama 0.13->0.14. Significant as all filter function signatures change.
All filter functions now take at least 2 args; the new 2nd arg is now typically `_: &dyn askama::Values`.
1 parent c66ce86 commit 43c4b52

File tree

7 files changed

+217
-81
lines changed

7 files changed

+217
-81
lines changed

Cargo.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

uniffi_bindgen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ ffi-trace = ["uniffi_testing?/ffi-trace"]
1818

1919
[dependencies]
2020
anyhow = "1"
21-
askama = { version = "0.13.0", default-features = false, features = ["config", "derive", "alloc"] }
21+
askama = { version = "0.14", default-features = false, features = ["config", "derive", "alloc"] }
2222
camino = "1.0.8"
2323
cargo_metadata = { version = "0.19", optional = true }
2424
fs-err = "2.7.0"

uniffi_bindgen/src/bindings/kotlin/gen_kotlin/mod.rs

Lines changed: 74 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -619,54 +619,80 @@ mod filters {
619619

620620
pub(super) fn type_name(
621621
as_ct: &impl AsCodeType,
622+
_: &dyn askama::Values,
622623
ci: &ComponentInterface,
623624
) -> Result<String, askama::Error> {
624625
Ok(as_ct.as_codetype().type_label(ci))
625626
}
626627

627-
pub(super) fn canonical_name(as_ct: &impl AsCodeType) -> Result<String, askama::Error> {
628+
pub(super) fn canonical_name(
629+
as_ct: &impl AsCodeType,
630+
_: &dyn askama::Values,
631+
) -> Result<String, askama::Error> {
628632
Ok(as_ct.as_codetype().canonical_name())
629633
}
630634

631-
pub(super) fn ffi_converter_name(as_ct: &impl AsCodeType) -> Result<String, askama::Error> {
635+
pub(super) fn ffi_converter_name(
636+
as_ct: &impl AsCodeType,
637+
_: &dyn askama::Values,
638+
) -> Result<String, askama::Error> {
632639
Ok(as_ct.as_codetype().ffi_converter_name())
633640
}
634641

635-
pub(super) fn ffi_type(type_: &impl AsType) -> askama::Result<FfiType, askama::Error> {
642+
pub(super) fn ffi_type(
643+
type_: &impl AsType,
644+
_: &dyn askama::Values,
645+
) -> askama::Result<FfiType, askama::Error> {
636646
Ok(type_.as_type().into())
637647
}
638648

639-
pub(super) fn lower_fn(as_ct: &impl AsCodeType) -> Result<String, askama::Error> {
649+
pub(super) fn lower_fn(
650+
as_ct: &impl AsCodeType,
651+
_: &dyn askama::Values,
652+
) -> Result<String, askama::Error> {
640653
Ok(format!(
641654
"{}.lower",
642655
as_ct.as_codetype().ffi_converter_name()
643656
))
644657
}
645658

646-
pub(super) fn allocation_size_fn(as_ct: &impl AsCodeType) -> Result<String, askama::Error> {
659+
pub(super) fn allocation_size_fn(
660+
as_ct: &impl AsCodeType,
661+
_: &dyn askama::Values,
662+
) -> Result<String, askama::Error> {
647663
Ok(format!(
648664
"{}.allocationSize",
649665
as_ct.as_codetype().ffi_converter_name()
650666
))
651667
}
652668

653-
pub(super) fn write_fn(as_ct: &impl AsCodeType) -> Result<String, askama::Error> {
669+
pub(super) fn write_fn(
670+
as_ct: &impl AsCodeType,
671+
_: &dyn askama::Values,
672+
) -> Result<String, askama::Error> {
654673
Ok(format!(
655674
"{}.write",
656675
as_ct.as_codetype().ffi_converter_name()
657676
))
658677
}
659678

660-
pub(super) fn lift_fn(as_ct: &impl AsCodeType) -> Result<String, askama::Error> {
679+
pub(super) fn lift_fn(
680+
as_ct: &impl AsCodeType,
681+
_: &dyn askama::Values,
682+
) -> Result<String, askama::Error> {
661683
Ok(format!("{}.lift", as_ct.as_codetype().ffi_converter_name()))
662684
}
663685

664-
pub(super) fn read_fn(as_ct: &impl AsCodeType) -> Result<String, askama::Error> {
686+
pub(super) fn read_fn(
687+
as_ct: &impl AsCodeType,
688+
_: &dyn askama::Values,
689+
) -> Result<String, askama::Error> {
665690
Ok(format!("{}.read", as_ct.as_codetype().ffi_converter_name()))
666691
}
667692

668693
pub fn render_default(
669694
default: &DefaultValue,
695+
_: &dyn askama::Values,
670696
as_ct: &impl AsType,
671697
ci: &ComponentInterface,
672698
) -> Result<String, askama::Error> {
@@ -694,7 +720,11 @@ mod filters {
694720
}
695721

696722
// Get the idiomatic Kotlin rendering of an individual enum variant's discriminant
697-
pub fn variant_discr_literal(e: &Enum, index: &usize) -> Result<String, askama::Error> {
723+
pub fn variant_discr_literal(
724+
e: &Enum,
725+
_: &dyn askama::Values,
726+
index: &usize,
727+
) -> Result<String, askama::Error> {
698728
let literal = e.variant_discr(*index).expect("invalid index");
699729
match literal {
700730
// Kotlin doesn't convert between signed and unsigned by default
@@ -709,67 +739,86 @@ mod filters {
709739

710740
pub fn ffi_type_name_by_value(
711741
type_: &FfiType,
742+
_: &dyn askama::Values,
712743
ci: &ComponentInterface,
713744
) -> Result<String, askama::Error> {
714745
Ok(KotlinCodeOracle.ffi_type_label_by_value(type_, ci))
715746
}
716747

717748
pub fn ffi_type_name_for_ffi_struct(
718749
type_: &FfiType,
750+
_: &dyn askama::Values,
719751
ci: &ComponentInterface,
720752
) -> Result<String, askama::Error> {
721753
Ok(KotlinCodeOracle.ffi_type_label_for_ffi_struct(type_, ci))
722754
}
723755

724-
pub fn ffi_default_value(type_: FfiType) -> Result<String, askama::Error> {
756+
pub fn ffi_default_value(
757+
type_: FfiType,
758+
_: &dyn askama::Values,
759+
) -> Result<String, askama::Error> {
725760
Ok(KotlinCodeOracle.ffi_default_value(&type_))
726761
}
727762

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

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

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

746782
/// Get the idiomatic Kotlin rendering of a variable name.
747-
pub fn var_name_raw<S: AsRef<str>>(nm: S) -> Result<String, askama::Error> {
783+
pub fn var_name_raw<S: AsRef<str>>(
784+
nm: S,
785+
_: &dyn askama::Values,
786+
) -> Result<String, askama::Error> {
748787
Ok(KotlinCodeOracle.var_name_raw(nm.as_ref()))
749788
}
750789

751790
/// Get a String representing the name used for an individual enum variant.
752-
pub fn variant_name(v: &Variant) -> Result<String, askama::Error> {
791+
pub fn variant_name(v: &Variant, _: &dyn askama::Values) -> Result<String, askama::Error> {
753792
Ok(KotlinCodeOracle.enum_variant_name(v.name()))
754793
}
755794

756-
pub fn error_variant_name(v: &Variant) -> Result<String, askama::Error> {
795+
pub fn error_variant_name(
796+
v: &Variant,
797+
_: &dyn askama::Values,
798+
) -> Result<String, askama::Error> {
757799
let name = v.name().to_string().to_upper_camel_case();
758800
Ok(KotlinCodeOracle.convert_error_suffix(&name))
759801
}
760802

761803
/// Get the idiomatic Kotlin rendering of an FFI callback function name
762-
pub fn ffi_callback_name<S: AsRef<str>>(nm: S) -> Result<String, askama::Error> {
804+
pub fn ffi_callback_name<S: AsRef<str>>(
805+
nm: S,
806+
_: &dyn askama::Values,
807+
) -> Result<String, askama::Error> {
763808
Ok(KotlinCodeOracle.ffi_callback_name(nm.as_ref()))
764809
}
765810

766811
/// Get the idiomatic Kotlin rendering of an FFI struct name
767-
pub fn ffi_struct_name<S: AsRef<str>>(nm: S) -> Result<String, askama::Error> {
812+
pub fn ffi_struct_name<S: AsRef<str>>(
813+
nm: S,
814+
_: &dyn askama::Values,
815+
) -> Result<String, askama::Error> {
768816
Ok(KotlinCodeOracle.ffi_struct_name(nm.as_ref()))
769817
}
770818

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

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

804854
pub fn async_free(
805855
callable: impl Callable,
856+
_: &dyn askama::Values,
806857
ci: &ComponentInterface,
807858
) -> Result<String, askama::Error> {
808859
let ffi_func = callable.ffi_rust_future_free(ci);
@@ -816,12 +867,16 @@ mod filters {
816867
/// These are used to avoid name clashes with kotlin identifiers, but sometimes you want to
817868
/// render the name unquoted. One example is the message property for errors where we want to
818869
/// display the name for the user.
819-
pub fn unquote<S: AsRef<str>>(nm: S) -> Result<String, askama::Error> {
870+
pub fn unquote<S: AsRef<str>>(nm: S, _: &dyn askama::Values) -> Result<String, askama::Error> {
820871
Ok(nm.as_ref().trim_matches('`').to_string())
821872
}
822873

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

uniffi_bindgen/src/bindings/python/filters.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ use askama::Result;
1919
///
2020
/// This makes it so the template code can use something like
2121
/// `{{ item.docstring|docstring(4) -}}` to render the correct docstring in both cases.
22-
pub fn docstring(docstring: &Option<String>, indent: usize) -> Result<String> {
22+
pub fn docstring(
23+
docstring: &Option<String>,
24+
_: &dyn askama::Values,
25+
indent: usize,
26+
) -> Result<String> {
2327
let Some(docstring) = docstring.as_deref() else {
2428
return Ok("".to_string());
2529
};

0 commit comments

Comments
 (0)