Skip to main content

SshConfigFile

Struct SshConfigFile 

Source
pub struct SshConfigFile {
    pub elements: Vec<ConfigElement>,
    pub path: PathBuf,
}
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

Implementations§

Source§

impl SshConfigFile

Source

pub fn host_entries(&self) -> Vec<HostEntry>

Get all host entries as convenience views (including from Include files).

Source

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.

Source

pub fn add_host(&mut self, entry: &HostEntry)

Add a new host entry to the config.

Source

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.

Source

pub fn set_host_tags(&mut self, alias: &str, tags: &[String])

Set tags on a host block by alias.

Source

pub fn delete_host(&mut self, alias: &str)

Delete a host entry by alias.

Source

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.

Source

pub fn insert_host_at(&mut self, element: ConfigElement, position: usize)

Insert a host block at a specific position (for undo).

Source

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

Source

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.

Source

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.

Source§

impl SshConfigFile

Source

pub fn write(&self) -> Result<()>

Write the config back to disk. Creates a backup before writing and uses atomic write (temp file + rename).

Source

pub fn serialize(&self) -> String

Serialize the config to a string.

Trait Implementations§

Source§

impl Clone for SshConfigFile

Source§

fn clone(&self) -> SshConfigFile

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SshConfigFile

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.