diff --git a/Cargo.toml b/Cargo.toml index 199a816..9ed34dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,7 +34,7 @@ emacs-macros = { path = "emacs-macros", version = "0.17.0" } rustc_version = "0.2.3" [features] -default = [] +default = [ "utf-8-validation" ] utf-8-validation = [] lossy-integer-conversion = [] nonzero-integer-conversion = [] diff --git a/guide/src/type-conversions.md b/guide/src/type-conversions.md index d7bf859..8538f29 100644 --- a/guide/src/type-conversions.md +++ b/guide/src/type-conversions.md @@ -57,11 +57,11 @@ features = ["nonzero-integer-conversion"] ## Strings -By default, no utf-8 validation is done when converting Lisp strings into Rust strings, because the string data returned by Emacs is guaranteed to be valid utf-8 sequence. If you think you've otherwise encountered an Emacs bug, utf-8 validation can be enabled through a feature: +By default, utf-8 validation is enabled when converting Lisp strings into Rust strings, because the string data returned by Emacs is not guaranteed to be valid utf-8 sequence. If you require additional performance and don't care about possible undefined behavior and crashes, utf-8 validation can be disabled through a feature `utf-8-validation`: ```toml [dependencies.emacs] -features = ["utf-8-validation"] +default-features = false ``` ## Vectors diff --git a/src/types/string.rs b/src/types/string.rs index 5c1099c..7808b69 100644 --- a/src/types/string.rs +++ b/src/types/string.rs @@ -13,7 +13,7 @@ impl FromLisp<'_> for String { #[cfg(feature = "utf-8-validation")] fn from_lisp(value: Value<'_>) -> Result { let bytes = value.env.string_bytes(value)?; - Ok(String::from_utf8(bytes).unwrap()) + String::from_utf8(bytes).map_err(|e| e.into()) } }