зеркало из https://github.com/mozilla/uniffi-rs.git
Add a configuration to allow removing `LocalizedError` conformation (#2319)
This commit is contained in:
Родитель
286de8d66e
Коммит
f4b0824003
|
@ -13,11 +13,12 @@ more likely to change than other configurations.
|
|||
| `module_name` | `{namespace}`[^1] | The name of the Swift module containing the high-level foreign-language bindings. |
|
||||
| `ffi_module_name` | `{module_name}FFI` | The name of the lower-level C module containing the FFI declarations. |
|
||||
| `ffi_module_filename` | `{ffi_module_name}` | The filename stem for the lower-level C module containing the FFI declarations. |
|
||||
| `generate_module_map` | `true` | Whether to generate a `.modulemap` file for the lower-level C module with FFI declarations. (ignored by `uniffi-bindgen-swift`) |
|
||||
| `generate_module_map` | `true` | Whether to generate a `.modulemap` file for the lower-level C module with FFI declarations. (ignored by `uniffi-bindgen-swift`) |
|
||||
| `omit_argument_labels` | `false` | Whether to omit argument labels in Swift function definitions. |
|
||||
| `generate_immutable_records` | `false` | Whether to generate records with immutable fields (`let` instead of `var`). |
|
||||
| `experimental_sendable_value_types` | `false` | Whether to mark value types as `Sendable'. |
|
||||
| `custom_types` | | A map which controls how custom types are exposed to Swift. See the [custom types section of the manual](../udl/custom_types.md#custom-types-in-the-bindings-code) |
|
||||
| `omit_localized_error_conformance` | `false` | Whether to make generated error types conform to `LocalizedError`. |
|
||||
|
||||
[^1]: `namespace` is the top-level namespace from your UDL file.
|
||||
|
||||
|
|
|
@ -197,6 +197,7 @@ pub struct Config {
|
|||
omit_argument_labels: Option<bool>,
|
||||
generate_immutable_records: Option<bool>,
|
||||
experimental_sendable_value_types: Option<bool>,
|
||||
omit_localized_error_conformance: Option<bool>,
|
||||
#[serde(default)]
|
||||
custom_types: HashMap<String, CustomTypeConfig>,
|
||||
}
|
||||
|
@ -264,6 +265,11 @@ impl Config {
|
|||
pub fn experimental_sendable_value_types(&self) -> bool {
|
||||
self.experimental_sendable_value_types.unwrap_or(false)
|
||||
}
|
||||
|
||||
// Whether to make generated error types conform to `LocalizedError`. Default: false.
|
||||
pub fn omit_localized_error_conformance(&self) -> bool {
|
||||
self.omit_localized_error_conformance.unwrap_or(false)
|
||||
}
|
||||
}
|
||||
|
||||
/// Generate UniFFI component bindings for Swift, as strings in memory.
|
||||
|
|
|
@ -90,8 +90,11 @@ public struct {{ ffi_converter_name }}: FfiConverterRustBuffer {
|
|||
{% if !contains_object_references %}
|
||||
extension {{ type_name }}: Equatable, Hashable {}
|
||||
{% endif %}
|
||||
|
||||
{% if !config.omit_localized_error_conformance() %}
|
||||
extension {{ type_name }}: Foundation.LocalizedError {
|
||||
public var errorDescription: String? {
|
||||
String(reflecting: self)
|
||||
}
|
||||
}
|
||||
{% endif %}
|
||||
|
|
|
@ -174,11 +174,13 @@ public struct {{ ffi_converter_name }}: FfiConverter {
|
|||
{# Objects as error #}
|
||||
{%- if is_error %}
|
||||
|
||||
{% if !config.omit_localized_error_conformance() %}
|
||||
extension {{ type_name }}: Foundation.LocalizedError {
|
||||
public var errorDescription: String? {
|
||||
String(reflecting: self)
|
||||
}
|
||||
}
|
||||
{% endif %}
|
||||
|
||||
{# Due to some mismatches in the ffi converter mechanisms, errors are a RustBuffer holding a pointer #}
|
||||
#if swift(>=5.8)
|
||||
|
|
Загрузка…
Ссылка в новой задаче