Skip to content

Commit e401f32

Browse files
committed
cargo fmt
1 parent 3031db7 commit e401f32

File tree

5 files changed

+39
-27
lines changed

5 files changed

+39
-27
lines changed

crates/swift-bridge-ir/src/codegen/codegen_tests/vec_codegen_tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ mod transparent_struct_vec_support_without_derives {
958958
}
959959
}
960960
},
961-
]
961+
],
962962
}
963963
}
964964

crates/swift-bridge-ir/src/codegen/generate_c_header.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
33
use crate::bridged_type::shared_struct::StructField;
44
use crate::bridged_type::{BridgeableType, BridgedType, StdLibType, StructFields};
5-
use crate::codegen::CodegenConfig;
65
use crate::codegen::generate_rust_tokens::can_generate_vec_of_transparent_struct_functions;
6+
use crate::codegen::CodegenConfig;
77
use crate::parse::{SharedTypeDeclaration, TypeDeclaration, TypeDeclarations};
88
use crate::parsed_extern_fn::ParsedExternFn;
99
use crate::{SwiftBridgeModule, SWIFT_BRIDGE_PREFIX};
@@ -113,11 +113,12 @@ impl SwiftBridgeModule {
113113
"".to_string()
114114
};
115115

116-
let vec_support = if can_generate_vec_of_transparent_struct_functions(&ty_struct) {
117-
vec_transparent_struct_c_support(&name)
118-
} else {
119-
format!("")
120-
};
116+
let vec_support =
117+
if can_generate_vec_of_transparent_struct_functions(&ty_struct) {
118+
vec_transparent_struct_c_support(&name)
119+
} else {
120+
format!("")
121+
};
121122

