Hello, all functioned very well in my "Give Powershell-Scripts an new home in an rust executable " Project but with only simple mods and simple functions in that includes. Now i have problem with reusing an Variable while rust is running and this is the time for an fresh starts into the structs/impl mechanism in rust.
pub struct PSScripts
{
pub data: String,
}
impl PSScripts
{
pub fn new(ScriptName: &str) -> PSScripts
{
let mut scriptdata: String = "fooBar".to_string();
if (ScriptName == "MakeLnk")
{
println!("{:?}", "foo");
scriptdata = include_str!(r"..\..\MakeLnk.ps1").to_string();
}
createTmpScriptFile("MakeLnk.ps1",&scriptdata);
PSScripts
{
data: scriptdata.to_string(),
}
}
}
pub fn writeLnk(lnkPath: &str, lnkTarget: &str, lnkArgs: &str, lnkIcon: &str)
{
use std::process::{Command, Stdio};
let lnk_script = PSScripts::new ("MakeLnk");
So yes the problem that include! macros only accepts literals i have solved with an classical if statement and furthermore i will remove the strcut data (is useless) and only put an scriptname struct variable in this. The code above is only for showing my understandings and codings before i come here and quest a question:).
So my problem: I want an in other Languages so called object that i can reuse, when i call the function writeLnk rust don't reuse the lnk_script variable and include to scriptdata twice and create the scriptfile by every calling the function writeLnk.
So the creation of the scriptfile can i pass by with an file_exist, cool but his passby will be unneccessary when i can rust say that he don't must recreate the lnk_script variable and reuse this variable every time when i call write_lnk again.
thx