Skip to content

Commit 2ace892

Browse files
committed
Rename string::String to LuaString
1 parent c1ffd4e commit 2ace892

26 files changed

+246
-264
lines changed

src/chunk.rs

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::ffi::CString;
44
use std::io::Result as IoResult;
55
use std::panic::Location;
66
use std::path::{Path, PathBuf};
7-
use std::string::String as StdString;
87

98
use crate::error::{Error, Result};
109
use crate::function::Function;
@@ -20,7 +19,7 @@ pub trait AsChunk {
2019
/// Returns optional chunk name
2120
///
2221
/// See [`Chunk::set_name`] for possible name prefixes.
23-
fn name(&self) -> Option<StdString> {
22+
fn name(&self) -> Option<String> {
2423
None
2524
}
2625

@@ -52,13 +51,13 @@ impl AsChunk for &str {
5251
}
5352
}
5453

55-
impl AsChunk for StdString {
54+
impl AsChunk for String {
5655
fn source<'a>(&self) -> IoResult<Cow<'a, [u8]>> {
5756
Ok(Cow::Owned(self.clone().into_bytes()))
5857
}
5958
}
6059

61-
impl AsChunk for &StdString {
60+
impl AsChunk for &String {
6261
fn source<'a>(&self) -> IoResult<Cow<'a, [u8]>>
6362
where
6463
Self: 'a,
@@ -92,7 +91,7 @@ impl AsChunk for &Vec<u8> {
9291
}
9392

9493
impl AsChunk for &Path {
95-
fn name(&self) -> Option<StdString> {
94+
fn name(&self) -> Option<String> {
9695
Some(format!("@{}", self.display()))
9796
}
9897

@@ -102,7 +101,7 @@ impl AsChunk for &Path {
102101
}
103102

104103
impl AsChunk for PathBuf {
105-
fn name(&self) -> Option<StdString> {
104+
fn name(&self) -> Option<String> {
106105
Some(format!("@{}", self.display()))
107106
}
108107

@@ -112,7 +111,7 @@ impl AsChunk for PathBuf {
112111
}
113112

114113
impl<C: AsChunk + ?Sized> AsChunk for Box<C> {
115-
fn name(&self) -> Option<StdString> {
114+
fn name(&self) -> Option<String> {
116115
(**self).name()
117116
}
118117

@@ -136,7 +135,7 @@ impl<C: AsChunk + ?Sized> AsChunk for Box<C> {
136135
#[must_use = "`Chunk`s do nothing unless one of `exec`, `eval`, `call`, or `into_function` are called on them"]
137136
pub struct Chunk<'a> {
138137
pub(crate) lua: WeakLua,
139-
pub(crate) name: StdString,
138+
pub(crate) name: String,
140139
pub(crate) env: Result<Option<Table>>,
141140
pub(crate) mode: Option<ChunkMode>,
142141
pub(crate) source: IoResult<Cow<'a, [u8]>>,
@@ -160,7 +159,7 @@ pub enum CompileConstant {
160159
Boolean(bool),
161160
Number(crate::Number),
162161
Vector(crate::Vector),
163-
String(StdString),
162+
String(String),
164163
}
165164

166165
#[cfg(any(feature = "luau", doc))]
@@ -192,7 +191,7 @@ impl From<&str> for CompileConstant {
192191
}
193192

194193
#[cfg(any(feature = "luau", doc))]
195-
type LibraryMemberConstantMap = HashMap<(StdString, StdString), CompileConstant>;
194+
type LibraryMemberConstantMap = HashMap<(String, String), CompileConstant>;
196195

197196
/// Luau compiler
198197
#[cfg(any(feature = "luau", doc))]
@@ -203,14 +202,14 @@ pub struct Compiler {
203202
debug_level: u8,
204203
type_info_level: u8,
205204
coverage_level: u8,
206-
vector_lib: Option<StdString>,
207-
vector_ctor: Option<StdString>,
208-
vector_type: Option<StdString>,
209-
mutable_globals: Vec<StdString>,
210-
userdata_types: Vec<StdString>,
211-
libraries_with_known_members: Vec<StdString>,
205+
vector_lib: Option<String>,
206+
vector_ctor: Option<String>,
207+
vector_type: Option<String>,
208+
mutable_globals: Vec<String>,
209+
userdata_types: Vec<String>,
210+
libraries_with_known_members: Vec<String>,
212211
library_constants: Option<LibraryMemberConstantMap>,
213-
disabled_builtins: Vec<StdString>,
212+
disabled_builtins: Vec<String>,
214213
}
215214

216215
#[cfg(any(feature = "luau", doc))]
@@ -294,7 +293,7 @@ impl Compiler {
294293
/// To set the library and method name, use the `lib.ctor` format.
295294
#[doc(hidden)]
296295
#[must_use]
297-
pub fn set_vector_ctor(mut self, ctor: impl Into<StdString>) -> Self {
296+
pub fn set_vector_ctor(mut self, ctor: impl Into<String>) -> Self {
298297
let ctor = ctor.into();
299298
let lib_ctor = ctor.split_once('.');
300299
self.vector_lib = lib_ctor.as_ref().map(|&(lib, _)| lib.to_owned());
@@ -307,7 +306,7 @@ impl Compiler {
307306
/// Sets alternative vector type name for type tables, in addition to default type `vector`.
308307
#[doc(hidden)]
309308
#[must_use]
310-
pub fn set_vector_type(mut self, r#type: impl Into<StdString>) -> Self {
309+
pub fn set_vector_type(mut self, r#type: impl Into<String>) -> Self {
311310
self.vector_type = Some(r#type.into());
312311
self
313312
}
@@ -316,7 +315,7 @@ impl Compiler {
316315
///
317316
/// It disables the import optimization for fields accessed through it.
318317
#[must_use]
319-
pub fn add_mutable_global(mut self, global: impl Into<StdString>) -> Self {
318+
pub fn add_mutable_global(mut self, global: impl Into<String>) -> Self {
320319
self.mutable_globals.push(global.into());
321320
self
322321
}
@@ -325,21 +324,21 @@ impl Compiler {
325324
///
326325
/// It disables the import optimization for fields accessed through these.
327326
#[must_use]
328-
pub fn set_mutable_globals<S: Into<StdString>>(mut self, globals: impl IntoIterator<Item = S>) -> Self {
327+
pub fn set_mutable_globals<S: Into<String>>(mut self, globals: impl IntoIterator<Item = S>) -> Self {
329328
self.mutable_globals = globals.into_iter().map(|s| s.into()).collect();
330329
self
331330
}
332331

333332
/// Adds a userdata type to the list that will be included in the type information.
334333
#[must_use]
335-
pub fn add_userdata_type(mut self, r#type: impl Into<StdString>) -> Self {
334+
pub fn add_userdata_type(mut self, r#type: impl Into<String>) -> Self {
336335
self.userdata_types.push(r#type.into());
337336
self
338337
}
339338

340339
/// Sets a list of userdata types that will be included in the type information.
341340
#[must_use]
342-
pub fn set_userdata_types<S: Into<StdString>>(mut self, types: impl IntoIterator<Item = S>) -> Self {
341+
pub fn set_userdata_types<S: Into<String>>(mut self, types: impl IntoIterator<Item = S>) -> Self {
343342
self.userdata_types = types.into_iter().map(|s| s.into()).collect();
344343
self
345344
}
@@ -373,14 +372,14 @@ impl Compiler {
373372

374373
/// Adds a builtin that should be disabled.
375374
#[must_use]
376-
pub fn add_disabled_builtin(mut self, builtin: impl Into<StdString>) -> Self {
375+
pub fn add_disabled_builtin(mut self, builtin: impl Into<String>) -> Self {
377376
self.disabled_builtins.push(builtin.into());
378377
self
379378
}
380379

381380
/// Sets a list of builtins that should be disabled.
382381
#[must_use]
383-
pub fn set_disabled_builtins<S: Into<StdString>>(
382+
pub fn set_disabled_builtins<S: Into<String>>(
384383
mut self,
385384
builtins: impl IntoIterator<Item = S>,
386385
) -> Self {
@@ -490,7 +489,7 @@ impl Compiler {
490489
if bytecode.first() == Some(&0) {
491490
// The rest of the bytecode is the error message starting with `:`
492491
// See https://github.com/luau-lang/luau/blob/0.640/Compiler/src/Compiler.cpp#L4336
493-
let message = StdString::from_utf8_lossy(&bytecode[2..]).into_owned();
492+
let message = String::from_utf8_lossy(&bytecode[2..]).into_owned();
494493
return Err(Error::SyntaxError {
495494
incomplete_input: message.ends_with("<eof>"),
496495
message,
@@ -513,7 +512,7 @@ impl Chunk<'_> {
513512
/// - `@` - file path (when truncation is needed, the end of the file path is kept, as this is
514513
/// more useful for identifying the file)
515514
/// - `=` - custom chunk name (when truncation is needed, the beginning of the name is kept)
516-
pub fn set_name(mut self, name: impl Into<StdString>) -> Self {
515+
pub fn set_name(mut self, name: impl Into<String>) -> Self {
517516
self.name = name.into();
518517
self
519518
}
@@ -761,7 +760,7 @@ impl Chunk<'_> {
761760
ChunkMode::Text
762761
}
763762

764-
fn convert_name(name: StdString) -> Result<CString> {
763+
fn convert_name(name: String) -> Result<CString> {
765764
CString::new(name).map_err(|err| Error::runtime(format!("invalid name: {err}")))
766765
}
767766

src/conversion.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use std::ffi::{CStr, CString, OsStr, OsString};
44
use std::hash::{BuildHasher, Hash};
55
use std::os::raw::c_int;
66
use std::path::{Path, PathBuf};
7-
use std::string::String as StdString;
87
use std::{mem, slice, str};
98

109
use bstr::{BStr, BString, ByteSlice, ByteVec};
@@ -13,7 +12,7 @@ use num_traits::cast;
1312
use crate::error::{Error, Result};
1413
use crate::function::Function;
1514
use crate::state::{Lua, RawLua};
16-
use crate::string::{BorrowedBytes, BorrowedStr, String};
15+
use crate::string::{BorrowedBytes, BorrowedStr, LuaString};
1716
use crate::table::Table;
1817
use crate::thread::Thread;
1918
use crate::traits::{FromLua, IntoLua, ShortTypeName as _};
@@ -47,14 +46,14 @@ impl FromLua for Value {
4746
}
4847
}
4948

50-
impl IntoLua for String {
49+
impl IntoLua for LuaString {
5150
#[inline]
5251
fn into_lua(self, _: &Lua) -> Result<Value> {
5352
Ok(Value::String(self))
5453
}
5554
}
5655

57-
impl IntoLua for &String {
56+
impl IntoLua for &LuaString {
5857
#[inline]
5958
fn into_lua(self, _: &Lua) -> Result<Value> {
6059
Ok(Value::String(self.clone()))
@@ -67,9 +66,9 @@ impl IntoLua for &String {
6766
}
6867
}
6968

70-
impl FromLua for String {
69+
impl FromLua for LuaString {
7170
#[inline]
72-
fn from_lua(value: Value, lua: &Lua) -> Result<String> {
71+
fn from_lua(value: Value, lua: &Lua) -> Result<LuaString> {
7372
let ty = value.type_name();
7473
lua.coerce_string(value)?
7574
.ok_or_else(|| Error::FromLuaConversionError {
@@ -84,7 +83,7 @@ impl FromLua for String {
8483
let type_id = ffi::lua_type(state, idx);
8584
if type_id == ffi::LUA_TSTRING {
8685
ffi::lua_xpush(state, lua.ref_thread(), idx);
87-
return Ok(String(lua.pop_ref_thread()));
86+
return Ok(LuaString(lua.pop_ref_thread()));
8887
}
8988
// Fallback to default
9089
Self::from_lua(lua.stack_value(idx, Some(type_id)), lua.lua())
@@ -119,15 +118,15 @@ impl IntoLua for &BorrowedStr<'_> {
119118

120119
impl FromLua for BorrowedStr<'_> {
121120
fn from_lua(value: Value, lua: &Lua) -> Result<Self> {
122-
let s = String::from_lua(value, lua)?;
121+
let s = LuaString::from_lua(value, lua)?;
123122
let BorrowedStr { buf, _lua, .. } = BorrowedStr::try_from(&s)?;
124123
let buf = unsafe { mem::transmute::<&str, &'static str>(buf) };
125124
let borrow = Cow::Owned(s);
126125
Ok(Self { buf, borrow, _lua })
127126
}
128127

129128
unsafe fn from_stack(idx: c_int, lua: &RawLua) -> Result<Self> {
130-
let s = String::from_stack(idx, lua)?;
129+
let s = LuaString::from_stack(idx, lua)?;
131130
let BorrowedStr { buf, _lua, .. } = BorrowedStr::try_from(&s)?;
132131
let buf = unsafe { mem::transmute::<&str, &'static str>(buf) };
133132
let borrow = Cow::Owned(s);
@@ -163,15 +162,15 @@ impl IntoLua for &BorrowedBytes<'_> {
163162

164163
impl FromLua for BorrowedBytes<'_> {
165164
fn from_lua(value: Value, lua: &Lua) -> Result<Self> {
166-
let s = String::from_lua(value, lua)?;
165+
let s = LuaString::from_lua(value, lua)?;
167166
let BorrowedBytes { buf, _lua, .. } = BorrowedBytes::from(&s);
168167
let buf = unsafe { mem::transmute::<&[u8], &'static [u8]>(buf) };
169168
let borrow = Cow::Owned(s);
170169
Ok(Self { buf, borrow, _lua })
171170
}
172171

173172
unsafe fn from_stack(idx: c_int, lua: &RawLua) -> Result<Self> {
174-
let s = String::from_stack(idx, lua)?;
173+
let s = LuaString::from_stack(idx, lua)?;
175174
let BorrowedBytes { buf, _lua, .. } = BorrowedBytes::from(&s);
176175
let buf = unsafe { mem::transmute::<&[u8], &'static [u8]>(buf) };
177176
let borrow = Cow::Owned(s);
@@ -497,7 +496,7 @@ impl FromLua for crate::Buffer {
497496
}
498497
}
499498

500-
impl IntoLua for StdString {
499+
impl IntoLua for String {
501500
#[inline]
502501
fn into_lua(self, lua: &Lua) -> Result<Value> {
503502
#[cfg(feature = "lua55")]
@@ -519,7 +518,7 @@ impl IntoLua for StdString {
519518
}
520519
}
521520

522-
impl FromLua for StdString {
521+
impl FromLua for String {
523522
#[inline]
524523
fn from_lua(value: Value, lua: &Lua) -> Result<Self> {
525524
let ty = value.type_name();

0 commit comments

Comments
 (0)