122123
let ty_decl = format!(
123124
r#"typedef struct {prefix}${name} {{{maybe_fields}}} {prefix}${name};

crates/swift-bridge-ir/src/codegen/generate_rust_tokens/shared_struct.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
//! crates/swift-bridge-ir/src/codegen/codegen_tests/shared_struct_codegen_tests.rs
33
44
use crate::bridged_type::{BridgedType, SharedStruct};
5+
use crate::codegen::generate_rust_tokens::vec::vec_of_transparent_struct::{
6+
can_generate_vec_of_transparent_struct_functions, generate_vec_of_transparent_struct_functions,
7+
};
58
use crate::{SwiftBridgeModule, SWIFT_BRIDGE_PREFIX};
6-
use crate::codegen::generate_rust_tokens::vec::vec_of_transparent_struct::{generate_vec_of_transparent_struct_functions, can_generate_vec_of_transparent_struct_functions};
79
use proc_macro2::{Span, TokenStream};
810
use quote::quote;
911
use syn::Ident;

crates/swift-bridge-ir/src/codegen/generate_rust_tokens/vec/vec_of_transparent_struct.rs

+24-17
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
use crate::bridged_type::{SharedStruct, StructSwiftRepr};
2-
use proc_macro2::{TokenStream};
2+
use proc_macro2::TokenStream;
33
use quote::quote;
44

5-
65
/// Generate the functions that Swift calls uses inside of the corresponding class for a
76
/// transparent struct's Vectorizable implementation.
87
///
98
/// So inside of `extension SomeTransparentStruct: Vectorizable {}` on the Swift side.
109
pub(in super::super) fn generate_vec_of_transparent_struct_functions(
11-
shared_struct: &SharedStruct
10+
shared_struct: &SharedStruct,
1211
) -> TokenStream {
1312
if can_generate_vec_of_transparent_struct_functions(&shared_struct) {
1413
let struct_name = &shared_struct.name;
15-
14+
1615
// examples:
1716
// "__swift_bridge__$Vec_SomeTransparentStruct$new"
1817
// "__swift_bridge__$Vec_SomeTransparentStruct$drop"
@@ -31,7 +30,7 @@ pub(in super::super) fn generate_vec_of_transparent_struct_functions(
3130
let export_name_push = make_export_name("push");
3231
let export_name_pop = make_export_name("pop");
3332
let export_name_as_ptr = make_export_name("as_ptr");
34-
33+
3534
let ffi_struct_repr = &shared_struct.ffi_name_tokens();
3635
let ffi_option_struct_repr = shared_struct.ffi_option_name_tokens();
3736
// TODO: Check for trait implementation as well
@@ -40,58 +39,58 @@ pub(in super::super) fn generate_vec_of_transparent_struct_functions(
4039
} else {
4140
quote! { v.clone() }
4241
};
43-
42+
4443
quote! {
4544
const _: () = {
4645
#[doc(hidden)]
4746
#[export_name = #export_name_new]
4847
pub extern "C" fn _new() -> *mut Vec<#struct_name> {
4948
Box::into_raw(Box::new(Vec::new()))
5049
}
51-
50+
5251
#[doc(hidden)]
5352
#[export_name = #export_name_drop]
5453
pub extern "C" fn _drop(vec: *mut Vec<#struct_name>) {
5554
let vec = unsafe { Box::from_raw(vec) };
5655
drop(vec)
5756
}
58-
57+
5958
#[doc(hidden)]
6059
#[export_name = #export_name_len]
6160
pub extern "C" fn _len(vec: *const Vec<#struct_name>) -> usize {
6261
unsafe { &*vec }.len()
6362
}
64-
63+
6564
#[doc(hidden)]
6665
#[export_name = #export_name_get]
6766
pub extern "C" fn _get(vec: *const Vec<#struct_name>, index: usize) -> #ffi_option_struct_repr {
6867
let vec = unsafe { &*vec };
6968
let val = vec.get(index).map(|v|#vec_map);
7069
#ffi_option_struct_repr::from_rust_repr(val)
7170
}
72-
71+
7372
#[doc(hidden)]
7473
#[export_name = #export_name_get_mut]
7574
pub extern "C" fn _get_mut(vec: *mut Vec<#struct_name>, index: usize) -> #ffi_option_struct_repr {
7675
let vec = unsafe { &mut *vec };
7776
let val = vec.get_mut(index).map(|v|#vec_map);
7877
#ffi_option_struct_repr::from_rust_repr(val)
7978
}
80-
79+
8180
#[doc(hidden)]
8281
#[export_name = #export_name_push]
8382
pub extern "C" fn _push(vec: *mut Vec<#struct_name>, val: #ffi_struct_repr) {
8483
unsafe { &mut *vec }.push( val.into_rust_repr() )
8584
}
86-
85+
8786
#[doc(hidden)]
8887
#[export_name = #export_name_pop]
8988
pub extern "C" fn _pop(vec: *mut Vec<#struct_name>) -> #ffi_option_struct_repr {
9089
let vec = unsafe { &mut *vec };
9190
let val = vec.pop();
9291
#ffi_option_struct_repr::from_rust_repr(val)
9392
}
94-
93+
9594
#[doc(hidden)]
9695
#[export_name = #export_name_as_ptr]
9796
pub extern "C" fn _as_ptr(vec: *const Vec<#struct_name>) -> *const #struct_name {
@@ -104,7 +103,9 @@ pub(in super::super) fn generate_vec_of_transparent_struct_functions(
104103
}
105104
}
106105

107-
pub(crate) fn can_generate_vec_of_transparent_struct_functions(shared_struct: &SharedStruct) -> bool {
106+
pub(crate) fn can_generate_vec_of_transparent_struct_functions(
107+
shared_struct: &SharedStruct,
108+
) -> bool {
108109
match shared_struct.swift_repr {
109110
StructSwiftRepr::Class => false,
110111
// TODO: Check for trait implementation as well
@@ -115,9 +116,9 @@ pub(crate) fn can_generate_vec_of_transparent_struct_functions(shared_struct: &S
115116
#[cfg(test)]
116117
mod tests {
117118
use super::*;
119+
use crate::bridged_type::{shared_struct::StructDerives, StructFields, StructSwiftRepr};
118120
use crate::test_utils::assert_tokens_eq;
119121
use proc_macro2::{Ident, Span};
120-
use crate::bridged_type::{StructSwiftRepr, StructFields, shared_struct::StructDerives};
121122

122123
/// Verify that we can generate the functions for an opaque Rust type that get exposed to Swift
123124
/// in order to power the `extension MyRustType: Vectorizable { }` implementation on the Swift
@@ -189,7 +190,10 @@ mod tests {
189190
fields: StructFields::Named(vec![]),
190191
swift_name: None,
191192
already_declared: false,
192-
derives: StructDerives { copy: true, clone: true },
193+
derives: StructDerives {
194+
copy: true,
195+
clone: true,
196+
},
193197
};
194198
assert_tokens_eq(
195199
&generate_vec_of_transparent_struct_functions(&shared_struct),
@@ -267,7 +271,10 @@ mod tests {
267271
fields: StructFields::Named(vec![]),
268272
swift_name: None,
269273
already_declared: false,
270-
derives: StructDerives { copy: false, clone: true },
274+
derives: StructDerives {
275+
copy: false,
276+
clone: true,
277+
},
271278
};
272279
assert_tokens_eq(
273280
&generate_vec_of_transparent_struct_functions(&shared_struct),

crates/swift-bridge-ir/src/codegen/generate_swift/shared_struct.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ impl SwiftBridgeModule {
4848
let convert_ffi_repr_to_swift =
4949
shared_struct.convert_ffi_expression_to_swift("self", &self.types);
5050

51-
let vectorizable_impl = if can_generate_vec_of_transparent_struct_functions(&shared_struct) {
51+
let vectorizable_impl = if can_generate_vec_of_transparent_struct_functions(
52+
&shared_struct,
53+
) {
5254
format!(
5355
r#"
5456
extension {struct_name}: Vectorizable {{
@@ -86,7 +88,7 @@ extension {struct_name}: Vectorizable {{
8688
struct_name = struct_name
8789
)
8890
} else {
89-
format!("")
91+
format!("")
9092
};
9193

9294
// No need to generate any code. Swift will automatically generate a

0 commit comments

Comments
 (0)