mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-04-18 03:00:27 -04:00
Rc<String> -> Rc<str>
This commit is contained in:
@@ -18,12 +18,12 @@ use super::{
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct StringIterator {
|
||||
pub string: Rc<String>,
|
||||
pub string: Rc<str>,
|
||||
pub index: usize,
|
||||
}
|
||||
|
||||
impl StringIterator {
|
||||
pub fn new(string: Rc<String>) -> StringIterator {
|
||||
pub fn new(string: Rc<str>) -> StringIterator {
|
||||
StringIterator { string, index: 0 }
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ use crate::{
|
||||
ValTrait,
|
||||
};
|
||||
|
||||
pub fn op_sub_string(string_data: &Rc<String>, subscript: &Val) -> Val {
|
||||
pub fn op_sub_string(string_data: &Rc<str>, subscript: &Val) -> Val {
|
||||
if let Some(subscript) = subscript.to_index() {
|
||||
let string_bytes = string_data.as_bytes();
|
||||
|
||||
@@ -133,10 +133,13 @@ static CODE_POINT_AT: NativeFunction = native_fn(|this, params| {
|
||||
static CONCAT: NativeFunction = native_fn(|this, params| {
|
||||
Ok(match this.get() {
|
||||
Val::String(string_data) => {
|
||||
let mut result = string_data.as_str().to_string();
|
||||
let mut result = string_data.to_string();
|
||||
|
||||
for param in params {
|
||||
result.push_str(param.to_string().as_str());
|
||||
match param {
|
||||
Val::String(str) => result.push_str(&str),
|
||||
_ => result.push_str(param.to_string().as_str()),
|
||||
};
|
||||
}
|
||||
|
||||
result.to_val()
|
||||
|
||||
@@ -27,7 +27,7 @@ pub enum Val {
|
||||
Number(f64),
|
||||
BigInt(BigInt),
|
||||
Symbol(VsSymbol),
|
||||
String(Rc<String>),
|
||||
String(Rc<str>),
|
||||
Array(Rc<VsArray>),
|
||||
Object(Rc<VsObject>),
|
||||
Function(Rc<VsFunction>),
|
||||
@@ -638,13 +638,13 @@ impl ToVal for char {
|
||||
|
||||
impl ToVal for &str {
|
||||
fn to_val(self) -> Val {
|
||||
Val::String(Rc::new(self.to_string()))
|
||||
Val::String(Rc::from(self.to_owned()))
|
||||
}
|
||||
}
|
||||
|
||||
impl ToVal for String {
|
||||
fn to_val(self) -> Val {
|
||||
Val::String(Rc::new(self))
|
||||
Val::String(Rc::from(self))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -798,7 +798,7 @@ pub fn number_to_index(x: f64) -> Option<usize> {
|
||||
return Some(x as usize);
|
||||
}
|
||||
|
||||
fn stringify_string(str: &String) -> String {
|
||||
fn stringify_string(str: &str) -> String {
|
||||
let mut res: String = "\"".into();
|
||||
|
||||
for c in str.chars() {
|
||||
|
||||
Reference in New Issue
Block a user