I want to use DisableRuntimeMarshallingAttribute in my apps. However, when I have rust Vec<T> then code like this is generated:
/// Gets the element at the given index.
public unsafe ushort this[int i]
{
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
get
{
if (i >= Count) throw new IndexOutOfRangeException();
if (_ptr == IntPtr.Zero) throw new NullReferenceException();
return Marshal.PtrToStructure<ushort>(new IntPtr(_ptr.ToInt64() + i * sizeof(ushort)));
}
}
The Marshal.PtrToStructure raises the following warning:
CA1421: 'System.Runtime.InteropServices.Marshal.PtrToStructure(nint)' uses runtime marshaling even when 'DisableRuntimeMarshallingAttribute' is applied. Use features like 'sizeof' and pointers directly to ensure accurate results.
Is there a reason you dont generate the following for normal, blittable structs?
return ((ushort*)_ptr.ToPointer())[i];
I would be happy to provide a PR if that's a change you would be comfortable with
I want to use
DisableRuntimeMarshallingAttributein my apps. However, when I have rustVec<T>then code like this is generated:The Marshal.PtrToStructure raises the following warning:
Is there a reason you dont generate the following for normal, blittable structs?
I would be happy to provide a PR if that's a change you would be comfortable with