pub struct ShortcutOptions {
pub arguments: Vec<OsString>,
pub working_directory: Option<PathBuf>,
pub icon: Option<ShortcutIcon>,
pub description: Option<String>,
}Expand description
Options used when creating a Windows .lnk shortcut.
§Examples
let options = win_desktop_utils::ShortcutOptions::new()
.argument("--safe-mode")
.working_directory(r"C:\Windows")
.icon(r"C:\Windows\notepad.exe", 0)
.description("Open a tool");
assert_eq!(options.arguments.len(), 1);
assert!(options.working_directory.is_some());
assert!(options.icon.is_some());
assert_eq!(options.description.as_deref(), Some("Open a tool"));Fields§
§arguments: Vec<OsString>Command-line arguments stored in the shortcut.
working_directory: Option<PathBuf>Optional working directory for the shortcut target.
icon: Option<ShortcutIcon>Optional icon resource for the shortcut.
description: Option<String>Optional user-facing shortcut description.
Implementations§
Source§impl ShortcutOptions
impl ShortcutOptions
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates options with no arguments, working directory, icon, or description.
Examples found in repository?
examples/shortcuts.rs (line 6)
1fn main() -> Result<(), Box<dyn std::error::Error>> {
2 let cwd = std::env::current_dir()?;
3 let notepad = r"C:\Windows\notepad.exe";
4
5 let lnk_path = cwd.join("notepad-demo.lnk");
6 let options = win_desktop_utils::ShortcutOptions::new()
7 .description("Open Notepad")
8 .working_directory(r"C:\Windows")
9 .icon(notepad, 0);
10
11 win_desktop_utils::create_shortcut(&lnk_path, notepad, &options)?;
12 println!("created shortcut: {}", lnk_path.display());
13
14 let url_path = cwd.join("rust-docs.url");
15 win_desktop_utils::create_url_shortcut(&url_path, "https://doc.rust-lang.org/std/")?;
16 println!("created URL shortcut: {}", url_path.display());
17
18 Ok(())
19}Sourcepub fn arguments<I, S>(self, arguments: I) -> Self
pub fn arguments<I, S>(self, arguments: I) -> Self
Replaces the command-line arguments stored in the shortcut.
Sourcepub fn argument(self, argument: impl Into<OsString>) -> Self
pub fn argument(self, argument: impl Into<OsString>) -> Self
Appends one command-line argument stored in the shortcut.
Sourcepub fn working_directory(self, path: impl Into<PathBuf>) -> Self
pub fn working_directory(self, path: impl Into<PathBuf>) -> Self
Sets the working directory used when the shortcut target starts.
Examples found in repository?
examples/shortcuts.rs (line 8)
1fn main() -> Result<(), Box<dyn std::error::Error>> {
2 let cwd = std::env::current_dir()?;
3 let notepad = r"C:\Windows\notepad.exe";
4
5 let lnk_path = cwd.join("notepad-demo.lnk");
6 let options = win_desktop_utils::ShortcutOptions::new()
7 .description("Open Notepad")
8 .working_directory(r"C:\Windows")
9 .icon(notepad, 0);
10
11 win_desktop_utils::create_shortcut(&lnk_path, notepad, &options)?;
12 println!("created shortcut: {}", lnk_path.display());
13
14 let url_path = cwd.join("rust-docs.url");
15 win_desktop_utils::create_url_shortcut(&url_path, "https://doc.rust-lang.org/std/")?;
16 println!("created URL shortcut: {}", url_path.display());
17
18 Ok(())
19}Sourcepub fn icon(self, path: impl Into<PathBuf>, index: i32) -> Self
pub fn icon(self, path: impl Into<PathBuf>, index: i32) -> Self
Sets the icon resource used by Explorer for the shortcut.
Examples found in repository?
examples/shortcuts.rs (line 9)
1fn main() -> Result<(), Box<dyn std::error::Error>> {
2 let cwd = std::env::current_dir()?;
3 let notepad = r"C:\Windows\notepad.exe";
4
5 let lnk_path = cwd.join("notepad-demo.lnk");
6 let options = win_desktop_utils::ShortcutOptions::new()
7 .description("Open Notepad")
8 .working_directory(r"C:\Windows")
9 .icon(notepad, 0);
10
11 win_desktop_utils::create_shortcut(&lnk_path, notepad, &options)?;
12 println!("created shortcut: {}", lnk_path.display());
13
14 let url_path = cwd.join("rust-docs.url");
15 win_desktop_utils::create_url_shortcut(&url_path, "https://doc.rust-lang.org/std/")?;
16 println!("created URL shortcut: {}", url_path.display());
17
18 Ok(())
19}Sourcepub fn description(self, description: impl Into<String>) -> Self
pub fn description(self, description: impl Into<String>) -> Self
Sets the shortcut description shown by Explorer.
Examples found in repository?
examples/shortcuts.rs (line 7)
1fn main() -> Result<(), Box<dyn std::error::Error>> {
2 let cwd = std::env::current_dir()?;
3 let notepad = r"C:\Windows\notepad.exe";
4
5 let lnk_path = cwd.join("notepad-demo.lnk");
6 let options = win_desktop_utils::ShortcutOptions::new()
7 .description("Open Notepad")
8 .working_directory(r"C:\Windows")
9 .icon(notepad, 0);
10
11 win_desktop_utils::create_shortcut(&lnk_path, notepad, &options)?;
12 println!("created shortcut: {}", lnk_path.display());
13
14 let url_path = cwd.join("rust-docs.url");
15 win_desktop_utils::create_url_shortcut(&url_path, "https://doc.rust-lang.org/std/")?;
16 println!("created URL shortcut: {}", url_path.display());
17
18 Ok(())
19}Trait Implementations§
Source§impl Clone for ShortcutOptions
impl Clone for ShortcutOptions
Source§fn clone(&self) -> ShortcutOptions
fn clone(&self) -> ShortcutOptions
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ShortcutOptions
impl Debug for ShortcutOptions
Source§impl Default for ShortcutOptions
impl Default for ShortcutOptions
Source§fn default() -> ShortcutOptions
fn default() -> ShortcutOptions
Returns the “default value” for a type. Read more
Source§impl PartialEq for ShortcutOptions
impl PartialEq for ShortcutOptions
impl Eq for ShortcutOptions
impl StructuralPartialEq for ShortcutOptions
Auto Trait Implementations§
impl Freeze for ShortcutOptions
impl RefUnwindSafe for ShortcutOptions
impl Send for ShortcutOptions
impl Sync for ShortcutOptions
impl Unpin for ShortcutOptions
impl UnsafeUnpin for ShortcutOptions
impl UnwindSafe for ShortcutOptions
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more