-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
812075a
commit 6690e16
Showing
6 changed files
with
59 additions
and
10 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,41 @@ | ||
// Prevents additional console window on Windows in release, DO NOT REMOVE!! | ||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] | ||
|
||
// Learn more about Tauri commands at https://tauri.app/v1/guides/features/command | ||
use std::fs::File; | ||
use std::path::Path; | ||
use std::io::prelude::*; | ||
use csv; | ||
|
||
fn check_file(path: &str) -> bool { | ||
Path::new(path).exists() | ||
} | ||
|
||
fn create_file(path: &str) -> std::io::Result<()> { | ||
let mut file = File::create(path)?; | ||
file.write_all(b"Name,Age,City\nJohn,30,New York\nJane,25,San Francisco\n")?; | ||
Ok(()) | ||
} | ||
|
||
#[tauri::command] | ||
fn greet(name: &str) -> String { | ||
format!("Hello, {}! You've been greeted from Rust!", name) | ||
fn read_from_file(path: &str) -> Result<(), String> { | ||
|
||
if !check_file(path) { | ||
create_file(path).map_err(|e| e.to_string())?; | ||
println!("File created: {}", path); | ||
} | ||
|
||
let mut reader = csv::Reader::from_path(path).map_err(|e| e.to_string())?; | ||
|
||
for result in reader.records() { | ||
let record = result.map_err(|e| e.to_string())?; | ||
println!("{:?}", record); | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn main() { | ||
tauri::Builder::default() | ||
.invoke_handler(tauri::generate_handler![greet]) | ||
.invoke_handler(tauri::generate_handler![read_from_file]) | ||
.run(tauri::generate_context!()) | ||
.expect("error while running tauri application"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters