Closed han1548772930 closed 9 months ago
It should work as expected.
Here is a complete working example that raises and outputs an error:
use rust_xlsxwriter::{Workbook, XlsxError};
fn main() -> Result<(), String> {
let res: Result<(), XlsxError> = export_excel();
return match res {
Ok(_) => Ok(()),
Err(e) => {
return Err(e.to_string());
}
};
}
fn export_excel() -> Result<(), XlsxError> {
let mut workbook = Workbook::new();
let worksheet = workbook.add_worksheet();
// This will raise an error.
worksheet.write(0, 16_384, "Hello")?;
// Save the file to disk.
workbook.save("gh68.xlsx")?;
Ok(())
}
Output:
$ cargo run --example gh68
Compiling rust_xlsxwriter v0.60.0 (/path/rust_xlsxwriter)
Finished dev [unoptimized + debuginfo] target(s) in 0.47s
Running `target/debug/examples/gh68`
Error: "Row or column exceeds Excel's allowed limits (1,048,576 x 16,384)."
tokio::spawn(async move {
let res: Result<(), XlsxError> = export_excel(uf_map_list, tgt_path, false, true).await;
return match res {
Ok(_) => {
Ok(())
}
Err(e) => {
log::error!("err:{}", e);
return Err(e.to_string().as_str());
}
};
});
My approximate code is like this
And what is the error that you get?
error[E0515]: cannot return value referencing temporary value
--> src\ufmap\TSKMapping.rs:569:17
|
569 | Err(e.to_string().as_str())
| ^^^^-------------^^^^^^^^^^
| | |
| | temporary value created here
| returns a value referencing data owned by the current function
That is just a general rust issue where you can't return a &str
from a function without specifying some lifetime. See for example:
https://stackoverflow.com/questions/29781331/why-cant-i-return-an-str-value-generated-from-a-string
It doesn't have anything to do with rust_xlsxwriter
.
I changed the way it works now
let res: Result<(), XlsxError> = export_excel(uf_map_list, tgt_path, false, true).await;
return match res {
Ok(_) => {
"".to_string()
}
Err(e) => {
log::error!("err:{}", e);
e.to_string()
}
};
That is just a general rust issue where you can't return a
&str
from a function without specifying some lifetime. See for example:https://stackoverflow.com/questions/29781331/why-cant-i-return-an-str-value-generated-from-a-string
It doesn't have anything to do with
rust_xlsxwriter
.
I'm really attracted to the potential and capabilities of this framework. It has earned my utmost admiration and support, and I've shown a little heartfelt support by sponsoring $10
I'm really attracted to the potential and capabilities of this framework. It has earned my utmost admiration and support, and I've shown a little heartfelt support by sponsoring $10
Thank you for the kind words and the donation. :-)
Current behavior
Any other information
No response