Skip to content

Commit

Permalink
rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
arsher authored and ralfbiedert committed Feb 1, 2025
1 parent bc72471 commit 233fd4a
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions crates/backend_csharp/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,10 +766,21 @@ pub trait CSharpWriter {
indented!(w, "fixed(char* s = managed.{})", field_name)?;
indented!(w, "{{")?;
w.indent();
indented!(w, r"if(Encoding.UTF8.GetByteCount(managed.{0}, 0, managed.{0}.Length) + 1 > {1})", field_name, a.len())?;
indented!(
w,
r"if(Encoding.UTF8.GetByteCount(managed.{0}, 0, managed.{0}.Length) + 1 > {1})",
field_name,
a.len()
)?;
indented!(w, r"{{")?;
w.indent();
indented!(w, r#"throw new InvalidOperationException($"The managed string field '{{nameof({0}.{1})}}' cannot be encoded to fit the fixed size array of {2}.");"#, the_type.rust_name(), field_name, a.len())?;
indented!(
w,
r#"throw new InvalidOperationException($"The managed string field '{{nameof({0}.{1})}}' cannot be encoded to fit the fixed size array of {2}.");"#,
the_type.rust_name(),
field_name,
a.len()
)?;
w.unindent();
indented!(w, r"}}")?;
indented!(
Expand All @@ -785,15 +796,16 @@ pub trait CSharpWriter {
indented!(w, r"if(managed.{}.Length > {})", field_name, a.len())?;
indented!(w, r"{{")?;
w.indent();
indented!(w, r#"throw new InvalidOperationException($"The managed array field '{{nameof({0}.{1})}}' has {{managed.{1}.Length}} elements, exceeding the fixed size array of {2}.");"#, the_type.rust_name(), field_name, a.len())?;
w.unindent();
indented!(w, r"}}")?;
indented!(
w,
r"var source = new ReadOnlySpan<{0}>(managed.{1}, 0, managed.{1}.Length);",
type_name,
field_name
r#"throw new InvalidOperationException($"The managed array field '{{nameof({0}.{1})}}' has {{managed.{1}.Length}} elements, exceeding the fixed size array of {2}.");"#,
the_type.rust_name(),
field_name,
a.len()
)?;
w.unindent();
indented!(w, r"}}")?;
indented!(w, r"var source = 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);")?;
}
Expand Down

0 comments on commit 233fd4a

Please sign in to comment.