Skip to content

Commit c89bc2d

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 86a3408 commit c89bc2d

File tree

7 files changed

+219
-82
lines changed

7 files changed

+219
-82
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: 75 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -634,17 +634,22 @@ mod filters {
634634

635635
pub(super) fn type_name(
636636
as_ct: &impl AsCodeType,
637+
_: &dyn askama::Values,
637638
ci: &ComponentInterface,
638639
) -> Result<String, askama::Error> {
639640
Ok(as_ct.as_codetype().type_label(ci))
640641
}
641642

642-
pub(super) fn canonical_name(as_ct: &impl AsCodeType) -> Result<String, askama::Error> {
643+
pub(super) fn canonical_name(
644+
as_ct: &impl AsCodeType,
645+
_: &dyn askama::Values,
646+
) -> Result<String, askama::Error> {
643647
Ok(as_ct.as_codetype().canonical_name())
644648
}
645649

646650
pub(super) fn qualified_type_name<T>(
647651
as_type: &T,
652+
_: &dyn askama::Values,
648653
ci: &ComponentInterface,
649654
config: &Config,
650655
) -> Result<String, askama::Error>
@@ -655,40 +660,61 @@ mod filters {
655660
.map_err(|err| to_askama_error(&err))
656661
}
657662

658-
pub(super) fn ffi_converter_name(as_ct: &impl AsCodeType) -> Result<String, askama::Error> {
663+
pub(super) fn ffi_converter_name(
664+
as_ct: &impl AsCodeType,
665+
_: &dyn askama::Values,
666+
) -> Result<String, askama::Error> {
659667
Ok(as_ct.as_codetype().ffi_converter_name())
660668
}
661669

662-
pub(super) fn ffi_type(type_: &impl AsType) -> askama::Result<FfiType, askama::Error> {
670+
pub(super) fn ffi_type(
671+
type_: &impl AsType,
672+
_: &dyn askama::Values,
673+
) -> askama::Result<FfiType, askama::Error> {
663674
Ok(type_.as_type().into())
664675
}
665676

666-
pub(super) fn lower_fn(as_ct: &impl AsCodeType) -> Result<String, askama::Error> {
677+
pub(super) fn lower_fn(
678+
as_ct: &impl AsCodeType,
679+
_: &dyn askama::Values,
680+
) -> Result<String, askama::Error> {
667681
Ok(format!(
668682
"{}.lower",
669683
as_ct.as_codetype().ffi_converter_name()
670684
))
671685
}
672686

673-
pub(super) fn allocation_size_fn(as_ct: &impl AsCodeType) -> Result<String, askama::Error> {
687+
pub(super) fn allocation_size_fn(
688+
as_ct: &impl AsCodeType,
689+
_: &dyn askama::Values,
690+
) -> Result<String, askama::Error> {
674691
Ok(format!(
675692
"{}.allocationSize",
676693
as_ct.as_codetype().ffi_converter_name()
677694
))
678695
}
679696

680-
pub(super) fn write_fn(as_ct: &impl AsCodeType) -> Result<String, askama::Error> {
697+
pub(super) fn write_fn(
698+
as_ct: &impl AsCodeType,
699+
_: &dyn askama::Values,
700+
) -> Result<String, askama::Error> {
681701
Ok(format!(
682702
"{}.write",
683703
as_ct.as_codetype().ffi_converter_name()
684704
))
685705
}
686706

687-
pub(super) fn lift_fn(as_ct: &impl AsCodeType) -> Result<String, askama::Error> {
707+
pub(super) fn lift_fn(
708+
as_ct: &impl AsCodeType,
709+
_: &dyn askama::Values,
710+
) -> Result<String, askama::Error> {
688711
Ok(format!("{}.lift", as_ct.as_codetype().ffi_converter_name()))
689712
}
690713

691-
pub(super) fn read_fn(as_ct: &impl AsCodeType) -> Result<String, askama::Error> {
714+
pub(super) fn read_fn(
715+
as_ct: &impl AsCodeType,
716+
_: &dyn askama::Values,
717+
) -> Result<String, askama::Error> {
692718
Ok(format!("{}.read", as_ct.as_codetype().ffi_converter_name()))
693719
}
694720

@@ -744,6 +770,7 @@ mod filters {
744770

745771
pub fn render_default(
746772
default: &DefaultValue,
773+
_: &dyn askama::Values,
747774
as_ct: &impl AsType,
748775
ci: &ComponentInterface,
749776
) -> Result<String, askama::Error> {
@@ -771,7 +798,11 @@ mod filters {
771798
}
772799

773800
// Get the idiomatic Kotlin rendering of an individual enum variant's discriminant
774-
pub fn variant_discr_literal(e: &Enum, index: &usize) -> Result<String, askama::Error> {
801+
pub fn variant_discr_literal(
802+
e: &Enum,
803+
_: &dyn askama::Values,
804+
index: &usize,
805+
) -> Result<String, askama::Error> {
775806
let literal = e.variant_discr(*index).expect("invalid index");
776807
match literal {
777808
// Kotlin doesn't convert between signed and unsigned by default
@@ -786,67 +817,86 @@ mod filters {
786817

787818
pub fn ffi_type_name_by_value(
788819
type_: &FfiType,
820+
_: &dyn askama::Values,
789821
ci: &ComponentInterface,
790822
) -> Result<String, askama::Error> {
791823
Ok(KotlinCodeOracle.ffi_type_label_by_value(type_, ci))
792824
}
793825

794826
pub fn ffi_type_name_for_ffi_struct(
795827
type_: &FfiType,
828+
_: &dyn askama::Values,
796829
ci: &ComponentInterface,
797830
) -> Result<String, askama::Error> {
798831
Ok(KotlinCodeOracle.ffi_type_label_for_ffi_struct(type_, ci))
799832
}
800833

801-
pub fn ffi_default_value(type_: FfiType) -> Result<String, askama::Error> {
834+
pub fn ffi_default_value(
835+
type_: FfiType,
836+
_: &dyn askama::Values,
837+
) -> Result<String, askama::Error> {
802838
Ok(KotlinCodeOracle.ffi_default_value(&type_))
803839
}
804840

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

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

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

823860
/// Get the idiomatic Kotlin rendering of a variable name.
824-
pub fn var_name_raw<S: AsRef<str>>(nm: S) -> Result<String, askama::Error> {
861+
pub fn var_name_raw<S: AsRef<str>>(
862+
nm: S,
863+
_: &dyn askama::Values,
864+
) -> Result<String, askama::Error> {
825865
Ok(KotlinCodeOracle.var_name_raw(nm.as_ref()))
826866
}
827867

828868
/// Get a String representing the name used for an individual enum variant.
829-
pub fn variant_name(v: &Variant) -> Result<String, askama::Error> {
869+
pub fn variant_name(v: &Variant, _: &dyn askama::Values) -> Result<String, askama::Error> {
830870
Ok(KotlinCodeOracle.enum_variant_name(v.name()))
831871
}
832872

833-
pub fn error_variant_name(v: &Variant) -> Result<String, askama::Error> {
873+
pub fn error_variant_name(
874+
v: &Variant,
875+
_: &dyn askama::Values,
876+
) -> Result<String, askama::Error> {
834877
let name = v.name().to_string().to_upper_camel_case();
835878
Ok(KotlinCodeOracle.convert_error_suffix(&name))
836879
}
837880

838881
/// Get the idiomatic Kotlin rendering of an FFI callback function name
839-
pub fn ffi_callback_name<S: AsRef<str>>(nm: S) -> Result<String, askama::Error> {
882+
pub fn ffi_callback_name<S: AsRef<str>>(
883+
nm: S,
884+
_: &dyn askama::Values,
885+
) -> Result<String, askama::Error> {
840886
Ok(KotlinCodeOracle.ffi_callback_name(nm.as_ref()))
841887
}
842888

843889
/// Get the idiomatic Kotlin rendering of an FFI struct name
844-
pub fn ffi_struct_name<S: AsRef<str>>(nm: S) -> Result<String, askama::Error> {
890+
pub fn ffi_struct_name<S: AsRef<str>>(
891+
nm: S,
892+
_: &dyn askama::Values,
893+
) -> Result<String, askama::Error> {
845894
Ok(KotlinCodeOracle.ffi_struct_name(nm.as_ref()))
846895
}
847896

848897
pub fn async_poll(
849898
callable: impl Callable,
899+
_: &dyn askama::Values,
850900
ci: &ComponentInterface,
851901
) -> Result<String, askama::Error> {
852902
let ffi_func = callable.ffi_rust_future_poll(ci);
@@ -857,6 +907,7 @@ mod filters {
857907

858908
pub fn async_complete(
859909
callable: impl Callable,
910+
_: &dyn askama::Values,
860911
ci: &ComponentInterface,
861912
) -> Result<String, askama::Error> {
862913
let ffi_func = callable.ffi_rust_future_complete(ci);
@@ -880,6 +931,7 @@ mod filters {
880931

881932
pub fn async_free(
882933
callable: impl Callable,
934+
_: &dyn askama::Values,
883935
ci: &ComponentInterface,
884936
) -> Result<String, askama::Error> {
885937
let ffi_func = callable.ffi_rust_future_free(ci);
@@ -891,12 +943,16 @@ mod filters {
891943
/// These are used to avoid name clashes with kotlin identifiers, but sometimes you want to
892944
/// render the name unquoted. One example is the message property for errors where we want to
893945
/// display the name for the user.
894-
pub fn unquote<S: AsRef<str>>(nm: S) -> Result<String, askama::Error> {
946+
pub fn unquote<S: AsRef<str>>(nm: S, _: &dyn askama::Values) -> Result<String, askama::Error> {
895947
Ok(nm.as_ref().trim_matches('`').to_string())
896948
}
897949

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

uniffi_bindgen/src/bindings/python/filters.rs

Lines changed: 6 additions & 2 deletions
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
};
@@ -32,7 +36,7 @@ pub fn docstring(docstring: &Option<String>, indent: usize) -> Result<String> {
3236
}
3337

3438
/// Get the idiomatic Python import statement for a module
35-
pub fn import_statement(module: &str) -> Result<String> {
39+
pub fn import_statement(module: &str, _: &dyn askama::Values) -> Result<String> {
3640
Ok(if module.starts_with('.') {
3741
let Some((from, name)) = module.rsplit_once('.') else {
3842
unreachable!()

0 commit comments

Comments
 (0)