Skip to content

Commit

Permalink
rustfmt and clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
arsher authored and ralfbiedert committed Feb 1, 2025
1 parent 6cdf164 commit 31052bf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 24 deletions.
48 changes: 25 additions & 23 deletions crates/backend_csharp/src/interop/types/composite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,12 @@ pub fn write_type_definition_composite_to_unmanaged_marshal_field(
)?;
w.unindent();
indented!(w, r"}}")?;
indented!(w, r"var source_{1} = new ReadOnlySpan<{0}>(managed.{1}, 0, managed.{1}.Length);", type_name, field_name)?;
indented!(
w,
r"var source_{1} = new ReadOnlySpan<{0}>(managed.{1}, 0, managed.{1}.Length);",
type_name,
field_name
)?;
indented!(w, r"var dest = new Span<{0}>(result.{1}, {2});", type_name, field_name, a.len())?;
indented!(w, r"source_{}.CopyTo(dest);", field_name)?;
}
Expand Down Expand Up @@ -325,30 +330,27 @@ pub fn write_type_definition_composite_body_field(i: &Interop, w: &mut IndentWri
c::Visibility::Private => "",
};

match field.the_type() {
CType::Array(a) => {
if i.unroll_struct_arrays {
let type_name = to_typespecifier_in_field(a.array_type(), field, the_type);
for i in 0..a.len() {
indented!(w, r"{}{} {}{};", visibility, type_name, field_name, i)?;
}
} else {
assert!(is_blittable(a.array_type()), "Array type is not blittable: {:?}", a.array_type());

let type_name = if matches!(a.array_type(), CType::Pattern(TypePattern::CChar)) {
"string".to_string()
} else {
format!("{}[]", to_typespecifier_in_field(a.array_type(), field, the_type))
};

indented!(w, r"{}{} {};", visibility, type_name, field_name)?;
if let CType::Array(a) = field.the_type() {
if i.unroll_struct_arrays {
let type_name = to_typespecifier_in_field(a.array_type(), field, the_type);
for i in 0..a.len() {
indented!(w, r"{}{} {}{};", visibility, type_name, field_name, i)?;
}
} else {
assert!(is_blittable(a.array_type()), "Array type is not blittable: {:?}", a.array_type());

Ok(())
}
_ => {
let type_name = to_typespecifier_in_field(field.the_type(), field, the_type);
indented!(w, r"{}{} {};", visibility, type_name, field_name)
let type_name = if matches!(a.array_type(), CType::Pattern(TypePattern::CChar)) {
"string".to_string()
} else {
format!("{}[]", to_typespecifier_in_field(a.array_type(), field, the_type))
};

indented!(w, r"{}{} {};", visibility, type_name, field_name)?;
}

Ok(())
} else {
let type_name = to_typespecifier_in_field(field.the_type(), field, the_type);
indented!(w, r"{}{} {};", visibility, type_name, field_name)
}
}
5 changes: 4 additions & 1 deletion crates/reference_project/src/functions.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
//! Functions using all supported type patterns.
use crate::patterns::result::{Error, FFIError};
use crate::types::{ambiguous1, ambiguous2, common, Array, BoolField, Callbacku8u8, CharArray, EnumDocumented, EnumRenamedXYZ, FixedString, Generic, Generic2, Generic3, Generic4, NestedArray, Packed1, Packed2, Phantom, StructDocumented, StructRenamedXYZ, Transparent, Tupled, Vec3f32, Visibility1, Visibility2, Weird1, Weird2};
use crate::types::{
ambiguous1, ambiguous2, common, Array, BoolField, Callbacku8u8, CharArray, EnumDocumented, EnumRenamedXYZ, FixedString, Generic, Generic2, Generic3, Generic4,
NestedArray, Packed1, Packed2, Phantom, StructDocumented, StructRenamedXYZ, Transparent, Tupled, Vec3f32, Visibility1, Visibility2, Weird1, Weird2,
};
use interoptopus::patterns::option::FFIOption;
use interoptopus::patterns::result::panics_and_errors_to_ffi_enum;
use interoptopus::patterns::slice::FFISlice;
Expand Down

0 comments on commit 31052bf

Please sign in to comment.