Rust codegen: Generic model Ref::to_owned() fails to compile when the model has a string field

Đang mở Phù hợp với người mới
#243 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
75/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
rust, swift
Lĩnh vực
backend

Hướng nghiên cứu

Đọc compiler/compiler/Compiler/Sources/Generation/Rust/RustValueModelGenerator.swift, tập trung vào borrowedAccessors, writeGeneric và writeConcrete. Kiểm tra cách ownedFields xử lý các thuộc tính kiểu chuỗi và thuộc tính kiểu chuỗi tùy chọn, sau đó tạo hoặc chạy các bài kiểm tra sinh mã Rust cho một mô hình generic được export với từng kiểu thuộc tính. Hoàn tất khi to_owned() được sinh ra biên dịch được trong cả hai trường hợp.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Found while reviewing https://github.com/Snapchat/Valdi/pull/211 (native Rust code generation). Not blocking that PR.

Generic model Ref::to_owned() fails to compile when the model has a string field

File: compiler/compiler/Compiler/Sources/Generation/Rust/RustValueModelGenerator.swift

When a generic @ExportModel has a string or optional string property, the generated to_owned() method on <Name>Ref<'a, ...> fails to compile in Rust because std::borrow::Cow<'a, str> does not implement valdi_core_rust::ValdiToOwned. In RustValueModelGenerator, borrowedAccessors returns std::borrow::Cow<'a, str> (or Option<std::borrow::Cow<'a, str>>) for string properties, while writeGeneric generates ownedFields calling valdi_core_rust::ValdiToOwned::to_owned_value(&self.<prop>()?)? for every property.

Handle .string and .nullable(.string) in ownedFields using into_owned() (or deserialize directly from self.value.property(...) with ValdiDeserialize::from_valdi, matching writeConcrete).

Ngôn ngữ chính
C++
Star
16.4k
Fork
539
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Snapchat/Valdi

Tất cả issue của Snapchat/Valdi

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.