11use crate :: { StdFunction , StdlibModule , StdlibRegistry } ;
22use std:: collections:: HashMap ;
33use std:: rc:: Rc ;
4- use techscript_runtime:: { error:: RuntimeError , error:: RuntimeErrorKind , value:: RuntimeValue } ;
54use techscript_runtime:: RuntimeContext ;
5+ use techscript_runtime:: { error:: RuntimeError , error:: RuntimeErrorKind , value:: RuntimeValue } ;
66
77fn trim ( _ctx : & mut RuntimeContext , args : Vec < RuntimeValue > ) -> Result < RuntimeValue , RuntimeError > {
88 let s = args[ 0 ] . try_into_string ( ) ?;
99 Ok ( RuntimeValue :: Str ( s. trim ( ) . to_string ( ) ) )
1010}
1111
12- fn replace ( _ctx : & mut RuntimeContext , args : Vec < RuntimeValue > ) -> Result < RuntimeValue , RuntimeError > {
12+ fn replace (
13+ _ctx : & mut RuntimeContext ,
14+ args : Vec < RuntimeValue > ,
15+ ) -> Result < RuntimeValue , RuntimeError > {
1316 let source = args[ 0 ] . try_into_string ( ) ?;
1417 let from = args[ 1 ] . try_into_string ( ) ?;
1518 let to = args[ 2 ] . try_into_string ( ) ?;
@@ -49,50 +52,77 @@ fn join(_ctx: &mut RuntimeContext, args: Vec<RuntimeValue>) -> Result<RuntimeVal
4952 }
5053}
5154
52- fn to_lower ( _ctx : & mut RuntimeContext , args : Vec < RuntimeValue > ) -> Result < RuntimeValue , RuntimeError > {
55+ fn to_lower (
56+ _ctx : & mut RuntimeContext ,
57+ args : Vec < RuntimeValue > ,
58+ ) -> Result < RuntimeValue , RuntimeError > {
5359 let s = args[ 0 ] . try_into_string ( ) ?;
5460 Ok ( RuntimeValue :: Str ( s. to_lowercase ( ) ) )
5561}
5662
57- fn to_upper ( _ctx : & mut RuntimeContext , args : Vec < RuntimeValue > ) -> Result < RuntimeValue , RuntimeError > {
63+ fn to_upper (
64+ _ctx : & mut RuntimeContext ,
65+ args : Vec < RuntimeValue > ,
66+ ) -> Result < RuntimeValue , RuntimeError > {
5867 let s = args[ 0 ] . try_into_string ( ) ?;
5968 Ok ( RuntimeValue :: Str ( s. to_uppercase ( ) ) )
6069}
6170
62- fn contains ( _ctx : & mut RuntimeContext , args : Vec < RuntimeValue > ) -> Result < RuntimeValue , RuntimeError > {
71+ fn contains (
72+ _ctx : & mut RuntimeContext ,
73+ args : Vec < RuntimeValue > ,
74+ ) -> Result < RuntimeValue , RuntimeError > {
6375 let s = args[ 0 ] . try_into_string ( ) ?;
6476 let sub = args[ 1 ] . try_into_string ( ) ?;
6577 Ok ( RuntimeValue :: Bool ( s. contains ( & sub) ) )
6678}
6779
68- fn from_int ( _ctx : & mut RuntimeContext , args : Vec < RuntimeValue > ) -> Result < RuntimeValue , RuntimeError > {
80+ fn from_int (
81+ _ctx : & mut RuntimeContext ,
82+ args : Vec < RuntimeValue > ,
83+ ) -> Result < RuntimeValue , RuntimeError > {
6984 let val = args[ 0 ] . try_into_int ( ) ?;
7085 Ok ( RuntimeValue :: Str ( val. to_string ( ) ) )
7186}
7287
73- fn from_float ( _ctx : & mut RuntimeContext , args : Vec < RuntimeValue > ) -> Result < RuntimeValue , RuntimeError > {
88+ fn from_float (
89+ _ctx : & mut RuntimeContext ,
90+ args : Vec < RuntimeValue > ,
91+ ) -> Result < RuntimeValue , RuntimeError > {
7492 let val = args[ 0 ] . try_into_float ( ) ?;
7593 Ok ( RuntimeValue :: Str ( val. to_string ( ) ) )
7694}
7795
78- fn from_bool ( _ctx : & mut RuntimeContext , args : Vec < RuntimeValue > ) -> Result < RuntimeValue , RuntimeError > {
96+ fn from_bool (
97+ _ctx : & mut RuntimeContext ,
98+ args : Vec < RuntimeValue > ,
99+ ) -> Result < RuntimeValue , RuntimeError > {
79100 let val = args[ 0 ] . try_into_bool ( ) ?;
80101 Ok ( RuntimeValue :: Str ( val. to_string ( ) ) )
81102}
82103
83- fn trim ( _ctx : & mut techscript_runtime:: RuntimeContext , args : Vec < RuntimeValue > ) -> Result < RuntimeValue , RuntimeError > {
104+ fn trim (
105+ _ctx : & mut techscript_runtime:: RuntimeContext ,
106+ args : Vec < RuntimeValue > ,
107+ ) -> Result < RuntimeValue , RuntimeError > {
84108 let s = args[ 0 ] . try_into_string ( ) ?;
85109 Ok ( RuntimeValue :: Str ( s. trim ( ) . to_string ( ) ) )
86110}
87111
88- fn replace ( _ctx : & mut techscript_runtime:: RuntimeContext , args : Vec < RuntimeValue > ) -> Result < RuntimeValue , RuntimeError > {
112+ fn replace (
113+ _ctx : & mut techscript_runtime:: RuntimeContext ,
114+ args : Vec < RuntimeValue > ,
115+ ) -> Result < RuntimeValue , RuntimeError > {
89116 let source = args[ 0 ] . try_into_string ( ) ?;
90117 let from = args[ 1 ] . try_into_string ( ) ?;
91118 let to = args[ 2 ] . try_into_string ( ) ?;
92119 Ok ( RuntimeValue :: Str ( source. replace ( & from, & to) ) )
93120}
94121
95- fn split ( _ctx : & mut techscript_runtime:: RuntimeContext , args : Vec < RuntimeValue > ) -> Result < RuntimeValue , RuntimeError > {
122+ fn split (
123+ _ctx : & mut techscript_runtime:: RuntimeContext ,
124+ args : Vec < RuntimeValue > ,
125+ ) -> Result < RuntimeValue , RuntimeError > {
96126 let s = args[ 0 ] . try_into_string ( ) ?;
97127 let pat = args[ 1 ] . try_into_string ( ) ?;
98128 let parts: Vec < RuntimeValue > = s
@@ -105,7 +135,10 @@ fn split(_ctx: &mut techscript_runtime::RuntimeContext, args: Vec<RuntimeValue>)
105135 } )
106136}
107137
108- fn join ( _ctx : & mut techscript_runtime:: RuntimeContext , args : Vec < RuntimeValue > ) -> Result < RuntimeValue , RuntimeError > {
138+ fn join (
139+ _ctx : & mut techscript_runtime:: RuntimeContext ,
140+ args : Vec < RuntimeValue > ,
141+ ) -> Result < RuntimeValue , RuntimeError > {
109142 let sep = args[ 1 ] . try_into_string ( ) ?;
110143 if let RuntimeValue :: List { items, .. } = & args[ 0 ] {
111144 let mut str_parts = Vec :: new ( ) ;
@@ -125,33 +158,51 @@ fn join(_ctx: &mut techscript_runtime::RuntimeContext, args: Vec<RuntimeValue>)
125158 }
126159}
127160
128- fn to_lower ( _ctx : & mut techscript_runtime:: RuntimeContext , args : Vec < RuntimeValue > ) -> Result < RuntimeValue , RuntimeError > {
161+ fn to_lower (
162+ _ctx : & mut techscript_runtime:: RuntimeContext ,
163+ args : Vec < RuntimeValue > ,
164+ ) -> Result < RuntimeValue , RuntimeError > {
129165 let s = args[ 0 ] . try_into_string ( ) ?;
130166 Ok ( RuntimeValue :: Str ( s. to_lowercase ( ) ) )
131167}
132168
133- fn to_upper ( _ctx : & mut techscript_runtime:: RuntimeContext , args : Vec < RuntimeValue > ) -> Result < RuntimeValue , RuntimeError > {
169+ fn to_upper (
170+ _ctx : & mut techscript_runtime:: RuntimeContext ,
171+ args : Vec < RuntimeValue > ,
172+ ) -> Result < RuntimeValue , RuntimeError > {
134173 let s = args[ 0 ] . try_into_string ( ) ?;
135174 Ok ( RuntimeValue :: Str ( s. to_uppercase ( ) ) )
136175}
137176
138- fn contains ( _ctx : & mut techscript_runtime:: RuntimeContext , args : Vec < RuntimeValue > ) -> Result < RuntimeValue , RuntimeError > {
177+ fn contains (
178+ _ctx : & mut techscript_runtime:: RuntimeContext ,
179+ args : Vec < RuntimeValue > ,
180+ ) -> Result < RuntimeValue , RuntimeError > {
139181 let s = args[ 0 ] . try_into_string ( ) ?;
140182 let sub = args[ 1 ] . try_into_string ( ) ?;
141183 Ok ( RuntimeValue :: Bool ( s. contains ( & sub) ) )
142184}
143185
144- fn from_int ( _ctx : & mut techscript_runtime:: RuntimeContext , args : Vec < RuntimeValue > ) -> Result < RuntimeValue , RuntimeError > {
186+ fn from_int (
187+ _ctx : & mut techscript_runtime:: RuntimeContext ,
188+ args : Vec < RuntimeValue > ,
189+ ) -> Result < RuntimeValue , RuntimeError > {
145190 let val = args[ 0 ] . try_into_int ( ) ?;
146191 Ok ( RuntimeValue :: Str ( val. to_string ( ) ) )
147192}
148193
149- fn from_float ( _ctx : & mut techscript_runtime:: RuntimeContext , args : Vec < RuntimeValue > ) -> Result < RuntimeValue , RuntimeError > {
194+ fn from_float (
195+ _ctx : & mut techscript_runtime:: RuntimeContext ,
196+ args : Vec < RuntimeValue > ,
197+ ) -> Result < RuntimeValue , RuntimeError > {
150198 let val = args[ 0 ] . try_into_float ( ) ?;
151199 Ok ( RuntimeValue :: Str ( val. to_string ( ) ) )
152200}
153201
154- fn from_bool ( _ctx : & mut techscript_runtime:: RuntimeContext , args : Vec < RuntimeValue > ) -> Result < RuntimeValue , RuntimeError > {
202+ fn from_bool (
203+ _ctx : & mut techscript_runtime:: RuntimeContext ,
204+ args : Vec < RuntimeValue > ,
205+ ) -> Result < RuntimeValue , RuntimeError > {
155206 let val = args[ 0 ] . try_into_bool ( ) ?;
156207 Ok ( RuntimeValue :: Str ( val. to_string ( ) ) )
157208}
0 commit comments