diff --git a/fixtures/futures/src/lib.rs b/fixtures/futures/src/lib.rs index 17a4f8e..215fbe8 100644 --- a/fixtures/futures/src/lib.rs +++ b/fixtures/futures/src/lib.rs @@ -193,5 +193,5 @@ pub async fn broken_sleep(ms: u16, fail_after: u16) { ) .await; } - + uniffi::include_scaffolding!("api"); diff --git a/fixtures/large_enum/src/lib.rs b/fixtures/large_enum/src/lib.rs index a19ef23..3c2c0d0 100644 --- a/fixtures/large_enum/src/lib.rs +++ b/fixtures/large_enum/src/lib.rs @@ -105,7 +105,7 @@ pub fn new_public_key_value(value: Vec) -> Value { // #[uniffi::export] // pub fn new_map(value: HashMap) -> MapEntry { -// todo!("Not done") +// todo!("Not done") // } #[uniffi::export] diff --git a/src/build.rs b/src/build.rs index 4fc9da7..6db0a2e 100644 --- a/src/build.rs +++ b/src/build.rs @@ -16,4 +16,3 @@ pub fn generate_scaffolding(udl_file: &Utf8Path) -> Result<()> { )?; Ok(()) } - diff --git a/src/gen/compounds.rs b/src/gen/compounds.rs index 77b34f8..0d85897 100644 --- a/src/gen/compounds.rs +++ b/src/gen/compounds.rs @@ -182,4 +182,3 @@ impl_code_type_for_compound!(SequenceCodeType, "List<{}>", "Sequence{}"); impl_renderable_for_compound!(OptionalCodeType, "{}?", "FfiConverterOptional{}"); impl_renderable_for_compound!(SequenceCodeType, "FfiConverterSequence{}"); - diff --git a/src/gen/enums.rs b/src/gen/enums.rs index 9cb5005..dd86b2a 100644 --- a/src/gen/enums.rs +++ b/src/gen/enums.rs @@ -175,4 +175,3 @@ pub fn generate_enum(obj: &Enum, type_helper: &dyn TypeHelperRenderer) -> dart:: } } } - diff --git a/src/gen/functions.rs b/src/gen/functions.rs index 4622b33..516821e 100644 --- a/src/gen/functions.rs +++ b/src/gen/functions.rs @@ -1,4 +1,3 @@ - use genco::prelude::*; use uniffi_bindgen::backend::Type; use uniffi_bindgen::interface::{AsType, Callable, ExternalKind, Function}; diff --git a/src/gen/mod.rs b/src/gen/mod.rs index 47101c5..696c8ee 100644 --- a/src/gen/mod.rs +++ b/src/gen/mod.rs @@ -7,10 +7,10 @@ use genco::fmt; use genco::prelude::*; use serde::{Deserialize, Serialize}; // use uniffi_bindgen::MergeWith; -use crate::gen::oracle::DartCodeOracle; -use uniffi_bindgen::{BindingGenerator, BindingsConfig, ComponentInterface}; use self::render::Renderer; use self::types::TypeHelpersRenderer; +use crate::gen::oracle::DartCodeOracle; +use uniffi_bindgen::{BindingGenerator, BindingsConfig, ComponentInterface}; mod compounds; mod enums; @@ -135,8 +135,9 @@ impl<'a> DartWrapper<'a> { native_args.append( quote!($(DartCodeOracle::ffi_native_type_label(Some(&arg.type_()))),), ); - dart_args - .append(quote!($(DartCodeOracle::ffi_dart_type_label(Some(&arg.type_()))),)); + dart_args.append( + quote!($(DartCodeOracle::ffi_dart_type_label(Some(&arg.type_()))),), + ); } if fun.has_rust_call_status_arg() { diff --git a/src/gen/objects.rs b/src/gen/objects.rs index c828357..815e9a7 100644 --- a/src/gen/objects.rs +++ b/src/gen/objects.rs @@ -1,9 +1,8 @@ - use genco::prelude::*; use uniffi_bindgen::backend::{CodeType, Literal}; use uniffi_bindgen::interface::{AsType, Method, Object}; -use crate::gen::oracle::{DartCodeOracle, AsCodeType}; +use crate::gen::oracle::{AsCodeType, DartCodeOracle}; use crate::gen::render::AsRenderable; use crate::gen::render::{Renderable, TypeHelperRenderer}; @@ -82,7 +81,7 @@ pub fn generate_object(obj: &Object, type_helper: &dyn TypeHelperRenderer) -> da } #[allow(unused_variables)] -pub fn generate_method(func: &Method, type_helper: &dyn TypeHelperRenderer) -> dart::Tokens { +pub fn generate_method(func: &Method, type_helper: &dyn TypeHelperRenderer) -> dart::Tokens { // let api = "_api"; // let ffi = fun.ffi_func(); // let fn_name = fn_name(fun.name()); @@ -166,4 +165,4 @@ pub fn generate_method(func: &Method, type_helper: &dyn TypeHelperRenderer) -> d } ) } -} \ No newline at end of file +} diff --git a/src/gen/oracle.rs b/src/gen/oracle.rs index 4459481..21e285e 100644 --- a/src/gen/oracle.rs +++ b/src/gen/oracle.rs @@ -26,7 +26,6 @@ impl DartCodeOracle { panic!("unsupported type for error: {type_:?}") } - /// Sanitize a Dart identifier, appending an underscore if it's a reserved keyword. pub fn sanitize_identifier(id: &str) -> String { if Self::is_reserved_identifier(id) { @@ -63,7 +62,10 @@ impl DartCodeOracle { /// Get the idiomatic Dart rendering of an FFI callback function name fn ffi_callback_name(nm: &str) -> String { - format!("Pointer>", nm.to_upper_camel_case()) + format!( + "Pointer>", + nm.to_upper_camel_case() + ) } /// Get the idiomatic Dart rendering of an exception name @@ -85,15 +87,15 @@ impl DartCodeOracle { return quote!(void); }; match ret_type { - FfiType::UInt8 | - FfiType::UInt16 | - FfiType::UInt32 | - FfiType::UInt64 | - FfiType::Int8 | - FfiType::Int16 | - FfiType::Int32 | - FfiType::Handle | - FfiType::Int64 => quote!(int), + FfiType::UInt8 + | FfiType::UInt16 + | FfiType::UInt32 + | FfiType::UInt64 + | FfiType::Int8 + | FfiType::Int16 + | FfiType::Int32 + | FfiType::Handle + | FfiType::Int64 => quote!(int), FfiType::Float32 | FfiType::Float64 => quote!(double), FfiType::RustBuffer(ref inner) => match inner { Some(i) => quote!($i), @@ -101,14 +103,14 @@ impl DartCodeOracle { }, FfiType::ForeignBytes => quote!(ForeignBytes), FfiType::RustArcPtr(_) => quote!(Pointer), - FfiType::Callback (name) => quote!($(Self::ffi_callback_name(name))), + FfiType::Callback(name) => quote!($(Self::ffi_callback_name(name))), _ => todo!("FfiType::{:?}", ret_type), } } - + pub fn ffi_native_type_label(ffi_ret_type: Option<&FfiType>) -> dart::Tokens { let Some(ret_type) = ffi_ret_type else { - return quote!(Void) + return quote!(Void); }; match ret_type { FfiType::UInt8 => quote!(Uint8), @@ -128,7 +130,7 @@ impl DartCodeOracle { }, FfiType::ForeignBytes => quote!(ForeignBytes), FfiType::RustArcPtr(_) => quote!(Pointer), - FfiType::Callback (name) => quote!($(Self::ffi_callback_name(name))), + FfiType::Callback(name) => quote!($(Self::ffi_callback_name(name))), _ => todo!("FfiType::{:?}", ret_type), } } @@ -169,7 +171,9 @@ impl DartCodeOracle { | Type::Object { .. } | Type::Enum { .. } | Type::Record { .. } - | Type::Optional { .. } => quote!($(ty.as_codetype().ffi_converter_name()).lift($inner)), + | Type::Optional { .. } => { + quote!($(ty.as_codetype().ffi_converter_name()).lift($inner)) + } _ => todo!("lift Type::{:?}", ty), } } @@ -193,7 +197,9 @@ impl DartCodeOracle { | Type::Enum { .. } | Type::Optional { .. } | Type::Record { .. } - | Type::Sequence { .. } => quote!($(ty.as_codetype().ffi_converter_name()).lower($inner)), + | Type::Sequence { .. } => { + quote!($(ty.as_codetype().ffi_converter_name()).lower($inner)) + } _ => todo!("lower Type::{:?}", ty), } } @@ -225,16 +231,71 @@ impl DartCodeOracle { } } - // https://dart.dev/guides/language/language-tour#keywords pub static RESERVED_IDENTIFIERS: [&str; 63] = [ - "abstract", "as", "assert", "async", "await", "break", "case", "catch", "class", "const", - "continue", "covariant", "default", "deferred", "do", "dynamic", "else", "enum", "export", - "extends", "extension", "external", "factory", "false", "final", "finally", "for", "Function", - "get", "hide", "if", "implements", "import", "in", "interface", "is", "late", "library", - "mixin", "new", "null", "on", "operator", "part", "required", "rethrow", "return", "set", - "show", "static", "super", "switch", "sync", "this", "throw", "true", "try", "typedef", - "var", "void", "while", "with", "yield", + "abstract", + "as", + "assert", + "async", + "await", + "break", + "case", + "catch", + "class", + "const", + "continue", + "covariant", + "default", + "deferred", + "do", + "dynamic", + "else", + "enum", + "export", + "extends", + "extension", + "external", + "factory", + "false", + "final", + "finally", + "for", + "Function", + "get", + "hide", + "if", + "implements", + "import", + "in", + "interface", + "is", + "late", + "library", + "mixin", + "new", + "null", + "on", + "operator", + "part", + "required", + "rethrow", + "return", + "set", + "show", + "static", + "super", + "switch", + "sync", + "this", + "throw", + "true", + "try", + "typedef", + "var", + "void", + "while", + "with", + "yield", ]; pub trait AsCodeType { @@ -290,4 +351,3 @@ impl AsCodeType for T { } } } - diff --git a/src/gen/primitives/boolean.rs b/src/gen/primitives/boolean.rs index b91c79d..00b73dc 100644 --- a/src/gen/primitives/boolean.rs +++ b/src/gen/primitives/boolean.rs @@ -42,4 +42,3 @@ impl Renderable for BooleanCodeType { } } } - diff --git a/src/gen/primitives/duration.rs b/src/gen/primitives/duration.rs index f996613..bbb03bd 100644 --- a/src/gen/primitives/duration.rs +++ b/src/gen/primitives/duration.rs @@ -44,4 +44,3 @@ impl Renderable for DurationCodeType { } } } - diff --git a/src/gen/primitives/mod.rs b/src/gen/primitives/mod.rs index 96d80b2..ddb5c3b 100644 --- a/src/gen/primitives/mod.rs +++ b/src/gen/primitives/mod.rs @@ -1,8 +1,8 @@ #[macro_use] mod macros; mod boolean; -mod string; mod duration; +mod string; use crate::gen::render::{Renderable, TypeHelperRenderer}; use genco::prelude::*; @@ -11,8 +11,8 @@ use uniffi_bindgen::backend::Literal; use uniffi_bindgen::interface::{Radix, Type}; pub use boolean::BooleanCodeType; -pub use string::StringCodeType; pub use duration::DurationCodeType; +pub use string::StringCodeType; fn render_literal(literal: &Literal) -> String { fn typed_number(type_: &Type, num_str: String) -> String { @@ -33,7 +33,7 @@ fn render_literal(literal: &Literal) -> String { match literal { Literal::Boolean(v) => format!("{}", v), - Literal::String(s) => format!("'{}'", s), + Literal::String(s) => format!("'{}'", s), Literal::Int(i, radix, type_) => typed_number( type_, match radix { @@ -78,4 +78,4 @@ impl_renderable_for_primitive!(UInt16CodeType, "int", "UInt16", 2); impl_renderable_for_primitive!(UInt32CodeType, "int", "UInt32", 4); impl_renderable_for_primitive!(UInt64CodeType, "int", "UInt64", 8); impl_renderable_for_primitive!(Float32CodeType, "double", "Double32", 4); -impl_renderable_for_primitive!(Float64CodeType, "double", "Double64", 8); \ No newline at end of file +impl_renderable_for_primitive!(Float64CodeType, "double", "Double64", 8); diff --git a/src/gen/primitives/string.rs b/src/gen/primitives/string.rs index 77c22b8..2ae3c6a 100644 --- a/src/gen/primitives/string.rs +++ b/src/gen/primitives/string.rs @@ -48,4 +48,3 @@ impl Renderable for StringCodeType { } } } - diff --git a/src/gen/records.rs b/src/gen/records.rs index ff77596..c6355bc 100644 --- a/src/gen/records.rs +++ b/src/gen/records.rs @@ -97,4 +97,3 @@ pub fn generate_record(obj: &Record, type_helper: &dyn TypeHelperRenderer) -> da } } } - diff --git a/src/gen/render/mod.rs b/src/gen/render/mod.rs index ed10019..1af11d1 100644 --- a/src/gen/render/mod.rs +++ b/src/gen/render/mod.rs @@ -28,15 +28,28 @@ pub trait Renderable { fn render_type(&self, ty: &Type, type_helper: &dyn TypeHelperRenderer) -> dart::Tokens { let type_name = match ty { - Type::UInt8 | Type::Int8 | Type::UInt16 | Type::Int16 | - Type::UInt32 | Type::Int32 | Type::UInt64 | Type::Int64 => quote!(int), + Type::UInt8 + | Type::Int8 + | Type::UInt16 + | Type::Int16 + | Type::UInt32 + | Type::Int32 + | Type::UInt64 + | Type::Int64 => quote!(int), Type::Float32 | Type::Float64 => quote!(double), Type::String => quote!(String), Type::Boolean => quote!(bool), Type::Object { name, .. } => quote!($name), Type::Optional { inner_type } => quote!($(&self.render_type(inner_type, type_helper))?), - Type::Sequence { inner_type } => quote!(List<$(&self.render_type(inner_type, type_helper))>), - Type::Map { key_type, value_type } => quote!(Map<$(&self.render_type(key_type, type_helper)), $(&self.render_type(value_type, type_helper))>), + Type::Sequence { inner_type } => { + quote!(List<$(&self.render_type(inner_type, type_helper))>) + } + Type::Map { + key_type, + value_type, + } => { + quote!(Map<$(&self.render_type(key_type, type_helper)), $(&self.render_type(value_type, type_helper))>) + } Type::Enum { name, .. } => quote!($name), Type::Record { name, .. } => quote!($name), Type::Duration => quote!(Duration), @@ -90,4 +103,3 @@ impl AsRenderable for T { } } } - diff --git a/src/gen/types.rs b/src/gen/types.rs index 2f91de7..e5c9e34 100644 --- a/src/gen/types.rs +++ b/src/gen/types.rs @@ -10,11 +10,11 @@ use uniffi_bindgen::{ }; use super::{enums, functions, objects, oracle::AsCodeType, primitives, records}; -use crate::gen::DartCodeOracle; use super::{ render::{AsRenderable, Renderer, TypeHelperRenderer}, Config, }; +use crate::gen::DartCodeOracle; type FunctionDefinition = dart::Tokens; @@ -42,13 +42,17 @@ impl<'a> TypeHelpersRenderer<'a> { } pub fn external_type_package_name(&self, crate_name: &str) -> String { - self.config.external_packages.get(crate_name).cloned() + self.config + .external_packages + .get(crate_name) + .cloned() .unwrap_or_else(|| crate_name.to_string()) } pub fn get_include_names(&self) -> HashMap { self.include_once_names.clone().into_inner() - }} + } +} impl TypeHelperRenderer for TypeHelpersRenderer<'_> { // Checks if the type imports for each type have already been added @@ -695,14 +699,14 @@ impl Renderer<(FunctionDefinition, dart::Tokens)> for TypeHelpersRenderer<'_> { await completer.future; callback.close(); - + final status = calloc(); try { - + final result = completeFunc(rustFuture, status); - + // checkCallStatus(errorHandler ?? NullRustCallStatusErrorHandler(), status.ref); - + return liftFunc(result); } finally { calloc.free(status); @@ -786,4 +790,4 @@ pub fn generate_type(ty: &Type) -> dart::Tokens { Type::Duration => quote!(Duration), _ => todo!("Type::{:?}", ty), } -} \ No newline at end of file +} diff --git a/src/gen/utils.rs b/src/gen/utils.rs index b9ddbf4..4d6fb25 100644 --- a/src/gen/utils.rs +++ b/src/gen/utils.rs @@ -94,4 +94,3 @@ pub static RESERVED_IDENTIFIERS: [&str; 63] = [ "with", "yield", ]; - diff --git a/src/lib.rs b/src/lib.rs index a50d5ae..48b6bc8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,4 +6,3 @@ pub mod testing; pub use build::generate_scaffolding; pub mod gen; - diff --git a/src/testing.rs b/src/testing.rs index 6159a1f..a8958ed 100644 --- a/src/testing.rs +++ b/src/testing.rs @@ -82,4 +82,3 @@ pub fn run_test(fixture: &str, udl_path: &str, config_path: Option<&str>) -> Res pub fn get_compile_sources() -> Result> { todo!("Not implemented") } -