I'm creating a Rust
app that needs to save and load files with its own custom file format, similar to Photoshop and Illustrator save/load to .psd
and .ai
files, respectively.
How do I go about "defining" my own file format so that the OS recognizes it and will use my app to open this file format (
.mtp
is the filetype's extension name)?How do I develop a means of parsing this file format in my app?
In reality, my app is saving to a JSON
style structure via Serde
. I want this file extension to distinguish the file type as something unique to my app so that users don't load random .json files into the app.
struct MyApp{
name: String,
content: String,
}
impl MyApp{
save_file(&self, path: String)->std::io::Result<()>{
let mut file = std::fs:File::create(path)?;
Ok(())
}
load_file(&self, path: String)->std::io::Result<()>{
let mut file = std::fs:File::open(path)?;
//do something with the file
Ok(())
}
}
fn main(){
//using my own custom .mtp format
let app = MyApp{
name: "CoolApp".to_string(),
content: "some information".to_string(),
}
app.save_fle("output/my_path.mtp");
app.load_file("output/my_path.mtp");
}