Commit f3a3ac0
authored
[Rust] Look through typedefs to pass borrowed strings as
wit-bindgen already knows to special-case passing strings by reference
and pass them as `&str` instead of naively passing them as `&String` and
requiring callers to have owned `Strings`. Implement this behavior for
type aliases of strings as well, so that in code like this:
```wit
type my-string = string;
foo: func(x: my-string);
```
the argument is `&str` instead of `&MyString` which is effectively
`&String`. And similar for lists.
This comes up in several functions in wasi-http; for example, in the
bindings for the `Fields::append` function, it enables this change:
```diff
@@ -5075,8 +5075,8 @@ pub mod wasi {
/// `field-value` are syntactically invalid.
pub fn append(
&self,
- name: &FieldName,
- value: &FieldValue,
+ name: &str,
+ value: &[u8],
) -> Result<(), HeaderError> {
unsafe {
#[repr(align(1))]
```
where `FieldName` and `FieldValue` are defined as:
```wit
pub type FieldKey = _rt::String;
pub type FieldName = FieldKey;
pub type FieldValue = _rt::Vec<u8>;
```&str (#1102)1 parent d1387cc commit f3a3ac0
2 files changed
+77
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1113 | 1113 | | |
1114 | 1114 | | |
1115 | 1115 | | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
| 1123 | + | |
| 1124 | + | |
| 1125 | + | |
| 1126 | + | |
| 1127 | + | |
| 1128 | + | |
| 1129 | + | |
| 1130 | + | |
| 1131 | + | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
| 1135 | + | |
| 1136 | + | |
| 1137 | + | |
| 1138 | + | |
| 1139 | + | |
1116 | 1140 | | |
1117 | 1141 | | |
1118 | 1142 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
85 | 137 | | |
86 | 138 | | |
87 | 139 | | |
| |||
96 | 148 | | |
97 | 149 | | |
98 | 150 | | |
99 | | - | |
| 151 | + | |
100 | 152 | | |
101 | 153 | | |
102 | 154 | | |
| |||
0 commit comments