Exemplo n.º 1
0
        void GenerateStruct(Type type)
        {
            var doc = options.RustdocEntrySource?.GetEntryForType(type);

            if (doc.HasValue)
            {
                GenerateDocComment(doc, "");
            }
            else
            {
                stringBuilder.AppendLine($"/// `{type.FullName}`");
            }

            stringBuilder.AppendLine("///");
            stringBuilder.AppendLine("/// # COM interop");
            stringBuilder.AppendLine($"/// This type was generated automatically from `{type.FullName}`.");

            stringBuilder.AppendLine("#[repr(C)]");
            stringBuilder.AppendLine("#[derive(Debug, Clone, Copy)]");
            stringBuilder.AppendLine($"pub struct {type.Name} {{");
            foreach (var field in type.GetRuntimeFields())
            {
                doc = options.RustdocEntrySource?.GetEntryForField(field);
                GenerateDocComment(doc, "\t");

                var nativeName = SnakeCaseConverter.Join(DotNetCamelCaseConverter.Split(field.Name));
                var nativeType = TranslateNativeType(field.FieldType, false, false);
                stringBuilder.AppendLine($"\tpub {nativeName}: {nativeType},");
            }
            stringBuilder.AppendLine("}");
            stringBuilder.AppendLine();
        }
Exemplo n.º 2
0
            public RustParameterInfo(RustCodeGen gen, Marshaller.ComMethodParameterInfo cmpi)
            {
                RustCodeGen            = gen;
                ComMethodParameterInfo = cmpi;

                gen.EnqueueTypeGeneration(cmpi.Type);
                NativeName = ComMethodParameterInfo.IsReturnValue ? "retval" :
                             SnakeCaseConverter.Join(DotNetCamelCaseConverter.Split(ComMethodParameterInfo.ParameterInfo.Name)).ToLowerInvariant();
            }