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

Open Beginner friendly
#243 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust, swift
Domain
backend

Research direction

Read compiler/compiler/Compiler/Sources/Generation/Rust/RustValueModelGenerator.swift, focusing on borrowedAccessors, writeGeneric, and writeConcrete. Check how ownedFields handles string and optional string properties, then build or run the Rust code generation tests for a generic exported model with each property type. Done when the generated to_owned() compiles for both cases.

Written by the indexing model from the issue text.

Description

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).

Dominant language
C++
Stars
16.4k
Forks
539
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Snapchat/Valdi

All issues in Snapchat/Valdi

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.