@@ -124,6 +124,9 @@ emitted for the owned message type (`Foo`). A subset of these functions with
124
124
functions with either ` &self ` or ` &mut self ` will also be included on the
125
125
` FooMut<'msg> ` .
126
126
127
+ To create an owned message type from a View / Mut type call ` to_owned() ` , which
128
+ creates a deep copy.
129
+
127
130
## Nested Types {#nested-types}
128
131
129
132
Given the message declaration:
@@ -324,6 +327,8 @@ enum Bar {
324
327
The compiler generates a struct where each variant is an associated constant:
325
328
326
329
``` rust
330
+ #[derive(Clone , Copy , PartialEq , Eq , Hash )]
331
+ #[repr(transparent)]
327
332
pub struct Bar (i32 );
328
333
329
334
impl Bar {
@@ -366,6 +371,20 @@ enum Bar {
366
371
}
367
372
```
368
373
374
+ The compiler generates a struct where each variant is an associated constant:
375
+
376
+ ``` rust
377
+ #[derive(Clone , Copy , PartialEq , Eq , Hash )]
378
+ #[repr(transparent)]
379
+ pub struct Bar (i32 );
380
+
381
+ impl Bar {
382
+ pub const Unspecified : Bar = Bar (0 );
383
+ pub const Value : Bar = Bar (1 );
384
+ pub const OtherValue : Bar = Bar (2 );
385
+ }
386
+ ```
387
+
369
388
For these field definitions:
370
389
371
390
``` proto
@@ -536,14 +555,15 @@ enum FooBar {
536
555
The compiler will generate:
537
556
538
557
``` rust
539
- #[derive(Clone , Copy , PartialEq , Eq )]
540
- pub struct Foo (i32 );
558
+ #[derive(Clone , Copy , PartialEq , Eq , Hash )]
559
+ #[repr(transparent)]
560
+ pub struct FooBar (i32 );
541
561
542
562
impl FooBar {
543
- pub const Unknown : Foo = Foo (0 );
544
- pub const A : Foo = Foo (1 );
545
- pub const FooB : Foo = Foo (5 );
546
- pub const ValueC : Foo = Foo (1234 );
563
+ pub const Unknown : FooBar = FooBar (0 );
564
+ pub const A : FooBar = FooBar (1 );
565
+ pub const FooB : FooBar = FooBar (5 );
566
+ pub const ValueC : FooBar = FooBar (1234 );
547
567
}
548
568
```
549
569
0 commit comments