Skip to content

Commit 2fbd266

Browse files
committed
Remove Error::ToLuaConversionError
This variant used only once and not practically useful.
1 parent c79b5e9 commit 2fbd266

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

src/conversion.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::os::raw::c_int;
66
use std::path::{Path, PathBuf};
77
use std::{mem, slice, str};
88

9-
use bstr::{BStr, BString, ByteSlice, ByteVec};
9+
use bstr::{BStr, BString, ByteVec};
1010
use num_traits::cast;
1111

1212
use crate::error::{Error, Result};
@@ -730,14 +730,17 @@ impl FromLua for OsString {
730730
}
731731

732732
impl IntoLua for &OsStr {
733+
#[cfg(unix)]
733734
#[inline]
734735
fn into_lua(self, lua: &Lua) -> Result<Value> {
735-
let s = <[u8]>::from_os_str(self).ok_or_else(|| Error::ToLuaConversionError {
736-
from: "OsStr".into(),
737-
to: "string",
738-
message: Some("invalid utf-8 encoding".into()),
739-
})?;
740-
Ok(Value::String(lua.create_string(s)?))
736+
use std::os::unix::ffi::OsStrExt;
737+
Ok(Value::String(lua.create_string(self.as_bytes())?))
738+
}
739+
740+
#[cfg(not(unix))]
741+
#[inline]
742+
fn into_lua(self, lua: &Lua) -> Result<Value> {
743+
self.display().to_string().into_lua(lua)
741744
}
742745
}
743746

src/error.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,6 @@ pub enum Error {
8787
/// Underlying error returned when converting argument to a Lua value.
8888
cause: Arc<Error>,
8989
},
90-
/// A Rust value could not be converted to a Lua value.
91-
ToLuaConversionError {
92-
/// Name of the Rust type that could not be converted.
93-
from: String,
94-
/// Name of the Lua type that could not be created.
95-
to: &'static str,
96-
/// A message indicating why the conversion failed in more detail.
97-
message: Option<String>,
98-
},
9990
/// A Lua value could not be converted to the expected Rust type.
10091
FromLuaConversionError {
10192
/// Name of the Lua type that could not be converted.
@@ -249,13 +240,6 @@ impl fmt::Display for Error {
249240
}
250241
write!(fmt, ": {cause}")
251242
}
252-
Error::ToLuaConversionError { from, to, message } => {
253-
write!(fmt, "error converting {from} to Lua {to}")?;
254-
match message {
255-
None => Ok(()),
256-
Some(message) => write!(fmt, " ({message})"),
257-
}
258-
}
259243
Error::FromLuaConversionError { from, to, message } => {
260244
write!(fmt, "error converting Lua {from} to {to}")?;
261245
match message {

0 commit comments

Comments
 (0)