pub trait Exportable {
type Error: Error + Send + Sync + 'static + From<Error>;
type ExportOptions: Default;
// Required methods
fn export_to_writer_with_options<W: Write>(
&self,
writer: W,
format: &str,
options: Self::ExportOptions,
) -> Result<(), Self::Error>;
fn known_export_formats() -> Vec<ExtensionWithMime>;
// Provided methods
fn export_to_writer<W: Write>(
&self,
writer: W,
format: &str,
) -> Result<(), Self::Error> { ... }
fn export_to_path_with_options<P: AsRef<Path>>(
&self,
path: P,
options: Self::ExportOptions,
) -> Result<(), Self::Error> { ... }
fn export_to_path<P: AsRef<Path>>(&self, path: P) -> Result<(), Self::Error> { ... }
fn export_to_bytes_with_options(
&self,
format: &str,
options: Self::ExportOptions,
) -> Result<Vec<u8>, Self::Error> { ... }
fn export_to_bytes(&self, format: &str) -> Result<Vec<u8>, Self::Error> { ... }
fn infer_format(path: &Path) -> Option<String> { ... }
}Expand description
Trait for exporting types to a file path or writer
Required Associated Types§
Sourcetype Error: Error + Send + Sync + 'static + From<Error>
type Error: Error + Send + Sync + 'static + From<Error>
The error type returned by export operations
Sourcetype ExportOptions: Default
type ExportOptions: Default
Export options
Required Methods§
Sourcefn export_to_writer_with_options<W: Write>(
&self,
writer: W,
format: &str,
options: Self::ExportOptions,
) -> Result<(), Self::Error>
fn export_to_writer_with_options<W: Write>( &self, writer: W, format: &str, options: Self::ExportOptions, ) -> Result<(), Self::Error>
Export to a writer, specifying the format and export options.
Sourcefn known_export_formats() -> Vec<ExtensionWithMime>
fn known_export_formats() -> Vec<ExtensionWithMime>
Get known export formats
This function can be used to suggest exports formats or construct file chooser filters
Provided Methods§
Sourcefn export_to_writer<W: Write>(
&self,
writer: W,
format: &str,
) -> Result<(), Self::Error>
fn export_to_writer<W: Write>( &self, writer: W, format: &str, ) -> Result<(), Self::Error>
Export to a writer, specifying the format.
Sourcefn export_to_path_with_options<P: AsRef<Path>>(
&self,
path: P,
options: Self::ExportOptions,
) -> Result<(), Self::Error>
fn export_to_path_with_options<P: AsRef<Path>>( &self, path: P, options: Self::ExportOptions, ) -> Result<(), Self::Error>
Export to a file path, optionally specifying the format and export options.
Sourcefn export_to_path<P: AsRef<Path>>(&self, path: P) -> Result<(), Self::Error>
fn export_to_path<P: AsRef<Path>>(&self, path: P) -> Result<(), Self::Error>
Export to a file path, optionally specifying the format.
Examples found in repository?
examples/petri_net_import_export.rs (line 25)
6fn main() -> Result<(), Box<dyn Error>> {
7 let args: Vec<String> = env::args().collect();
8 if args.len() != 3 {
9 eprintln!("Usage: {} <input_pnml_path> <output_pnml_path>", args[0]);
10 std::process::exit(1);
11 }
12
13 let input_path = PathBuf::from(&args[1]);
14 let output_path = PathBuf::from(&args[2]);
15
16 println!("Importing Petri net from {:?}", input_path);
17 let petri_net = PetriNet::import_from_path(&input_path)?;
18
19 println!("Petri net stats:");
20 println!(" Places: {}", petri_net.places.len());
21 println!(" Transitions: {}", petri_net.transitions.len());
22 println!(" Arcs: {}", petri_net.arcs.len());
23
24 println!("Exporting Petri net to {:?}", output_path);
25 petri_net.export_to_path(&output_path)?;
26
27 println!("Done!");
28 Ok(())
29}More examples
examples/ocel_duckdb_export.rs (line 24)
6pub fn main() -> Result<(), Box<dyn Error>> {
7 let path_opt = args().nth(1);
8 if let Some(mut path) = path_opt.map(PathBuf::from) {
9 let mut ocel = OCEL::import_from_path(&path)?;
10 // Including invalid E2O relations (i.e., to objects that do not exist) can cause corrupted or incomplete SQL exports
11 // Thus, we filter the E2O relations to only keep valid ones
12 let all_obj_ids: HashSet<_> = ocel.objects.iter().map(|o| &o.id).collect();
13 for e in &mut ocel.events {
14 e.relationships
15 .retain(|r| all_obj_ids.contains(&r.object_id));
16 }
17 // Export
18 path.set_file_name(format!(
19 "{}.duckdb",
20 path.file_name()
21 .and_then(|p| p.to_str())
22 .unwrap_or_default()
23 ));
24 ocel.export_to_path(&path)?;
25 }
26 Ok(())
27}examples/process_discovery.rs (line 37)
10fn main() -> Result<(), Box<dyn Error>> {
11 let args: Vec<String> = env::args().collect();
12 if args.len() != 3 {
13 eprintln!("Usage: {} <path_to_event_log> <output_pnml_path>", args[0]);
14 std::process::exit(1);
15 }
16
17 let input_path = PathBuf::from(&args[1]);
18 let output_path = PathBuf::from(&args[2]);
19
20 println!("Importing event log from {:?}", input_path);
21 let log = EventLog::import_from_path(&input_path)?;
22
23 println!("Converting to activity projection...");
24 let projection = EventLogActivityProjection::from(&log);
25
26 println!("Discovering Petri net using Alpha+++...");
27 let config = AlphaPPPConfig::default();
28 let petri_net = alphappp_discover_petri_net(&projection, config);
29
30 println!(
31 "Discovered Petri net with {} places and {} transitions.",
32 petri_net.places.len(),
33 petri_net.transitions.len()
34 );
35
36 println!("Exporting Petri net to {:?}", output_path);
37 petri_net.export_to_path(&output_path)?;
38
39 println!("Done!");
40 Ok(())
41}Sourcefn export_to_bytes_with_options(
&self,
format: &str,
options: Self::ExportOptions,
) -> Result<Vec<u8>, Self::Error>
fn export_to_bytes_with_options( &self, format: &str, options: Self::ExportOptions, ) -> Result<Vec<u8>, Self::Error>
Export as a byte array with the specified options
Sourcefn infer_format(path: &Path) -> Option<String>
fn infer_format(path: &Path) -> Option<String>
Infer format from path.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.