-
Notifications
You must be signed in to change notification settings - Fork 389
Transferring ownership of fields #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Here is a possible patch addressing this. It passes all tests. |
I added one Added Another difference is that
Exposing SinglularPtrField instead of xxx_yyy functions is an interesting idea. I need to think about it. |
Well my generated file has 14712 lines (GitHub has issues rendering it and caps at 13105 lines). I'm not really that worried about file size. My concerns are with run-time performance, which is why the When doing dozens to hundreds of thousands of operations per second this things start to add up. Unnecessary copying is a problem, specially when hidden behind interfaces you don't have control over.
Custom .proto per language is not always possibleUnfortunately, modifying .proto file definitions to augment them for specific languages is a nice feature but not a practical one. The .proto files are in general shared across language barriers, having to maintain a custom copy of the .proto for each language that access it is not practical and defeats the purpose of having a .proto that can be used to exchange data between systems written in different languages (not to mention in some cases it crosses corporate boundaries). Refactor suggestionI would be more than happy to help abstract the fields into a |
To be clear, |
Options in .protoAbout options to customize file generation. Patching I don't like it personally, but Refactor suggestionI don't understand, how |
I expected certain features from the macro that are simply not there yet. I tried creating an example and run into both a limitation on the current macro system that prevents us from doing that, and another bug preventing us to do accomplish the first macro manually with multiple calls to a smaller macro (plus some auto generated code). I run into a few more setbacks when returning a custom type that wraps the object. let mut me = Person::new();
me.mut_age().set(27u);
me.mut_name().as_mut().mut_first().set("John".to_string());
me.mut_name().as_mut().mut_last().set("John".to_string()); If we had a built-in trait abstracting assignment we could change that to something closer to: let mut me = Person::new();
me.age = 27u;
me.name.first = "John".to_string();
me.name.last = "John".to_string(); I'll keep tabs on the state of the ops module. Regarding the TL;DR; Perhaps we can revisit the architecture later when the macro system and the ops module mature a bit. I would like to insist though on a non-copy |
|
This issue was active 11 years ago, but anyway, you made my day 🥇 |
Say type T has a field u of type U and field v of type V.
T and U are both ::protobuf::Message.
I have the following function:
Even though it seems like I have ownership over t, I can't deconstruct a Message and pass on ownership of the field u.
I recommend adding something similar to the following two extra functions per field
With the new semantics I can now implement my method by:
I don't know if this is the correct way of solving the use case, but it makes it possible to implement.
Another option is...
A possible breaking change given that this needs to be implemented for each field is to have a single
get_field
that returnsField<T>
and have that wrapper trait surfacetake()
,unwrap()
,as_ref()
, andas_mut()
(perhaps clone() if T : Clone). I know this is a subset ofSingularField
andSingularPtrField
backing the internalMessage
.Honestly, I've seen all those functions being used throughout the
std
and other crates, I'm not sure if it's worth bringing it up with the Rust devs but having 4 unique traits that represent each of those operations might clean up a lot of code and allow for certain generic macro sugaring. If I'm not mistaken, Deref and DerefMut cover the signatures foras_ref
andas_mut
as operator overloads which is what is currently available withget_field
andget_mut_field
. I'm not sure if the borrow module is more applicable.The text was updated successfully, but these errors were encountered: