pub struct SshConfigFile {
pub elements: Vec<ConfigElement>,
pub path: PathBuf,
pub crlf: bool,
}Expand description
Represents the entire SSH config file as a sequence of elements. Preserves the original structure for round-trip fidelity.
Fields§
§elements: Vec<ConfigElement>§path: PathBuf§crlf: boolWhether the original file used CRLF line endings.
Implementations§
Source§impl SshConfigFile
impl SshConfigFile
Sourcepub fn host_entries(&self) -> Vec<HostEntry>
pub fn host_entries(&self) -> Vec<HostEntry>
Get all host entries as convenience views (including from Include files).
Sourcepub fn include_paths(&self) -> Vec<PathBuf>
pub fn include_paths(&self) -> Vec<PathBuf>
Collect all resolved Include file paths (recursively).
Sourcepub fn include_glob_dirs(&self) -> Vec<PathBuf>
pub fn include_glob_dirs(&self) -> Vec<PathBuf>
Collect parent directories of Include glob patterns. When a file is added/removed under a glob dir, the directory’s mtime changes.
Sourcepub fn has_host(&self, alias: &str) -> bool
pub fn has_host(&self, alias: &str) -> bool
Check if a host alias already exists (including in Include files). Walks the element tree directly without building HostEntry structs.
Sourcepub fn is_included_host(&self, alias: &str) -> bool
pub fn is_included_host(&self, alias: &str) -> bool
Check if a host alias is from an included file (read-only). Handles multi-pattern Host lines by splitting on whitespace.
Sourcepub fn last_element_has_trailing_blank(&self) -> bool
pub fn last_element_has_trailing_blank(&self) -> bool
Check if the last element already ends with a blank line.
Sourcepub fn update_host(&mut self, old_alias: &str, entry: &HostEntry)
pub fn update_host(&mut self, old_alias: &str, entry: &HostEntry)
Update an existing host entry by alias. Merges changes into the existing block, preserving unknown directives.
Sourcepub fn set_host_provider(
&mut self,
alias: &str,
provider_name: &str,
server_id: &str,
)
pub fn set_host_provider( &mut self, alias: &str, provider_name: &str, server_id: &str, )
Set provider on a host block by alias.
Sourcepub fn find_hosts_by_provider(
&self,
provider_name: &str,
) -> Vec<(String, String)>
pub fn find_hosts_by_provider( &self, provider_name: &str, ) -> Vec<(String, String)>
Find all hosts with a specific provider, returning (alias, server_id) pairs. Searches both top-level elements and Include files so that provider hosts in included configs are recognized during sync (prevents duplicate additions).
Sourcepub fn add_forward(&mut self, alias: &str, directive_key: &str, value: &str)
pub fn add_forward(&mut self, alias: &str, directive_key: &str, value: &str)
Add a forwarding directive to a host block.
Inserts at content_end() (before trailing blanks), using detected indentation.
Uses split_whitespace matching for multi-pattern Host lines.
Sourcepub fn remove_forward(
&mut self,
alias: &str,
directive_key: &str,
value: &str,
) -> bool
pub fn remove_forward( &mut self, alias: &str, directive_key: &str, value: &str, ) -> bool
Remove a specific forwarding directive from a host block. Matches key (case-insensitive) and value (whitespace-normalized). Uses split_whitespace matching for multi-pattern Host lines. Returns true if a directive was actually removed.
Sourcepub fn has_forward(&self, alias: &str, directive_key: &str, value: &str) -> bool
pub fn has_forward(&self, alias: &str, directive_key: &str, value: &str) -> bool
Check if a host block has a specific forwarding directive. Uses whitespace-normalized value comparison and split_whitespace host matching.
Sourcepub fn find_tunnel_directives(&self, alias: &str) -> Vec<TunnelRule>
pub fn find_tunnel_directives(&self, alias: &str) -> Vec<TunnelRule>
Find tunnel directives for a host alias, searching all elements including Include files. Uses split_whitespace matching like has_host() for multi-pattern Host lines.
Sourcepub fn deduplicate_alias(&self, base: &str) -> String
pub fn deduplicate_alias(&self, base: &str) -> String
Generate a unique alias by appending -2, -3, etc. if the base alias is taken.
Sourcepub fn deduplicate_alias_excluding(
&self,
base: &str,
exclude: Option<&str>,
) -> String
pub fn deduplicate_alias_excluding( &self, base: &str, exclude: Option<&str>, ) -> String
Generate a unique alias, optionally excluding one alias from collision detection. Used during rename so the host being renamed doesn’t collide with itself.
Set tags on a host block by alias.
Sourcepub fn set_host_askpass(&mut self, alias: &str, source: &str)
pub fn set_host_askpass(&mut self, alias: &str, source: &str)
Set askpass source on a host block by alias.
Sourcepub fn set_host_meta(&mut self, alias: &str, meta: &[(String, String)])
pub fn set_host_meta(&mut self, alias: &str, meta: &[(String, String)])
Set provider metadata on a host block by alias.
Sourcepub fn delete_host(&mut self, alias: &str)
pub fn delete_host(&mut self, alias: &str)
Delete a host entry by alias.
Sourcepub fn delete_host_undoable(
&mut self,
alias: &str,
) -> Option<(ConfigElement, usize)>
pub fn delete_host_undoable( &mut self, alias: &str, ) -> Option<(ConfigElement, usize)>
Delete a host and return the removed element and its position for undo. Does NOT collapse blank lines so the position stays valid for re-insertion.
Sourcepub fn insert_host_at(&mut self, element: ConfigElement, position: usize)
pub fn insert_host_at(&mut self, element: ConfigElement, position: usize)
Insert a host block at a specific position (for undo).
Sourcepub fn swap_hosts(&mut self, alias_a: &str, alias_b: &str) -> bool
pub fn swap_hosts(&mut self, alias_a: &str, alias_b: &str) -> bool
Swap two host blocks in the config by alias. Returns true if swap was performed.
Source§impl SshConfigFile
impl SshConfigFile
Sourcepub fn parse(path: &Path) -> Result<Self>
pub fn parse(path: &Path) -> Result<Self>
Parse an SSH config file from the given path. Preserves all formatting, comments, and unknown directives for round-trip fidelity.
Sourcepub fn parse_content(content: &str) -> Vec<ConfigElement>
pub fn parse_content(content: &str) -> Vec<ConfigElement>
Parse SSH config content from a string (without Include resolution). Used by tests to create SshConfigFile from inline strings.
Trait Implementations§
Source§impl Clone for SshConfigFile
impl Clone for SshConfigFile
Source§fn clone(&self) -> SshConfigFile
fn clone(&self) -> SshConfigFile
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for SshConfigFile
impl RefUnwindSafe for SshConfigFile
impl Send for SshConfigFile
impl Sync for SshConfigFile
impl Unpin for SshConfigFile
impl UnsafeUnpin for SshConfigFile
impl UnwindSafe for SshConfigFile
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more